Jump to content

Recommended Posts

Posted (edited)

I have a lisp that I'm trying to improve that calculates two points using polar (based off a point the user selected), then selects an object with ssget, using a window selection between the two points.

 

The problem is if the object to be selected is not on screen when the user selects the point, the ssget to make the selection fails.

 

Here is a runnable example of my problem:

 

(defun c:sother (/ a b c ent)
(setq b (polar (setq a (getpoint)) 0 5))
(setq c (polar b (dtr 315) 1))
(setq ent (entget (ssname (ssget "_W" b c) 0)))
;do something with ent
) 
(defun dtr 
(x)
   (* PI (/ x 180.0))
)

 

The user first selects a point, then the program selects an object in the drawing at an expected location (the program didn't create the object).

 

The problem can be demonstrated by drawing a small circle at approx. (5.3448, -0.344), running this program and selecting (0, 0) as the point. If the circle is visible on screen when the initial point is selected, the entget will return the entity info. If not, it will fail.

 

Is there a system variable or some such I could set to fix this (easy solution)? Or should I attempt to select the objects by querying the database (a bit more complicated, I think).

Edited by dallion
Posted

You haven't posted your code, so I could be missing some information... Why don't you just pass the EName to your Selection Set?

 

(defun _Select (ss)
 ;; Example:
 ;; (_Select (ssadd (car (entsel))))
 (sssetfirst nil ss)
)

 

Here's a quick sample:

 

(defun c:FOO (/ eName ss)
 (if (and (setq eName (car (entsel "\nSelect an entity: ")))
          (setq ss (ssadd eName))
     )
   (_Select ss)
 )
 (princ)
)

Posted

sorry, I have updated initial post with a more detailed explanation.

Posted

I think you're not understanding my suggestion... Do not use the Window selection to create your Selection Set at all. Instead add the entity to a Selection Set based on some unique identifying criteria, such as layer, object type, XRecord, etc.

Posted

To select objects which may be off-screen at the time of selection, one workaround solution is to temporarily zoom to the selection area before evaluating the ssget expression, for example:

(defun c:sother ( / c p q s )
   (if (setq p (getpoint "\nPick point: "))
       (progn
           (setq p (cons (+ 5 (car p)) (cdr p))
                 q (polar p (* pi 1.75) 1.0)
                 c (getvar 'cmdecho)
           )
           (setvar 'cmdecho 0)
           (command "_.zoom" "_W" "_non" p "_non" q)
           (if (setq s (ssget "_W" p q))
               (mapcar 'print (entget (ssname s 0)))
           )
           (command "_.zoom" "_P")
           (setvar 'cmdecho c)
       )
   )
   (princ)
)

Or, alternatively using Visual LISP:

(defun c:sother ( / a p q s )
   (if (setq p (getpoint "\nPick point: "))
       (progn
           (setq p (cons (+ 5 (car p)) (cdr p))
                 q (polar p (* pi 1.75) 1.0)
                 a (vlax-get-acad-object)
           )
           (vlax-invoke a 'zoomwindow (trans p 1 0) (trans q 1 0))
           (if (setq s (ssget "_W" p q))
               (mapcar 'print (entget (ssname s 0)))
           )
           (vla-zoomprevious a)
       )
   )
   (princ)
)
(vl-load-com)

However, as BlackBox has suggested above, a far more reliable and elegant method would be to retrieve the entity directly from the drawing database (ssget "X" mode) based on other unique characteristics, such as entity type, layer, linetype, etc. or even using unique geometrical properties (such as the circle center or radius, if indeed it is a circle you are trying to select).

Posted

Thanks both of you, I guess I will just write a function to find the entity using (ssget "_X" ..) and the position it should be at relative to the selected point. Good to know "_X" mode will work for off screen objects.

Posted

X is a search entire dwg not sure how you will use that ? I agree with Lee do a temporary zoom, I have come across this problem before doing other stuff like multiple filleting at one time must be able to see all lines for it to work.

Posted
X is a search entire dwg not sure how you will use that ? I agree with Lee do a temporary zoom, I have come across this problem before doing other stuff like multiple filleting at one time must be able to see all lines for it to work.

 

Well, I know the entity I'm looking for is text, so I can filter by DTEXT, MTEXT, and get a hold of the one of those that has an insertion point within a rectangle defined by my two points. My AutoLisp is a little rusty by I'm pretty sure that's possible.

 

Although the temporary zoom is tempting since Lee's been kind enough to write it out :D

Posted

Your ssget can have multiple filters like (2 . "Text,mtext") inconjunction with your WP

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