Jump to content

Selecting similar to what is visable on screen


3dwannab

Recommended Posts

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • 3dwannab

    15

  • Lee Mac

    9

  • jdiala

    6

  • wimal

    5

Top Posters In This Topic

Posted Images

  • 6 months later...

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.

Link to comment
Share on other sites

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 by Lee Mac
Fixed bug
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

 

highlight not shown.jpg

 

after clicking inside model space viewport.jpg

 

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...