polhub Posted July 29, 2016 Share Posted July 29, 2016 I have done a little bit of Lisping but this one is beyond me so I am hoping someone can help. I have been looking for a way to do the following: Select first block (SL-Dev) and grab the value of the attribute tag ID_1 (this stays the same for multiple selections) Select second block (SL-Con) and grab the value of attribute tag IN_1 Place both values with a space between (ID_1 IN_1) and put that new value back into the second block (SL-Con) with the attribute tag NEAR I would then like to continue this process by clicking on multiple SL-Con blocks and use its tag IN_1 to combine with the ORIGINAL SL_DEV tag ID_1 Seems pretty tricky to me but any help would be appreciated Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted July 29, 2016 Share Posted July 29, 2016 Untested... (defun c:ID_1-sour+IN_1-dest->NEAR-dest ( / s b1 sourval1 b2 sourval2 destval ) (vl-load-com) (prompt "\nPick (SL-Dev) block reference...") (setq s (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1)))) (while (or (not s) (vlax-property-available-p (setq b1 (vlax-ename->vla-object (ssname s 0))) 'Path) (/= (vla-get-effectivename b1) "SL-Dev")) (prompt "\nMissed or wrong block reference pick or picked xref... Try picking (SL-Dev) block reference again...") (setq s (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1)))) ) (foreach att (append (vlax-invoke b1 'getattributes) (vlax-invoke b1 'getstaticattributes)) (if (= (vla-get-tagstring att) "ID_1") (setq sourval1 (vla-get-textstring att)) ) ) (while t (prompt "\nPick (SL-Con) block reference... ESC to terminate and finish picking (SL-Con) block references...") (setq s (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1)))) (while (or (not s) (vlax-property-available-p (setq b2 (vlax-ename->vla-object (ssname s 0))) 'Path) (/= (vla-get-effectivename b2) "SL-Con")) (prompt "\nMissed or wrong block reference pick or picked xref... Try picking (SL-Con) block reference again...") (setq s (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1)))) ) (foreach att (append (vlax-invoke b2 'getattributes) (vlax-invoke b2 'getstaticattributes)) (if (= (vla-get-tagstring att) "IN_1") (setq sourval2 (vla-get-textstring att)) ) ) (setq destval (strcat sourval1 " " sourval2)) (foreach att (append (vlax-invoke b2 'getattributes) (vlax-invoke b2 'getstaticattributes)) (if (= (vla-get-tagstring att) "NEAR") (vla-put-textstring att destval) ) ) ) (princ) ) To give you picture what should it look like... Quote Link to comment Share on other sites More sharing options...
polhub Posted July 29, 2016 Author Share Posted July 29, 2016 As I said beyond me... I did load it and run it however, and this is what I got after I selected the SL-DEV block (it is dynamic if that makes a difference). Pick (SL-Dev) block reference... Select objects: ; error: ActiveX Server returned the error: unknown name: "GETSTATICATTRIBUTES" Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted July 29, 2016 Share Posted July 29, 2016 (edited) Replace (append (vlax-invoke [b1/b2] 'getattributes) (vlax-invoke [b1/b2] 'getstaticattributes))... with (append (vlax-invoke [b1/b2] 'getattributes) (vlax-invoke [b1/b2] 'getconstantattributes)) in all occurrencies in posted code... I don't have time, you'll have to debugg it alone... Edited August 1, 2016 by marko_ribar message changed... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 29, 2016 Share Posted July 29, 2016 Try the following untested code: ([color=BLUE]defun[/color] c:combatt ( [color=BLUE]/[/color] ent id1 idx in1 sel ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect SL-DEV block <exit>: "[/color]))) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]null[/color] ent) [color=BLUE]nil[/color]) ( ([color=BLUE]/=[/color] [color=MAROON]"INSERT"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ent)))) ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object is not a block."[/color]) ) ( ([color=BLUE]/=[/color] [color=MAROON]"SL-DEV"[/color] ([color=BLUE]strcase[/color] (LM:al-effectivename ent))) ([color=BLUE]princ[/color] [color=MAROON]"\nSelected block is not an \"SL-DEV\" block."[/color]) ) ( ([color=BLUE]not[/color] ([color=BLUE]setq[/color] id1 (LM:getattributevalue ent [color=MAROON]"ID_1"[/color]))) ([color=BLUE]princ[/color] [color=MAROON]"\nBlock does not contain \"ID_1\" attribute."[/color]) ) ) ) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] id1 ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] [color=MAROON]"_:L"[/color] ([color=BLUE]list[/color] '(0 . [color=MAROON]"INSERT"[/color]) '(66 . 1) ([color=BLUE]cons[/color] 2 ([color=BLUE]apply[/color] '[color=BLUE]strcat[/color] ([color=BLUE]cons[/color] [color=MAROON]"SL-CON"[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]strcat[/color] [color=MAROON]",`"[/color] x)) (LM:getanonymousreferences [color=MAROON]"SL-CON"[/color]) ) ) ) ) ) ) ) ) ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel)) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] ent ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx))) in1 (LM:getattributevalue ent [color=MAROON]"IN_1"[/color]) ) (LM:setattributevalue ent [color=MAROON]"NEAR"[/color] ([color=BLUE]strcat[/color] id1 in1)) ) ) ) ([color=BLUE]princ[/color]) ) [color=GREEN];; Get Anonymous References - Lee Mac[/color] [color=GREEN];; Returns the names of all anonymous references of a block.[/color] [color=GREEN];; blk - [str] Block name/wildcard pattern for which to return anon. references[/color] ([color=BLUE]defun[/color] LM:getanonymousreferences ( blk [color=BLUE]/[/color] ano def lst rec ref ) ([color=BLUE]setq[/color] blk ([color=BLUE]strcase[/color] blk)) ([color=BLUE]while[/color] ([color=BLUE]setq[/color] def ([color=BLUE]tblnext[/color] [color=MAROON]"block"[/color] ([color=BLUE]null[/color] def))) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]logand[/color] 1 ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 70 def)))) ([color=BLUE]setq[/color] rec ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 330 ([color=BLUE]entget[/color] ([color=BLUE]tblobjname[/color] [color=MAROON]"block"[/color] ([color=BLUE]setq[/color] ano ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 def))) ) ) ) ) ) ) ) ([color=BLUE]while[/color] ([color=BLUE]and[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] ano lst)) ([color=BLUE]setq[/color] ref ([color=BLUE]assoc[/color] 331 rec)) ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] ref)) ([color=BLUE]wcmatch[/color] ([color=BLUE]strcase[/color] (LM:al-effectivename ([color=BLUE]cdr[/color] ref))) blk) ) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] ano lst)) ) ([color=BLUE]setq[/color] rec ([color=BLUE]cdr[/color] ([color=BLUE]member[/color] ([color=BLUE]assoc[/color] 331 rec) rec))) ) ) ) ([color=BLUE]reverse[/color] lst) ) [color=GREEN];; Effective Block Name - Lee Mac[/color] [color=GREEN];; ent - [ent] Block Reference entity[/color] ([color=BLUE]defun[/color] LM:al-effectivename ( ent [color=BLUE]/[/color] blk rep ) ([color=BLUE]if[/color] ([color=BLUE]wcmatch[/color] ([color=BLUE]setq[/color] blk ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] ent)))) [color=MAROON]"`**"[/color]) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] rep ([color=BLUE]cdadr[/color] ([color=BLUE]assoc[/color] -3 ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 330 ([color=BLUE]entget[/color] ([color=BLUE]tblobjname[/color] [color=MAROON]"block"[/color] blk) ) ) ) '([color=MAROON]"acdbblockrepbtag"[/color]) ) ) ) ) ([color=BLUE]setq[/color] rep ([color=BLUE]handent[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1005 rep)))) ) ([color=BLUE]setq[/color] blk ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] rep)))) ) ) blk ) [color=GREEN];; Get Attribute Value - Lee Mac[/color] [color=GREEN];; Returns the value held by the specified tag within the supplied block, if present.[/color] [color=GREEN];; blk - [ent] Block (Insert) Entity Name[/color] [color=GREEN];; tag - [str] Attribute TagString[/color] [color=GREEN];; Returns: [str] Attribute value, else nil if tag is not found.[/color] ([color=BLUE]defun[/color] LM:getattributevalue ( blk tag [color=BLUE]/[/color] enx ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTRIB"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]setq[/color] blk ([color=BLUE]entnext[/color] blk))))))) ([color=BLUE]if[/color] ([color=BLUE]=[/color] ([color=BLUE]strcase[/color] tag) ([color=BLUE]strcase[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx)))) ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1 enx)) (LM:getattributevalue blk tag) ) ) ) [color=GREEN];; Set Attribute Value - Lee Mac[/color] [color=GREEN];; Sets the value of the first attribute with the given tag found within the block, if present.[/color] [color=GREEN];; blk - [ent] Block (Insert) Entity Name[/color] [color=GREEN];; tag - [str] Attribute TagString[/color] [color=GREEN];; val - [str] Attribute Value[/color] [color=GREEN];; Returns: [str] Attribute value if successful, else nil.[/color] ([color=BLUE]defun[/color] LM:setattributevalue ( blk tag val [color=BLUE]/[/color] enx ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]"ATTRIB"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]setq[/color] blk ([color=BLUE]entnext[/color] blk))))))) ([color=BLUE]if[/color] ([color=BLUE]=[/color] ([color=BLUE]strcase[/color] tag) ([color=BLUE]strcase[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx)))) ([color=BLUE]if[/color] ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 1 val) ([color=BLUE]assoc[/color] 1 enx) enx)) ([color=BLUE]progn[/color] ([color=BLUE]entupd[/color] blk) val ) ) (LM:setattributevalue blk tag val) ) ) ) ([color=BLUE]princ[/color]) The above uses my Attribute Functions & Get Anonymous References function. Quote Link to comment Share on other sites More sharing options...
polhub Posted August 3, 2016 Author Share Posted August 3, 2016 Lee, you are the man!!! Works like a charm thank you! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 3, 2016 Share Posted August 3, 2016 Lee, you are the man!!! Works like a charm thank you! Excellent - you're welcome! Quote Link to comment Share on other sites More sharing options...
polhub Posted September 25, 2017 Author Share Posted September 25, 2017 Lee, we have been using the above for almost a year not (THANKS AGAIN) we have found a couple items that we would like to change. I tried a couple things but was unsuccessful so I am hoping you or someone else can help with the changes. Originally we had two blocks to draw information from SL-Dev and SL-Con, what we are looking for now is to be able to select SL-Dev or SL-Dev2 for the first selection set and SL-Con, SL-Con2, SL-Con3, SL-Con4 for the second selection set. The attribute tags for SL-Dev and SL-Dev2 are the same as are the tags for the SL-Con blocks. I can't seem to figure out how to increase the selection sets so any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 25, 2017 Share Posted September 25, 2017 What we are looking for now is to be able to select SL-Dev or SL-Dev2 for the first selection set and SL-Con, SL-Con2, SL-Con3, SL-Con4 for the second selection set. The attribute tags for SL-Dev and SL-Dev2 are the same as are the tags for the SL-Con blocks. Change the following: Line 12 from: ( (/= "SL-DEV" (strcase (LM:al-effectivename ent))) to: ( (not (wcmatch (strcase (LM:al-effectivename ent)) "SL-DEV,SL-DEV2")) Line 28 from: (cons "SL-CON" to: (cons "SL-CON,SL-CON[234]" Line 30 from: (LM:getanonymousreferences "SL-CON") to: (LM:getanonymousreferences "SL-CON,SL-CON[234]") Quote Link to comment Share on other sites More sharing options...
polhub Posted September 25, 2017 Author Share Posted September 25, 2017 Lee, Thank you for the very quick reply, IT WORKS GREAT! Thank you so much. It was the item and list on the cons that tripped me up, I still have a lot to learn. Thanks again! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 25, 2017 Share Posted September 25, 2017 You're welcome! I'm glad it's working well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.