construction lines

construction lines

Anonymous
Not applicable
1,631 Views
23 Replies
Message 1 of 24

construction lines

Anonymous
Not applicable

need help, my lisp isn't working.  Thanks

 

(defun-q c:dz(/ss1)
 (princ"\nErease all xlines:")
 (if(setq ss1(ssget"X"(list(cons 0"XLINE")(con67(if(xyz_is_paper)1 0))))))
  (progn
  (command"erase"ss1)
  (princ(strcat"\Erased "(itoa(sslength ss1))"xlines"))
 );_progn
)'_if
 (princ)
)

0 Likes
Accepted solutions (1)
1,632 Views
23 Replies
Replies (23)
Message 2 of 24

Kent1Cooper
Consultant
Consultant

Welcome to these Forums.

 

It looks to me as though you have an extra right parenthesis at the end of the longest line.  If removing one doesn't fix it, post your (xyz_is_paper) function [do you know that's loaded?], in case the problem might be in that.

 

Also, though it may not make a difference, try (defun) rather than the old (defun-q) function [read about that].

 

Are any Xlines on locked Layers?

 

Finally, "isn't working" is not really enough information.  In what way does it not work?  Does it do something different from what you expect, or nothing at all?  Is there any error message?  Etc., etc.

Kent Cooper, AIA
0 Likes
Message 3 of 24

Anonymous
Not applicable

when I try to enter it, it says unknown command.

0 Likes
Message 4 of 24

Anonymous
Not applicable

tried it but still get "dz Unknown command "DZ".  Press F1 for help."

0 Likes
Message 5 of 24

hmsilva
Mentor
Mentor

Hi agmic,

when formatting the code, you'll need to pay attention at the spaces between functions and arguments...
Was required an extra enter "" to finalize the erase command.

Assuming you have Vladimir Nesterovsky's 'xyz_is_paper' loaded, should work as expected

 

(defun c:dz ( / ss1)
 (princ"\nErease all xlines:")
 (if (setq ss1 (ssget "X" (list (cons 0"XLINE")(cons 67 (if (xyz_is_paper) 1 0)))))
  (progn
  (command "erase" ss1 "")
  (princ (strcat "\Erased " (itoa(sslength ss1)) " xlines"))
 );_progn
);_if
 (princ)
)

 

Hope that helps
Henrique

EESignature

0 Likes
Message 6 of 24

Anonymous
Not applicable

still not working. Anyone have another lisp routine to delete construction lines?

0 Likes
Message 7 of 24

hmsilva
Mentor
Mentor

@Anonymous wrote:

still not working.


Do you have Vladimir Nesterovsky's 'xyz_is_paper' loaded?

If not, add this function to 'your' code, and try again...

 

;;;=========================================================================
;;; xyz_is_paper - returns nil for modelspace, T for paperspace
;;;  by Vladimir Nesterovsky
;;; use (cons 67 (if (xyz_is_paper) 1 0)) for ssget "X" of mspace vs. pspace
;;;  note that pspace will get all objects in layouts, not just current
;;;=========================================================================
(defun-q xyz_is_paper () (> 2 (getvar "cvport") (getvar "tilemode")))

 

Henrique

EESignature

0 Likes
Message 8 of 24

Anonymous
Not applicable

sorry, how do you add this function?  or can i just change the paper to model?

0 Likes
Message 9 of 24

hmsilva
Mentor
Mentor

@Anonymous wrote:

sorry, how do you add this function?  or can i just change the paper to model?


 

 

;;;=========================================================================
;;; xyz_is_paper - returns nil for modelspace, T for paperspace
;;;  by Vladimir Nesterovsky
;;; use (cons 67 (if (xyz_is_paper) 1 0)) for ssget "X" of mspace vs. pspace
;;;  note that pspace will get all objects in layouts, not just current
;;;=========================================================================
(defun-q xyz_is_paper () (> 2 (getvar "cvport") (getvar "tilemode")))

(defun c:dz ( / ss1)
 (princ"\nErease all xlines:")
 (if (setq ss1 (ssget "X" (list (cons 0"XLINE")(cons 67 (if (xyz_is_paper) 1 0)))))
  (progn
  (command "erase" ss1 "")
  (princ (strcat "\Erased " (itoa(sslength ss1)) " xlines"))
 );_progn
);_if
 (princ)
)

 

Henrique

EESignature

0 Likes
Message 10 of 24

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

still not working. Anyone have another lisp routine to delete construction lines?


Again, what does "not working" mean?  Still an unknown command?  If not, I would guess that it's in the (xyz_is_paper) function, or that function is not loaded.

 

If you want to delete all Xlines in the current space, try something like:

 

(defun C:DZ (/ ss1)
  (prompt "\nErase all Xlines:")
  (if (setq ss1 (ssget "_X" (list '(0 . "XLINE") (cons 410 (getvar 'ctab)))))
    (progn
      (command "erase" ss1 "")
      (princ (strcat "\Erased " (itoa (sslength ss1)) " Xlines"))
    );_progn
  );_if
  (princ)
); defun

 

If you want to get rid of all Xlines, regardless of where they are, try something like:

 

