Jump to content

Drawing Cleanup


betterway

Recommended Posts

New to AutoLisp.

Need some help with a lisp file that moves all dimensions to a dimension layer and text to a text layer. Problem is if say a dimension does not exist in modelspace, but does exist in paperspace, the lisp file does not complete all steps. Same problem if a dimension exists in paperspace but not in modelspace. Have tried testing for a null set but apparently it must not be null if it finds a dimension in the other space. Any suggestions?

Code:

 

; for Dimensions to Dimension Layer
; for Text, Mtext, Leaders and Multileaders to Text Layer
;
(defun C:CLN (
)
(command "_.mspace")
(command
"_.chprop"
(ssget "X" '((0 . "dimension")))
""
"_LAyer"
"DIMENSION"
""
); end command
(command
"_.chprop"
(ssget "X" '((0 . "text,mtext,leader,multileader")))
""
"_LAyer"
"TEXT"
""
); end command
;
(command "_.pspace")
;
(command
"_.chprop"
(ssget "X" '((0 . "dimension")))
""
"_LAyer"
"DIMENSION"
""
); end command
;
(command
"_.chprop"
(ssget "X" '((0 . "text,mtext,leader,multileader")))
""
"_LAyer"
"TEXT"
""
); end command
); end defun


Edited by rkmcswain
Added [CODE] Tags
Link to comment
Share on other sites

Thanks Mr Melancon for the lsp routine.

Tried it and it works great for new dimensions, etc.

Would like to take an existing drawing though and move dimensions to dimension layer, etc.

Link to comment
Share on other sites

Betterway, try this. This one works for the dimensions. I tested it with dimensions in both model and paper space, as well as dimensions in model but not in paper and vice versa. Hope it works on your end. Let me know if not. Ill look into working on the text portion of it.

 

; Changes Dimensions to Layer DIMENSION
; If the layer with such name does not exist, it is created
; Courtesy of VVA - CadTutor.net ENJOY!
; Modified by tmelancon 06/14/2016

(defun c:CLN ()
 (tolayer
   (ssget "X" '((0 . "DIMENSION")))
   "DIMENSION"
   )
 (princ)
)
(defun tolayer ( ss lay / i e )
 ;;; ss - pickset
 ;;; lay -layer name
 (repeat (setq i (sslength ss))
   (entmod
     (subst
       (cons 8 lay)
       (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
       (entget e)
       )
     )
   )
 )

Link to comment
Share on other sites

And here is something just real rough to allow changing the dimensions and your text (I am still learning LISP) so its sort of a quick way of making it work. Someone can definitely chime in to consolidate this code and allow you to add to your list as your please to make it more powerful. Check it out.

 

; Changes all dimensions to Layer DIMENSION
; If the layer with such name does not exist, it is created
; Courtes of VVA - CadTutor.net ENJOY!
; Modified by tmelancon 06/14/2016
(defun c:CLN ()
 (tolayer
   (ssget "X" '((0 . "DIMENSION")))
   "DIMENSION"
   )
(CLN2)
 (princ)
)
(defun tolayer ( ss lay / i e )
 ;;; ss - pickset
 ;;; lay -layer name
 (repeat (setq i (sslength ss))
   (entmod
     (subst
       (cons 8 lay)
       (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
       (entget e)
       )
     )
   )
 )

; Changes selected objects to Layer TEXT
; If the layer with such name does not exist, it is created
; Courtes of VVA - CadTutor.net ENJOY!
; Modified by tmelancon 06/14/2016
(defun CLN2 ()
 (tolayer
   (ssget "X" '((0 . "TEXT,MTEXT,LEADER,MULTILEADER")))
   "TEXT"
   )
 (princ)
)
(defun tolayer ( ss lay / i e )
 ;;; ss - pickset
 ;;; lay -layer name
 (repeat (setq i (sslength ss))
   (entmod
     (subst
       (cons 8 lay)
       (assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
       (entget e)
       )
     )
   )
 )

Edited by tmelancon
Edited [CODE] to Add Leader,Multileader
Link to comment
Share on other sites

Tweaked your first code to include mtext,etc. and it seems to be working.

But am getting an error: extra right paren on input.

 

 

; Changes Dimensions to Layer DIMENSION

; If the layer with such name does not exist, it is created ; Courtes of VVA - CadTutor.net ENJOY!

; Modified by tmelancon 06/14/2016

(defun c:CLN ()

(tolayer

(ssget "X" '((0 . "DIMENSION")))

"DIMENSION"

)

(princ)

)

(tolayer

(ssget "X" '((0 . "text,mtext,*leader")))

"TEXT"

)

(princ)

)

(defun tolayer ( ss lay / i e )

;;; ss - pickset

;;; lay -layer name

(repeat (setq i (sslength ss))

(entmod

(subst

(cons 8 lay)

(assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))

(entget e)

)

)

)

Link to comment
Share on other sites

Check it out again, I just edited it again. Let me know if your still getting the extra paren. There seems to be a loose parentheses somewhere in there. Try the updated code first. Also try to remember to use

 brackets.
Link to comment
Share on other sites

Tried your uploaded code and it is Working Perfectly !

 

Thanks again for your help.

 

ps. Tried using the # button for code, but did not seem to work in the quick reply window (probably in my haste).

Link to comment
Share on other sites

Not a problem, I am just glad I could help. I have been trying to get better and better at LISP over the years. Still nowhere near where I would like to be (i.e. A Mentor like Lee Mac) so I can continue to help others in their beginning journey in Autocad and LISP programming. Take care.

Link to comment
Share on other sites

I know enough to be dangerous, but what I found interesting was that you can call a subroutine from within the lisp file

Link to comment
Share on other sites

Same here. Well glad you learned something new today. Feels good to actually succeed in helping someone. That is my intention to one day know enough about Autocad programming so that one day I can periodically browse CADTutor, TheSwamp, and AUGI to help others. Cheeers.

Link to comment
Share on other sites

FWIW, the code could be shortened to:

(defun c:cln ( / e i s )
   (if (setq s (ssget "_X" '((0 . "*DIMENSION,*TEXT,*LEADER"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (entmod (subst (cons 8 (if (wcmatch (cdr (assoc 0 e)) "*DIMENSION") "DIMENSION" "TEXT")) (assoc 8 e) e))
       )
   )
   (princ)
)

Though, it's debatable whether checking the object type for every item in a single selection set is more efficient than retrieving multiple selection sets and processing each set separately with no check for object type.

Link to comment
Share on other sites

There he is! I knew it was only a matter of time before you would cast your wisdom upon us. Haha thanks for the input. We do appreciate it.

Link to comment
Share on other sites

Thank you for all the lisp help today.

Will take a look to try and understand the couple of techniques presented today .... always looking for a betterway !

Link to comment
Share on other sites

Lee how would one edit your code to change the color of the added layers (if they didnt exist). Just curious so I can learn.

Link to comment
Share on other sites

There he is! I knew it was only a matter of time before you would cast your wisdom upon us. Haha thanks for the input. We do appreciate it.

 

Thank you for your flattery Tyler, there are usually many ways to skin a cat in AutoLISP.

 

Lee how would one edit your code to change the color of the added layers (if they didnt exist). Just curious so I can learn.

 

It would require a separate expression to entmake the layer with the desired properties, rather than relying on the entmod expression to automatically create the layer with default properties.

 

Here is an example:

(defun c:cln ( / e i s )
   (if (setq s (ssget "_X" '((0 . "*DIMENSION,*TEXT,*LEADER"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (entmod
               (subst
                   (cons 8
                       (if (wcmatch (cdr (assoc 0 e)) "*DIMENSION")
                           (createlayer "DIMENSION" 1)
                           (createlayer "TEXT"      2)
                       )
                   )
                   (assoc 8 e) e
               )
           )
       )
   )
   (princ)
)
(defun createlayer ( lay col )
   (if (not (tblsearch "layer" lay))
       (entmake
           (list
              '(000 . "LAYER")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbLayerTableRecord")
              '(070 . 0)
               (cons 02 lay)
               (cons 62 col)
           )
       )
   )
   lay
)

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