Jump to content

Recommended Posts

Posted (edited)

Hey Guys,

 

Ive got this routine which is intended to erase everything visible which is of a colour determined by the user.

 

(defun c:ec ()
(setq ecc (getint "\nEnter COLOUR of objects to ERASE : "))
(setq CODE 62)
(setq pt1 '( -50000000000000 -50000000000000 -50000000000000))
(setq pt2 '( 50000000000000 50000000000000 50000000000000))
(setq ssec (ssget "w" pt1 pt2 '(list (cons CODE ecc))))
(command "ERASE" ssec "")
)

The plan is to only ERASE objects which are visible at the time. So the routine should not operate on any objects on hidden layers... but should operate on objects off the screen (visible in viewport but cannot be seen due to zoom/pan position... if you follow).

 

The problem I am having is I am finding it difficult to pass the colour variable (ecc) to the SSGET filter list while using the "W" option. If I replace "W" with the "X" option.. the routine works, but it will operate on everything in the database.

 

So... I was just wondering if someone could please advise me of a way to filter the "W" optioned SSGET with a variable defined by the user?

 

Thanks so much for any help.

 

 

----------EDIT---------

 

The problem with using the "W" option and defining the co-ordinates as I have is that it is dependant on my current UCS. I have since amended the routine to work around this issue. Please see below.

 

(defun c:ec ()
(setq ecc (getint "\nEnter COLOUR of objects to ERASE : "))
(setq CODE 62)
(command "ucsicon" "off" "ucs" "view")
(setq pt1 '( -50000000000000 -50000000000000 -50000000000000))
(setq pt2 '( 50000000000000 50000000000000 50000000000000))
(setq ssec (ssget "w" pt1 pt2 '(list (cons CODE ecc))))
(command "ERASE" ssec "")
(command "ucs" "p" "ucsicon" "on")
)

Thanks guys.

Edited by lamensterms
Posted

Note that graphical ssget selection modes (e.g. Window / Crossing / Polygon) will only select objects that are visible on screen at the time of selection. Whereas, the X selection mode is not a graphical selection but instead iterates over the entire drawing database to retrieve a selection set containing entities whose DXF data validates the criteria set by the filter list.

 

One way to account for this behaviour is to temporarily zoom to the selection area before evaluating the ssget expression, e.g.:

(defun c:ec ( / a c p q s )
   (while
       (and
           (setq c (getint "\nEnter COLOUR of objects to ERASE: "))
           (not (<= 1 c 255))
       )
       (princ "\nPlease enter an integer between 1 and 255.")
   )
   (if (= 'int (type c))
       (progn
           (setq p '(-5.0e+013 -5.0e+013 -5.0e+013)
                 q '( 5.0e+013  5.0e+013  5.0e+013)
                 a  (vlax-get-acad-object)
           )
           (vlax-invoke a 'zoomwindow p q)
           (setq s (ssget "_W" (trans p 0 1) (trans q 0 1) (list (cons 62 c))))
           (vla-zoomprevious a)
           (if s
               (command "_.erase" s "")
               (princ "\nNo objects found to erase.")
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)

Also, in your code you were quoting the ssget filter list as a literal expression and so the functions within the filter list (list / cons) would not have been evaluated.

Posted

Remove the quote mark in front of list.

 

Oh, Lee already addressed everything.

Posted

Ahhh, sweet... I didn't even consider the fact that CAD would fail to select visible-but-off-screen objects. Most of the time I have been zooming>extents prior to executing this routine. And pre-list quote mark has now been removed.

 

Thanks so much for taking the time to help guys. It is greatly appreciated.

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