Jump to content

Lisp to select entity by window


woodman78

Recommended Posts

I have this lisp to select an entity by a crossing window but I am getting an error. Can anyone help?

 

 

(defun c:OSi ( /p1 p2 sel1)
(setq p1 476.702,-48.6347)
(setq p2 472.854,-44.789)
(setq sel1 (ssget "w" p1 p2))
(command "erase" sel1 "" )
(princ)
)

 

Thanks.

Link to comment
Share on other sites

(defun c:OSi (/ p1 p2 sel1)
 (setq p1 (list 476.702 -48.6347))
 (setq p2 (list 472.854 -44.789))
 (if (and (listp p1) (listp p2) (setq sel1 (ssget "w" p1 p2)))
   (command "_.erase" sel1 "")
 )
 (princ)
)

Link to comment
Share on other sites

Your points must be lists, i.e.

 

(setq p1 '(476.702 -48.6347))

In AutoLISP 476.702,-48.6347 is just a symbol - it not a string or a list and has no numerical value (it holds no value whatsoever unless defined using a set[q] expression)

Link to comment
Share on other sites

  • 4 years later...
(defun c:OSi (/ p1 p2 sel1)
 (setq p1 (list 476.702 -48.6347))
 (setq p2 (list 472.854 -44.789))
 (if (and (listp p1) (listp p2) (setq sel1 (ssget "w" p1 p2)))
   (command "_.erase" sel1 "")
 )
 (princ)
)

 

 

 

Is there any reason why following variation is not working? (i.e. not erasing):

 

(defun foo (p1 p2 / sel1)
 (if (= (getvar "TILEMODE") 1)
   (setvar 'TILEMODE 0)
 )
 (if (and (listp p1) (listp p2) (setq sel1 (ssget "w" p1 p2)))
   (command "_.Erase" sel1 "")
 )
 (princ)
)
(foo '(115 15) '(131 21))

 

The problem seems to be switching to Paper space. If I drag the lisp onto drawing while paper space is active, it works fine. However, being in Model Space, the code just activates the Paper space and that's about it. :unsure:

Link to comment
Share on other sites

The problem seems to be switching to Paper space. If I drag the lisp onto drawing while paper space is active, it works fine. However, being in Model Space, the code just activates the Paper space and that's about it. :unsure:

 

Hi,

Try to add the following codes with AND function:

 

(setvar 'CTAB (getvar 'CTAB))

Link to comment
Share on other sites

Try to add the following codes with AND function:

(setvar 'CTAB (getvar 'CTAB))

 

This will have no effect - you are setting CTAB to its existing value.

 

I would suggest removing the lines:

  (if (= (getvar "TILEMODE") 1)
   (setvar 'TILEMODE 0)
 )

Link to comment
Share on other sites

This will have no effect - you are setting CTAB to its existing value.

I am setting the CTAB after moving to last visited paper space to allow the ssget to work in that space but it seems that it is working without it after testing it a few seconds ago.

 

I would suggest removing the lines:

  (if (= (getvar "TILEMODE") 1)
   (setvar 'TILEMODE 0)
 )

 

The guy who asked for the an answer, needs to run the codes in paper space and that's why they included that fore-said codes at the beginning.

Link to comment
Share on other sites

Hi,

Try to add the following codes with AND function:

 

(setvar 'CTAB (getvar 'CTAB))

 

No change. I tried like so:

 

(defun foo (p1 p2 / sel1)
 (if (= (getvar "TILEMODE") 1)
   (setvar 'TILEMODE 0)
 )
 (if (and (setvar 'CTAB (getvar 'CTAB)) (listp p1) (listp p2) (setq sel1 (ssget "w" p1 p2)))
   (command "_.Erase" sel1 "")
 )
 (princ)
)
(foo '(115 15) '(131 21))

 

This will have no effect - you are setting CTAB to its existing value.

 

I would suggest removing the lines:

  (if (= (getvar "TILEMODE") 1)
   (setvar 'TILEMODE 0)
 )

 

The texts that I want to delete are in paper space. Most of drawings have been last saved&closed in Model space. I need this bit of code to switch over.

Link to comment
Share on other sites

I am setting the CTAB after moving to last visited paper space to allow the ssget to work in that space but it seems that it is working without it after testing it a few seconds ago.

 

Consider that:

(setvar 'ctab (getvar 'ctab))

Is no different to doing:

(setq a a)

You are setting a system variable to the value it already holds. ;)

Link to comment
Share on other sites

The texts that I want to delete are in paper space. Most of drawings have been last saved&closed in Model space. I need this bit of code to switch over.

It did work for me.

 

Consider that:
(setvar 'ctab (getvar 'ctab))

Is no different to doing:

(setq a a)

You are setting a system variable to the value it already holds. ;)

Lee I am not a new to AutoLISP to say that and I am not giving replies by guessing.

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