(defun C:DZ (/ ss1 n)
  (prompt "\nErase all Xlines:")
  (if (setq ss1 (ssget "_X" '((0 . "XLINE"))))
    (repeat (setq n (sslength ss1))

      (entdel (ssname ss1 (setq n (1- n))))
    ); repeat
  ); if
  (princ)
); defun

Kent Cooper, AIA
0 Likes
Message 11 of 24

Anonymous
Not applicable

should i use the smileyvery-happy after the defun c: ?

0 Likes
Message 12 of 24

Kent1Cooper
Consultant
Consultant

@hmsilva wrote:
Do you have Vladimir Nesterovsky's 'xyz_is_paper' loaded?

....

 

....
;;; use (cons 67 (if (xyz_is_paper) 1 0)) for ssget "X" of mspace vs. pspace
;;;  note that pspace will get all objects in layouts, not just current
;;;=========================================================================
(defun-q xyz_is_paper () (> 2 (getvar "cvport") (getvar "tilemode")))

....


Note that while that function, when used in paper space, may get all appropriate objects in all layouts, not just the current one, that only covers the finding of them -- the Erase command will not Erase those that are not in the current layout.  You would need to get into every layout and run the command in each.  If you want to get those in other than the current layout/space, without getting into each one, use something like my version that uses (entdel).

Kent Cooper, AIA
0 Likes
Message 13 of 24

Anonymous
Not applicable

Again, what does "not working" mean?  Still an unknown command?  If not, I would guess that it's in the (xyz_is_paper) function, or that function is not loaded.

 

Sorry, the "not working" means that when I load the lisp file and try to use it, autocad gives me dx unknown command"dz"...

Is that better...

0 Likes
Message 14 of 24

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

should i use the smileyvery-happy after the defun c: ?


No, you should go into your Profile and disable emoticons.  This is a problem that's been pointed out repeatedly around here, since a colon followed by certain letters triggers emoticons, but it's a common element in AutoLISP defined commands that get posted here.  Pick on your user name up top, in the Quick Links area at bottom right choose My Settings, in the Preferences Tab pick on Display, and under Emoticon Type pick None.  Save the change, and thereafter, whenever you are signed in, emoticons of the colon-and-letter variety will not show.

Kent Cooper, AIA
0 Likes
Message 15 of 24

Anonymous
Not applicable

Working in model space, enter the command "dz" autocad says DZ unknown command "dz".  I have tried both of the routines, but neither is working.  (Unkown Command)???

0 Likes
Message 16 of 24

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Working in model space, enter the command "dz" autocad says DZ unknown command "dz".  I have tried both of the routines, but neither is working.  (Unkown Command)???


Are the commands loading successfully?  To recap how it should be done, just in case:  Copy the code for one of them and paste it into a plain-text editor like Notepad, and save it into a file called anything you like with a .lsp filetype extension.  In AutoCAD, type AP [or APPLOAD] and navigate to where you saved that file, select it and pick Load, and Close.  It should put a line like this at the Command: prompt line:

 

WhateverYouCalledIt.lsp successfully loaded.

Kent Cooper, AIA
0 Likes
Message 17 of 24

Lee_Mac
Advisor
Advisor

Not too different from those already posted, but try the following:

 

(defun c:delx ( / i s )
    (if (setq s (ssget "_X" (list '(0 . "XLINE") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
        (repeat (setq i (sslength s)) (entdel (ssname s (setq i (1- i)))))
    )
    (princ)
)

 

The command is 'delx'.

 

Lee

0 Likes
Message 18 of 24

hmsilva
Mentor
Mentor

@Kent1Cooper wrote:

@hmsilva wrote:
Do you have Vladimir Nesterovsky's 'xyz_is_paper' loaded?

....

 

....
;;; use (cons 67 (if (xyz_is_paper) 1 0)) for ssget "X" of mspace vs. pspace
;;;  note that pspace will get all objects in layouts, not just current
;;;=========================================================================
(defun-q xyz_is_paper () (> 2 (getvar "cvport") (getvar "tilemode")))

....


Note that while that function, when used in paper space, may get all appropriate objects in all layouts, not just the current one, that only covers the finding of them -- the Erase command will not Erase those that are not in the current layout.  You would need to get into every layout and run the command in each.  If you want to get those in other than the current layout/space, without getting into each one, use something like my version that uses (entdel).


I fully agree with your comments.

I just add Vladimir Nesterovsky's 'xyz_is_paper' with the 'author' comments and explanation, the remaining code was from the 'OP' not mine.

I probably would have written the code using 'entdel', or simply using a 'vla' approach and 'vla-delete'...

 

Henrique

EESignature

0 Likes
Message 19 of 24

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....

If you want to get rid of all Xlines, regardless of where they are, try something like:

 

(defun C:DZ (/ ss1 n)
  (prompt "\nErase all Xlines:")
  (if (setq ss1 (ssget "_X" '((0 . "XLINE"))))
    (repeat (setq n (sslength ss1))

      (entdel (ssname ss1 (setq n (1- n))))
    ); repeat
  ); if
  (princ)
); defun


So now that I've tried that out a little, I find it has a quirk I can't figure out.  In a drawing with two Paper-Space Layouts, if I draw some Xlines in both of them and some in Model Space, it gets rid of the ones in Model Space and in one of the Layouts, but not in both Layouts.  That seems to be the case whether I run it from Model or Paper Space, and whether, when in a Layout, I'm out in Paper Space or into Model Space through a Viewport.  If in Paper Space, it always dumps those in the current Layout but not the other, but always gets those in Model Space, no matter where I run it from.  It apparently finds the right total number of Xlines, but why it doesn't take them out from one of the Layouts, I couldn't say -- I'd be interested in any theories.

Kent Cooper, AIA
0 Likes
Message 20 of 24

hmsilva
Mentor
Mentor
Accepted solution
Using entdel, with ssget "_X", if we are in a layout tab, in a dwg with multi layouts, entdel will only delete objects in current layout and model space, if we are in model space, will delete model and first layout objects...
Or we activate each layout and erase ss, or change each entity to a vlaObject and vla-delete, will delete in all layouts...

Henrique

EESignature

0 Likes