Link dynamic block attributes

Link dynamic block attributes

athielG9KWR
Explorer Explorer
371 Views
2 Replies
Message 1 of 3

Link dynamic block attributes

athielG9KWR
Explorer
Explorer

I'm trying to link 2 blocks attributes with a field automatically.  

 

I'm new to auto lisps and tried using AI to write the code for me since I'm new to auto lisp but it keeps failing when trying to get an attribute list from the first block

0 Likes
Accepted solutions (1)
372 Views
2 Replies
Replies (2)
Message 2 of 3

paullimapa
Mentor
Mentor

If you're referring to linking an attribute value with another attribute, then try the attached.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 3

Moshe-A
Mentor
Mentor
Accepted solution

@athielG9KWR  hi,

 

For a novice, writing a lisp program to link 2 attributes is not a walk in the park. if your goal is to learn AutoLISP then you should start writing simple ones with Classic Autolisp, cause this one involves VisualLISP/Activex.

 

any way here is my version, great thanks to mr Lee Mac for his contribution 🙏

Command: LNK2ATT

 

enjoy

Moshe

 

 

(vl-load-com); load activex support

;; 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)
)

(defun c:lnk2att (/ get_attrib ; local function
		    ename0 ename1 AcDbAttrib0 AcDbAttrib1 Oid0)

 (defun get_attrib (kmsg / flag pick ename elist)
  (while (and (not flag) (not pick))
   (setvar "errno" 0) ; clear error code
   (setq pick (nentsel (strcat "\nPick " kmsg " attribute: ")))
    
   (cond
    ((= (getvar "errno") 52) ; user press enter
     (setq pick nil ename nil flag t)
    ); case
    ((= (getvar "errno") 07)  ; user missed picking object
     (setq pick nil ename nil flag (prompt "\nNoting selected."))
    ); case
    ((not
       (and
         (setq ename (car pick))
         (setq elist (entget ename))
         (eq (cdr (assoc '0 elist)) "ATTRIB")
       )
     )
     (setq pick nil ename nil flag (prompt "\nSelect attribute please..."))
    ); case
    ( t
     (setq flag t)
    ); case
   ); cond
    
  ); while
    
  ename ; return
 ); get_attrib

 ; here start c:lnk2att
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
   
 (if (and
       (setq ename0 (get_attrib "source"))
       (setq ename1 (get_attrib "target"))
     )
  (progn
   (setq AcDbAttrib0 (vlax-ename->vla-object ename0))
   (setq Oid0 (LM:ObjectID AcDbAttrib0))	; get object id
   (setq AcDbAttrib1 (vlax-ename->vla-object ename1))
   
   (vla-put-textstring AcDbAttrib1 (strcat "%<\\AcObjProp Object(%<\\_ObjId " Oid0 ">%).TextString>%"))

   (vlax-release-object AcDbAttrib1)
   (vlax-release-object AcDbAttrib0)

   (command "._updatefield" "_si" ename1)
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:lnk2att

 

0 Likes