CadFrank Posted July 22, 2016 Posted July 22, 2016 Hi, I'd like to know if theirs a way of retreiving a textstring with a field value then modify the field and resend it back into the attribute. Regards Quote
broncos15 Posted July 22, 2016 Posted July 22, 2016 Lee Mac has some great field code LISP routines. This one http://www.lee-mac.com/fieldcode.html should be very helpful. Quote
CadFrank Posted July 22, 2016 Author Posted July 22, 2016 Is it compatible with block attribute because I can't seem to get any values out of it when I print it. Quote
Lee Mac Posted July 22, 2016 Posted July 22, 2016 Lee Mac has some great field code LISP routines. This one http://www.lee-mac.com/fieldcode.html should be very helpful. Thank you for the recommendation & praise broncos - that is the function that I would also have suggested to accomplish this task based on the description given by the OP. Is it compatible with block attribute because I can't seem to get any values out of it when I print it. Yes - my LM:fieldcode function linked above is compatible with any annotation object capable of housing a Field Expression - how are you evaluating the function? Quote
CadFrank Posted August 15, 2016 Author Posted August 15, 2016 (edited) (defun c:test () (setq objEnt (entsel "\nSelect block :")) (setq eNameEnt (vlax-ename->vla-object objEnt)) (setq objEnt2 (car (car (entsel objEnt))) (setq attribute (LM:GETATTRIBUTEVALUE eNameEnt "LONG")) (setq field (LM:fieldcode objEnt)) (print field) ) (defun LM:GETATTRIBUTEVALUE (BLOCK TAG) (vl-some (function (lambda (ATTRIB) (if (eq TAG (strcase (vla-get-tagstring ATTRIB))) (vla-get-textstring ATTRIB) ) ;_ fin deif ) ;_ fin delambda ) ;_ fin defunction (vlax-invoke BLOCK 'GETATTRIBUTES) ) ;_ fin devl-some ) ;_ fin dedefun ;; Field Code - Lee Mac ;; Returns the field expression associated with an entity (defun LM:fieldcode ( ent / replacefield replaceobject enx ) (defun replacefield ( str enx / ent fld pos ) (if (setq pos (vl-string-search "\\_FldIdx" (setq str (replaceobject str enx)))) (progn (setq ent (assoc 360 enx) fld (entget (cdr ent)) ) (strcat (substr str 1 pos) (replacefield (cdr (assoc 2 fld)) fld) (replacefield (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx))) ) ) str ) ) (defun replaceobject ( str enx / ent pos ) (if (setq pos (vl-string-search "ObjIdx" str)) (strcat (substr str 1 (+ pos 5)) " " (LM:ObjectID (vlax-ename->vla-object (cdr (setq ent (assoc 331 enx))))) (replaceobject (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx))) ) str ) ) (if (and (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION") (setq enx (cdr (assoc 360 enx))) (setq enx (dictsearch enx "ACAD_FIELD")) (setq enx (dictsearch (cdr (assoc -1 enx)) "TEXT")) ) (replacefield (cdr (assoc 2 enx)) enx) ) ) ;; ObjectID - Lee Mac ;; Returns a string containing the ObjectID of a supplied VLA-Object ;; Compatible with 32-bit & 64-bit systems (defun LM:ObjectID ( obj ) (eval (list 'defun 'LM:ObjectID '( obj ) (if (and (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring) ) (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false) '(itoa (vla-get-objectid obj)) ) ) ) (LM:ObjectID obj) ) ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) ) Edited August 17, 2016 by CadFrank Quote
Lee Mac Posted August 15, 2016 Posted August 15, 2016 Your variable 'objEnt' refers to a block reference entity, not an annotation object. Quote
CadFrank Posted August 16, 2016 Author Posted August 16, 2016 Oh I see so Even though it's an annotative attribute since it's nested in a block it does'nt work. So I need to get the attribute and not the block. Quote
Lee Mac Posted August 16, 2016 Posted August 16, 2016 So I need to get the attribute and not the block. Exactly - Feel free to ask if you require assistance in this respect. Quote
CadFrank Posted August 17, 2016 Author Posted August 17, 2016 Exactly - Feel free to ask if you require assistance in this respect. I'm not sure which functions to use to get Entities inside and Entity. So I think I need help !!! I've updated my code up there Regards Quote
Lee Mac Posted August 17, 2016 Posted August 17, 2016 I'm not sure which functions to use to get Entities inside and Entity. So I think I need help !!! The entnext function is the key - consider the following example: (defun c:test ( / ent enx fld ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ;; non-nil return - stay in loop ) ( (null ent) nil ;; Exit loop ) ( (or (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) (/= 1 (cdr (assoc 66 enx))) ) (princ "\nSelected object is not an attributed block.") ;; non-nil return - stay in loop ) ( (progn (setq ent (entnext ent) enx (entget ent) ) (while (and (= "ATTRIB" (cdr (assoc 0 enx))) (/= "LONG" (cdr (assoc 2 enx)))) (setq ent (entnext ent) enx (entget ent) ) ) (/= "LONG" (cdr (assoc 2 enx))) ) (princ "\nSelected block does not contain \"LONG\" attribute.") ;; non-nil return - stay in loop ) ( (null (setq fld (LM:fieldcode ent))) (princ "\n\"LONG\" attribute does not contain a field.") ) ( t (prompt "\nAttribute tag: ") (prompt (cdr (assoc 2 enx))) (prompt "\nAttribute value: ") (prompt (cdr (assoc 1 enx))) (prompt "\nField code: ") (prompt fld) ) ) ) ) (princ) ) Quote
CadFrank Posted August 18, 2016 Author Posted August 18, 2016 Thanks Lee it's exactly what I needed 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.