betterway Posted June 14, 2016 Share Posted June 14, 2016 (edited) 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 June 14, 2016 by rkmcswain Added [CODE] Tags Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 We use Lee Macs Layer Director. Works like a charm! Hopefully you find it useful. LayerDirectorV1-1.lsp Quote Link to comment Share on other sites More sharing options...
betterway Posted June 14, 2016 Author Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 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) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
betterway Posted June 14, 2016 Author Share Posted June 14, 2016 Works excellent. Seems to get around the dimensions in other space problem Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 (edited) 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 June 14, 2016 by tmelancon Edited [CODE] to Add Leader,Multileader Quote Link to comment Share on other sites More sharing options...
betterway Posted June 14, 2016 Author Share Posted June 14, 2016 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) ) ) ) Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
betterway Posted June 14, 2016 Author Share Posted June 14, 2016 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). Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
betterway Posted June 14, 2016 Author Share Posted June 14, 2016 I know enough to be dangerous, but what I found interesting was that you can call a subroutine from within the lisp file Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
betterway Posted June 14, 2016 Author Share Posted June 14, 2016 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 ! Quote Link to comment Share on other sites More sharing options...
tmelancon Posted June 14, 2016 Share Posted June 14, 2016 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 14, 2016 Share Posted June 14, 2016 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 ) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.