wimal Posted October 28, 2013 Share Posted October 28, 2013 Thanks Mr.jdiala. You have shown me the correct path to learn about that function. And even thanks Mr.Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 28, 2013 Share Posted October 28, 2013 Thanks guys Quote Link to comment Share on other sites More sharing options...
3dwannab Posted October 28, 2013 Author Share Posted October 28, 2013 Thanks everyone for your help. Hopefully this routine will help lots of people. Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 16, 2014 Author Share Posted May 16, 2014 Note: the above is incompatible with dynamic block references. Hi Lee, I was wondering if you know a way for this to work with DYN block references now? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 17, 2014 Share Posted May 17, 2014 (edited) I was wondering if you know a way for this to work with DYN block references now? Thanks in advance. Try this quick mod: ([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] blk enx idx itm lst ref sel tmp ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] ([color=BLUE]list[/color] ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport)) ([color=BLUE]cons[/color] 410 ([color=BLUE]getvar[/color] 'ctab)) '(410 . [color=MAROON]"Model"[/color]) ) ) ) ) ([color=BLUE]progn[/color] ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel)) ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx))))) ([color=BLUE]if[/color] ([color=BLUE]equal[/color] '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]assoc[/color] 0 enx)) ([color=BLUE]setq[/color] blk (LM:name->effectivename ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx))) itm ([color=BLUE]list[/color] '(-4 . [color=MAROON]"<AND"[/color]) '(0 . [color=MAROON]"INSERT"[/color]) ([color=BLUE]cons[/color] 2 ([color=BLUE]cond[/color] ( ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] blk tmp))) ( ([color=BLUE]setq[/color] ref ([color=BLUE]strcat[/color] blk ([color=BLUE]apply[/color] '[color=BLUE]strcat[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]strcat[/color] [color=MAROON]",`"[/color] x)) (LM:getanonymousreferences blk)))) tmp ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] blk ref) tmp) ) ref ) ) ) ([color=BLUE]assoc[/color] 8 enx) '(-4 . [color=MAROON]"AND>"[/color]) ) ) ([color=BLUE]setq[/color] itm ([color=BLUE]list[/color] '(-4 . [color=MAROON]"<AND"[/color]) ([color=BLUE]assoc[/color] 0 enx) ([color=BLUE]assoc[/color] 8 enx) '(-4 . [color=MAROON]"AND>"[/color]) ) ) ) ([color=BLUE]or[/color] ([color=BLUE]member[/color] itm lst) ([color=BLUE]setq[/color] lst ([color=BLUE]cons[/color] itm lst)) ) ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]apply[/color] '[color=BLUE]ssget[/color] ([color=BLUE]append[/color] '([color=MAROON]"_C"[/color]) ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]trans[/color] x 0 1)) (LM:ViewportExtents)) ([color=BLUE]list[/color] ([color=BLUE]append[/color] '((-4 . [color=MAROON]"<OR"[/color])) ([color=BLUE]apply[/color] '[color=BLUE]append[/color] lst) '((-4 . [color=MAROON]"OR>"[/color])) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport)) ([color=BLUE]list[/color] ([color=BLUE]cons[/color] 410 ([color=BLUE]getvar[/color] 'ctab))) '((410 . [color=MAROON]"Model"[/color])) ) ) ) ) ) ) ([color=BLUE]command[/color] [color=MAROON]"_.isolateobjects"[/color] sel [color=MAROON]""[/color]) ) ) ) ([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 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]setq[/color] ref ([color=BLUE]entget[/color] ([color=BLUE]cdr[/color] ref))) ([color=BLUE]=[/color] blk ([color=BLUE]strcase[/color] (LM:name->effectivename ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ref))))) ) ([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];; Block Name -> Effective Block Name - Lee Mac[/color] [color=GREEN];; blk - [str] Block name[/color] ([color=BLUE]defun[/color] LM:name->effectivename ( blk [color=BLUE]/[/color] rep ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]wcmatch[/color] blk [color=MAROON]"`**"[/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]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] rep))) blk ) ) [color=GREEN];; Viewport Extents - Lee Mac[/color] [color=GREEN];; Returns two WCS points describing the lower-left and[/color] [color=GREEN];; upper-right corners of the active viewport.[/color] ([color=BLUE]defun[/color] LM:ViewportExtents ( [color=BLUE]/[/color] c h v ) ([color=BLUE]setq[/color] c ([color=BLUE]trans[/color] ([color=BLUE]getvar[/color] 'viewctr) 1 0) h ([color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'viewsize) 2.0) v ([color=BLUE]list[/color] ([color=BLUE]*[/color] h ([color=BLUE]apply[/color] '[color=BLUE]/[/color] ([color=BLUE]getvar[/color] 'screensize))) h) ) ([color=BLUE]list[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]-[/color] c v) ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] c v)) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Edited May 22, 2014 by Lee Mac Fixed bug Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 21, 2014 Author Share Posted May 21, 2014 Try this quick mod: Hi Lee, thanks for this. Sorry I didn't get back as I was off ill. I've tried that but I get the error for DYN attribute blocks. Select objects: ; error: bad SSGET list value in the command line. It works for DYN blocks but its a little slow to finish the command. Roughly 5-7 seconds per command. 'Normal' objects are working just as fast. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 22, 2014 Share Posted May 22, 2014 I've tried that but I get the error for DYN attribute blocks. Select objects: ; error: bad SSGET list value in the command line. Are you able to post a drawing containing a sample dynamic block for which the program is failing - I have tried the updated program with attributed dynamic blocks and cannot seem to get the program to fail. Lee Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 22, 2014 Author Share Posted May 22, 2014 Are you able to post a drawing containing a sample dynamic block for which the program is failing - I have tried the updated program with attributed dynamic blocks and cannot seem to get the program to fail. Lee Oh, strange maybe if you send me your file too. Here's a different test file I created which gives the same error. DYN ATT test file.dwg Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 22, 2014 Share Posted May 22, 2014 Oh, strange maybe if you send me your file too. Here's a different test file I created which gives the same error.[ATTACH]49063[/ATTACH] Thanks 3dwannab - I have edited the above code to hopefully fix the issue. Lee Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 22, 2014 Author Share Posted May 22, 2014 Thanks 3dwannab - I have edited the above code to hopefully fix the issue. Lee Lee, I can't thank you enough for your efforts. You are a credit to the community. One small change I made was to change the line: (command "_.isolateobjects" sel "") to: (command "_.pselect" sel "") This works better for my workflow from here I can press shortcuts I've setup SHIFT+H to hide or CTRL+ALT+E to isolate the selection made. EDIT: I will test on the same file that was slow to run the LISP and report back to you Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 22, 2014 Share Posted May 22, 2014 Lee, I can't thank you enough for your efforts. You are a credit to the community. Thank you 3dwannab, that's very kind of you to say One small change I made was to change the line: (command "_.isolateobjects" sel "") to: (command "_.pselect" sel "") This works better for my workflow from here I can press shortcuts I've setup SHIFT+H to hide or CTRL+ALT+E to isolate the selection made. No problem - the program could be configured to perform any action you wish on the resulting selection set by simply exchanging the line you have quoted above. Rather than using the PSELECT command, you could also use the following the highlight the selection: (sssetfirst nil sel) EDIT: I will test on the same file that was slow to run the LISP and report back to you The performance hit could be a result of the method I am using the obtain all (anonymous) references of any dynamic blocks in the initial selection - this involves iterating over all blocks defined in the drawing (which could be quite a few for large drawings). Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 22, 2014 Author Share Posted May 22, 2014 Rather than using the PSELECT command, you could also use the following the highlight the selection: (sssetfirst nil sel) Thanks, I've done some more testing and it seems that it intermittently doesn't highlight the objects even though in the properties dialog it shows as been whatever number selected. Then if I click anywhere inside modelspace viewport they become selected. (See screen-shots attached). It's a minor bug but I'm sure I can live with that. I have done in the past with the old one but I thought you might want to know. The performance hit could be a result of the method I am using the obtain all (anonymous) references of any dynamic blocks in the initial selection - this involves iterating over all blocks defined in the drawing (which could be quite a few for large drawings). No problem. Being one of my most used scripts it's a small price to pay for what is to me an invaluable tool. Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 23, 2014 Author Share Posted May 23, 2014 I've fixed the problem with the screen not refreshing sometimes after the LISP has run by changing: (sssetfirst nil sel) ;;(command "_.pselect" sel "") ) ) ) (princ) ) To: (sssetfirst nil sel) ;;(command "_.pselect" sel "") ) (command "._REGEN" "") ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 24, 2014 Share Posted May 24, 2014 Thanks, I've done some more testing and it seems that it intermittently doesn't highlight the objects even though in the properties dialog it shows as been whatever number selected. Then if I click anywhere inside modelspace viewport they become selected. Since the code is simply obtaining the relevant selection set and passing this selection set to the sssetfirst function to be selected & gripped, I would guess that the intermittent behaviour that you are experiencing is caused either by a bug in AutoCAD or perhaps by another selection being active when the sssetfirst function is evaluated, causing some interference. I've fixed the problem with the screen not refreshing sometimes after the LISP has run by changing: (sssetfirst nil sel) ;;(command "_.pselect" sel "") ) ) ) (princ) ) To: (sssetfirst nil sel) ;;(command "_.pselect" sel "") ) (command "._REGEN" "") ) ) (princ) ) Although regenerating all objects in the active layout is not ideal (especially for larger drawings), I'm glad you were able to find a solution. Though, I would suggest incorporating the call to the REGEN command within the 'then' argument for the if function, so that the drawing is not unnecessarily regenerated when no selection is obtained, i.e.: (progn (sssetfirst nil sel) (command "_.regen") ) (a minor point) Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 25, 2014 Author Share Posted May 25, 2014 Thanks, I always thought there was a difference between RE (Regen) and REA (Regen All) And from the help files it says regen only refreshes all objects the current visable viewport (which i think is only what you see) but regenall does all veiwports. See: http://autode.sk/1h2xYjf. Maybe I'm picking it up wrong I trying to learn a bit about LISPs and here's my code now: (progn (sssetfirst nil sel) (princ (strcat "\n" (if sel (itoa (sslength sel)) "0") " Entities Selected.\n")) ) ((command "_.regen") (princ)) ) ) ) (princ) I know the regen command is not within the 'then' argument for the if function but what I was tring to do is hide the command regen from showing up in the CAD commandline. I've also added a code to let me know how many objects are selected. How to you suppress the regen command within the then argument. I've tried doing so but can get it to work. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 25, 2014 Share Posted May 25, 2014 Perhaps something like this: (progn (sssetfirst nil sel) (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) (command "_.regen") (setvar 'cmdecho cmd) (princ (strcat "\n" (itoa (sslength sel)) " object(s) selected.")) ) (princ "\nNo objects selected.") And add the cmd symbol to the list of declared local variables. Quote Link to comment Share on other sites More sharing options...
3dwannab Posted May 25, 2014 Author Share Posted May 25, 2014 Perhaps something like this: (progn (sssetfirst nil sel) (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) (command "_.regen") (setvar 'cmdecho cmd) (princ (strcat "\n" (itoa (sslength sel)) " object(s) selected.")) ) (princ "\nNo objects selected.") And add the cmd symbol to the list of declared local variables. Great, I'm getting an understanding of what the local variables job is. BTW I did try the cmdecho but in a different way using the command method instead of setvar but it didn't work. Thanks very much for your help in this matter Lee. Greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 25, 2014 Share Posted May 25, 2014 Great, I'm getting an understanding of what the local variables job is. BTW I did try the cmdecho but in a different way using the command method instead of setvar but it didn't work. Thanks very much for your help in this matter Lee. Greatly appreciated. You're most welcome 3dwannab - I'm glad to hear you are learning along the way. 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.