resullins Posted February 15, 2011 Share Posted February 15, 2011 Forgive me if this has already been covered, I'm new here and I couldn't find it. I've been using ACAD for a VERY long time, but have never consciously used a LISP routine. A little bit of research has sort of told me what they are.... but I have NO idea how to make them work. My dilemma: Auto-numbering selct attributes in blocks. I found one here that people say works perfecly, and I've saved it to my support file, and I've loaded it in to my drawing, but how do I actually make it run? Sorry for my ignorance. All help is appreciated! Quote Link to comment Share on other sites More sharing options...
CyberAngel Posted February 15, 2011 Share Posted February 15, 2011 If you look at the code, it should begin with a parenthesis, the word "defun" (for DEfine FUNction), and the name of the routine. Once you load the routine in your AutoCAD session, you only have to type the name to run it. In effect, you've created a new command. Quote Link to comment Share on other sites More sharing options...
resullins Posted February 15, 2011 Author Share Posted February 15, 2011 Ah... thank you. So easy! Now I just have to find the right LISP... the one I tried was SO close to working! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 15, 2011 Share Posted February 15, 2011 This might help: http://lee-mac.com/runlisp.html Quote Link to comment Share on other sites More sharing options...
resullins Posted February 16, 2011 Author Share Posted February 16, 2011 Thanks Lee... It all makes sense now. I've just never had the privilege of working with LISPS before since I'm not much of a programmer. One more question, since you seem to have a metric s-ton of experience in this stuff... I know this topic has been discussed ad-nauseum around here, but I can't seem to find the answer I need. I need to autonumber certain block attributes, with a prefix. For example, I need a whole bunch of blocks to number from L-001 to L-010. Then later in the drawing, I might need to number some from L-201 to L-221. I've found a lisp that will auto-number well, but it won't leave a prefix on there. Has anyone figured this one out? Quote Link to comment Share on other sites More sharing options...
CADkitt Posted February 16, 2011 Share Posted February 16, 2011 Here is a similar problem with a solution. http://www.cadtutor.net/forum/showthread.php?52077-Leading-zero-s-in-attribute-value&highlight=leading Quote Link to comment Share on other sites More sharing options...
BlackBox Posted February 16, 2011 Share Posted February 16, 2011 This might help: http://lee-mac.com/runlisp.html Thanks Lee... It all makes sense now. That was easy... If only I had done the same when I started out! :lol: lmao I'm only kidding, of course. Happy coding, resullins! :wink: Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 16, 2011 Share Posted February 16, 2011 Here is a similar problem with a solution.http://www.cadtutor.net/forum/showthread.php?52077-Leading-zero-s-in-attribute-value&highlight=leading Complete with argument and funny GIF from me. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 16, 2011 Share Posted February 16, 2011 One more question, since you seem to have a metric s-ton of experience in this stuff... I know this topic has been discussed ad-nauseum around here, but I can't seem to find the answer I need. I need to autonumber certain block attributes, with a prefix. For example, I need a whole bunch of blocks to number from L-001 to L-010. Then later in the drawing, I might need to number some from L-201 to L-221. I've found a lisp that will auto-number well, but it won't leave a prefix on there. I wrote this a while back, and have quickly modified it to accept an optional prefix and zero padding - it will number from left to right currently: (defun c:AttNum ( / *error* _StartUndo _EndUndo _PadLeft doc ss lst ) (vl-load-com) ;; © Lee Mac 2010 (defun *error* ( msg ) (if doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) (defun _PadLeft ( str cha len ) (if (< (strlen str) len) (_PadLeft (strcat cha str) cha len) str ) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (setq *tag (cond ( *tag ) ( "TAG1" )) ) (setq *tag (strcase (cond ( (eq "" (setq tmp (getstring (strcat "\nSpecify Attribute Tag to be Numbered <" (setq *tag (cond ( *tag ) ( "TAG1" )) ) "> : " ) ) ) ) *tag ) ( tmp ) ) ) ) (setq *pre (getstring t "\nSpecify Prefix <None> : ")) (initget 6) (setq len (getint "\nSpecify Number Length <Any> : ")) (setq *num (1- (cond ( (getint (strcat "\nSpecify Starting Number <" (itoa (setq *num (1+ (cond ( *num ) ( 0 )) ) ) ) "> : " ) ) ) ( *num ) ) ) ) (if (ssget "_:L" '((0 . "INSERT") (66 . 1))) (progn (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc)) (setq lst (cons (cons (vlax-get o 'InsertionPoint) o) lst ) ) ) (vla-delete ss) (_StartUndo doc) (mapcar (function (lambda ( block ) (mapcar (function (lambda ( attrib ) (if (eq *tag (strcase (vla-get-TagString attrib))) (vla-put-TextString attrib (strcat *pre (_PadLeft (itoa (setq *num (1+ *num))) "0" (cond ( len ) ( 0 ))) ) ) ) ) ) (vlax-invoke (cdr block) 'GetAttributes) ) ) ) (vl-sort lst (function (lambda ( a b ) (< (caar a) (caar b))) ) ) ) (_EndUndo doc) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 16, 2011 Share Posted February 16, 2011 Complete with argument and funny GIF from me. [ATTACH]26234[/ATTACH] lol . Quote Link to comment Share on other sites More sharing options...
resullins Posted February 16, 2011 Author Share Posted February 16, 2011 @Lee: You're AWESOME! That does exactly what I need it to do! You're the best. So glad I found this forum! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 16, 2011 Share Posted February 16, 2011 You're very welcome Resullins - I hope I've sparked your interest in LISP Quote Link to comment Share on other sites More sharing options...
resullins Posted February 16, 2011 Author Share Posted February 16, 2011 You really have. In fact, I'm going to see if I can alter your code to remove on of the input options. We ALWAYS need to change one specific tag, so I think I can take out that prompt. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 16, 2011 Share Posted February 16, 2011 Good luck! - and if you need help, just shout Quote Link to comment Share on other sites More sharing options...
resullins Posted March 3, 2011 Author Share Posted March 3, 2011 Ok Lee: I'm having trouble with this LISP editing. I can't seem to get it right. I'm trying to update the above LISP so that it always alters the attribute called LINE#, and so that the default value for number length is 3. But I seem to keep screwing it up. (Luckily, I'm smart enough to keep a copy of the original that I keep going back to.) Any tips? Quote Link to comment Share on other sites More sharing options...
mathew21 Posted March 3, 2011 Share Posted March 3, 2011 (edited) try the tutorials.. i know they helped me.. you may need a reread them a few times as your learning ( i reread about 20 time for a 4 line command i made) these are the tutorials lee mac refered me to AfraLISP or JeffreySanders Edited March 3, 2011 by mathew21 found link Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 3, 2011 Share Posted March 3, 2011 Just remove the prompts for those parameters should do the trick: (defun c:AttNum ( / *error* _StartUndo _EndUndo _PadLeft doc ss lst len ) (vl-load-com) ;; © Lee Mac 2010 (defun *error* ( msg ) (if doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) (defun _PadLeft ( str cha len ) (if (< (strlen str) len) (_PadLeft (strcat cha str) cha len) str ) ) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) [color=red] (setq *tag "LINE#" len 3)[/color] (setq *pre (getstring t "\nSpecify Prefix <None> : ")) (setq *num (1- (cond ( (getint (strcat "\nSpecify Starting Number <" (itoa (setq *num (1+ (cond ( *num ) ( 0 )) ) ) ) "> : " ) ) ) ( *num ) ) ) ) (if (ssget "_:L" '((0 . "INSERT") (66 . 1))) (progn (vlax-for o (setq ss (vla-get-ActiveSelectionSet doc)) (setq lst (cons (cons (vlax-get o 'InsertionPoint) o) lst ) ) ) (vla-delete ss) (_StartUndo doc) (mapcar (function (lambda ( block ) (mapcar (function (lambda ( attrib ) (if (eq *tag (strcase (vla-get-TagString attrib))) (vla-put-TextString attrib (strcat *pre (_PadLeft (itoa (setq *num (1+ *num))) "0" (cond ( len ) ( 0 ))) ) ) ) ) ) (vlax-invoke (cdr block) 'GetAttributes) ) ) ) (vl-sort lst (function (lambda ( a b ) (< (caar a) (caar b))) ) ) ) (_EndUndo doc) ) ) (princ) ) Untested however. Quote Link to comment Share on other sites More sharing options...
resullins Posted March 31, 2011 Author Share Posted March 31, 2011 Ok, I'm ressurecting this thing in hopes that someone can help me further. I need to alter the Lisp program the very kind LeeMac provided in this thread. I simply need to remove some of the user inputs, and make them default to an attribute I dictate. But the only thing I can find on how to learn LISP is all about AutoLisp. Is there anything out there that's not going to take me 18 years to learn? Quote Link to comment Share on other sites More sharing options...
SLW210 Posted March 31, 2011 Share Posted March 31, 2011 Give AFRALISP a try. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted March 31, 2011 Share Posted March 31, 2011 ... Is there anything out there that's not going to take me 18 years to learn? That entirely depends on you, the student. :wink: 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.