iamvadim Posted May 3, 2017 Posted May 3, 2017 Hello, I have a lisp routine that reads a block attribute and uses it to create an MLeader. The read attribute string is processed 10 times to insert a carriage return at every double space (" "). This function crashes CAD returning a memory access exception. It does not like working with my variables, specifically attval (string from block attribute being processed). Looking at the lisp below, is there a better, more reliable way to manage these variables? Thanks! Vadim ------------------------------------------------------------------------------------------- (command "_AUDCALLOUTINSERT" e "" p) (setq xEnt (entlast)) (setq myEnt xEnt) (setq InsPnt (cdr (assoc 10 (entget xEnt)))) (setq insTyp (cdr (assoc 0 (entget xEnt)))) (setq insLyr (cdr (assoc 8 (entget xEnt)))) ; Get the value of ATTRIBUTE1 (while (and (null val) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq myEnt (entnext myEnt))))))) ) (if (= (strcase "ATTRIBUTE1") (strcase (cdr (assoc 2 enx)))) (progn (setq attval (cdr (assoc 1 enx))) (setq atthgt (cdr (assoc 40 enx))) ; Convert double spaces to CR/LF ; Command repeats 10 times 'cause the function only converts one of the strings at a time (repeat 10 (setq attval (vl-string-subst "\r\n" " " attval))) ) ) ) (entdel xEnt) (command "-layer" "set" insLyr "") (setq PT1 (getpoint "\nPick start point of leader: ")) (setq PT2 (getpoint PT1 "\nPick landing point: ")) (command "._mleader" PT1 PT2 attval) (princ) (command "-layer" "set" curLyr "") Quote
Grrr Posted May 3, 2017 Posted May 3, 2017 If activex is an option: (vl-load-com) (and (setq e (car (entsel "\nPick attributed block: "))) (setq o (vlax-ename->vla-object e)) (vlax-write-enabled-p o) (eq (vla-get-HasAttributes o) :vlax-true) (setq att (vl-some (function (lambda (x) (if (= "ATTRIBUTE1" (strcase (vla-get-TagString x))) x))) (vlax-invoke o 'GetAttributes))) (setq attval (vla-get-TextString att)) (setq atthgt (vla-get-Height att)) (setq attval (vl-string-translate "\r" " " (vl-string-translate "\n" " " attval))) (setq pt1 (getpoint "\nPick start point of leader: ")) (setq PT2 (getpoint pt1 "\nPick landing point: ")) (progn (command "._MLEADER" pt1 pt2 attval) (entmod (append (entget (entlast)) (list (assoc 8 (entget e))))) (not (vla-Delete o)) ) ); and Quote
SLW210 Posted May 4, 2017 Posted May 4, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
iamvadim Posted May 5, 2017 Author Posted May 5, 2017 Thanks for the code! I have it a shot but still get AUD to crash when I run that routine. Will need to play around some more. Once again, thanks! Quote
Grrr Posted May 5, 2017 Posted May 5, 2017 vl-some function returns other than nil or nil. Yes, so to determine exactly what to return the focus must be inside the (lambda) - for instance: (vl-some (function (lambda (x) (= "ATTRIBUTE1" (strcase (vla-get-TagString x))))) (vlax-invoke o 'GetAttributes)) may return T or nil and: (vl-some (function (lambda (x) (if (= "ATTRIBUTE1" (strcase (vla-get-TagString x))) x))) (vlax-invoke o 'GetAttributes)) may return the attribute object or nil Quote
BIGAL Posted May 6, 2017 Posted May 6, 2017 An alternative maybe to the lambda is to use foreach as per this example (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 x)) 'getattributes) (if (= oldtag1 (strcase (vla-get-tagstring att))) (vla-put-textstring att newstr1) )) Quote
iamvadim Posted May 19, 2017 Author Posted May 19, 2017 Trying out new methods of getting the attribute value and using it in an MLeader, but i'm not quite getting the value in att. I'm spinning wheels here, could someone check if i'm getting the attribute correctly? Complete code below. Also as a disclaimer, i'm very new to AutoLISP. Hoping to edit this function to eliminate the the crashing. (defun c:MLCALLOUT (/) (vl-load-com) (sssetfirst nil nil) ; Deselect everything if anything is selected (setq myMode (getvar "tilemode")) ; myMode=0 means we're in paper space (if (= myMode 0) (command ".mspace")) ; if in paper space, switch to model space (setq ss (ssget "_+.:E:S" '((0 . "INSERT,ARC,CIRCLE,*POLYLINE")))) ; get the entity (setq e (ssname ss 0)) ; get the entity's handle (setq p (cadr (cadddr (car (ssnamex ss))))) (setq curLyr (getvar "clayer")) (setq myScale (getvar "cannoscale")) ; get the annotation scale (setq myScale (atoi (substr myScale 3 (- (strlen myScale) 2)))) ;get the cannoscale (if (= myMode 0) (progn (command ".pspace")(setq p (list 0 0 0 )))) ; if we were in paper space, switch back (setq xT (cdr (assoc 0 (entget e)))) ; AUD insert Callout Command (command "_AUDCALLOUTINSERT" e "" p) (setq xEnt (entlast)) (setq myEnt xEnt) (setq insLyr (cdr (assoc 8 (entget xEnt)))) ; Get the value of ATTRIBUTE1 (setq blk (vlax-ename->vla-object myEnt)) (setq tag "ATTRIBUTE1") (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes) ) (entdel xEnt) ; Delete the block entity from AUD Callout Command (command "-layer" "set" insLyr "") ; Set to callout layer ; Create multileader (setq PT1 (getpoint "\nPick start point of leader: ")) (setq PT2 (getpoint PT1 "\nPick landing point: ")) (command "._mleader" PT1 PT2 att) (command "-layer" "set" curLyr "") ; Restore previous layer ) 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.