pvr Posted May 1 Posted May 1 Hello, I have this code I use to automatically annotate my details (FAS). It takes the block´s name and its description and inputs them into two attributes of the block I use to define a specific Multileader (Smart Multileader). I would like to make it work when selecting nested blocks. I have tried by using nentselp but cannot find the right way. Any help would be really appreciated. Thanks in advance! (defun getDesc (blk / Com) (cond ((not (vl-catch-all-error-p (vl-catch-all-apply (function (lambda ( ) (setq com (vla-get-Comments (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) blk)))))))) Com) (t nil))) (defun c:FAS (/ ent entl obj) (cond ((not (setq ent (car (entsel "\nSelect block: "))))) ((not (eq (cdr (assoc 0 (entget ent))) "INSERT")) (princ "\nInvalid object!")) ((setq pt (getpoint "\nSpecify first point: ")) (setq entl (entlast)) (setvar "cmleaderstyle" "Standard") (vl-cmdf "_.mleader" "_non" pt "\\") (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf "")) (setq txt (vlax-get-property (setq obj (vlax-ename->vla-object ent)) (if (vlax-property-available-p obj 'EffectiveName) 'EffectiveName ;if obj has EffectiveName. use EffectiveName, else use 'Name 'Name ) ) ) (if (setq desc (getDesc (cdr (assoc 2 (entget ent))))) (setq txt(strcat txt "\n" desc)) ) ;(alert txt) (if (not (equal entl (setq entl (entlast)))) (vla-put-textstring (vlax-ename->vla-object entl) txt) ) ) ) (princ) ) (defun c:FAS (/ ent entl obj) (cond ((not (setq ent (car (entsel "\nSelect block: "))))) ((not (eq (cdr (assoc 0 (entget ent))) "INSERT")) (princ "\nInvalid object!")) ((setq pt1 (getpoint "\nSpecify first point: ")) (setq pt2 (getpoint "\nSpecify second point: ")) (setq entl (entlast)) (setq name (vlax-get-property (setq obj (vlax-ename->vla-object ent)) (if (vlax-property-available-p obj 'EffectiveName) 'EffectiveName ;if obj has EffectiveName. use EffectiveName, else use 'Name 'Name ) ) ) (setq desc (getDesc (cdr (assoc 2 (entget ent))))) (setvar 'attdia 0) (setvar 'attreq 1) (setvar "cmleaderstyle" "Smart Multileader") (command-s "mleader" pt1 pt2 name "" desc "" "" "") ) ) (princ) ) (vl-load-com) (princ) dwg1.dwg Quote
CyberAngel Posted May 1 Posted May 1 First impressions: Obviously there's a lot going on here. I don't consider myself an expert on AutoLISP, but I've dabbled in many languages. Anyone remember SNOBOL? APL? AutoLISP is not case sensitive, but using "Com" and "com" could confuse the casual reader (such as myself). Not only that, COM is the Component Object Model, which is a Microsoft thing you can use with AutoLISP; if that variable has nothing to do with COM, I'd use something else (again to avoid confusion). You can overload functions in AutoLISP, but I think you have to use different argument lists. Since there are two definitions of FAS here with the same argument list, the first one will be ignored. Since the code is different, I'm not sure which one to discuss. I have not seen the command-s keyword before. Interesting. Wouldn't (logand 1 (getvar 'CMDACTIVE)) be equivalent to (eq (logand 1 (getvar 'CMDACTIVE)) 1)? Wait, no it isn't. This is the kind of thing that trips me up. Welcome to the forum! A better programmer will be along shortly to help you. 1 Quote
BIGAL Posted May 2 Posted May 2 "I have not seen the command-s keyword before. Interesting." Check out help, in simple terms is like a catch errors if you leave something out. I tend not to use but make sure command works. Including stuff like Text has 2 versions with or without a height. Quote
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.