Put a field link in attribs

Discussion in 'AutoCAD' started by Marc'Antonio Alessi, Feb 18, 2005.

  1. I have a block with 3 (or more) attribs, the tags are:

    ITEM_NO
    ITEM_NO_LINK1
    ITEM_NO_LINK2
    ....

    I need to create a link using Field from the main
    ITEM_NO attrib to the others ITEM_NO_LINK1, ITEM_NO_LINK2, ...

    without use Attedit (or similar commands)
    - create the link with the Filed data dialogue for the
    first ITEM_NO_LINK1 to ITEM_NO
    - copy the string value from Filed data dialogue of the
    ITEM_NO_LINK1 in text value of the other(s) attrib(s)

    So when I edit the value of the main item number (ITEM_NO)
    all the others linked attribs change as well.

    This is what I can do:

    (setq MAtObj (vlax-ename->vla-object (car (nentsel))))
    (setq AttOId (vla-get-ObjectID AttObj))

    (setq StrVal
    (strcat
    "%<\\AcObjProp Object(%<\\_ObjId " (itoa AttOId) ">%).TextString>%"
    )
    )

    (setq LAtObj (vlax-ename->vla-object (car (nentsel))))
    (vla-put-textstring LAtObj StrVal)

    ....then select attrib ITEM_NO_LINK2...

    --

    Is this correct?
    Side effects?
    Is ObjectID always a integer?

    The final goal is to select the block and put the link
    in all the attribs with a matching filter criteria
    without ask anything.


    --

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    --
     
    Marc'Antonio Alessi, Feb 18, 2005
    #1
  2. Here is my attempt, any hint?

    Marco

    --

    ; -------------------------------------------------------------------------
    ; Block_Utils.lsp - 19/02/2005
    ; Copyright ©2005 Marc'Antonio Alessi, Italy - All rights reserved
    ; http://xoomer.virgilio.it/alessi
    ; -------------------------------------------------------------------------
    ; ALE_BlockFieldLinkAttribByTag - ALE_vlax-GetAttributes
    ; -------------------------------------------------------------------------
    ;
    ; Function: ALE_BlockFieldLinkAttribByTag
    ;
    ; Version 1.00 - 19/02/2005
    ;
    ; Description:
    ; Make a "Field" linking the attrib with tag = SrcTag with all
    ; the others attribs that respect wcmatch the condition in AttTgs
    ;
    ; Arguments:
    ; EntNam: valid entity name or nil to select a Block
    ; SrcTag: Source Tag to link
    ; AttTgs: wcmatch string of attribs to link with SrcTag
    ;
    ; Example:
    ; (ALE_BlockFieldLinkAttribByTag nil "Item_No" "Item_No_Lnk??")
    ; (ALE_BlockFieldLinkAttribByTag nil "$LAY_ITEM_NBMR" "*Item*")
    ;
    ; Notes:
    ; if the block contains tags (SrcTag) with the same name, the first found
    ; will be linked to the following ones that respect wcmatch the condition
    ;
    (defun ALE_BlockFieldLinkAttribByTag (EntNam SrcTag AttTgs /
    FlgSlt BlkObj Obj_Id AttLst StrVal)
    (vl-load-com)
    (cond
    ( (and
    (not EntNam)
    (while (not FlgSlt) ; block with attribs
    (if (setq EntNam (ssget "_:E:S" '((0 . "INSERT") (66 . 1))))
    (not (setq FlgSlt T))
    (if (= 52 (getvar "ERRNO"))
    (setq FlgSlt T)
    (princ
    "\nNo objects selected or compatible with the function, try again!"
    )
    )
    )
    )
    )
    ;|e|; (princ "\nFunction cancelled. ")
    )
    ( (not (or (= (type EntNam) 'ENAME) (setq EntNam (ssname EntNam 0))))
    ;|e|; (alert "Selection Error!")
    )
    ( (=
    (vl-catch-all-apply
    'vla-get-HasAttributes
    (list (setq BlkObj (vlax-ename->vla-object EntNam)))
    )
    :vlax-true
    )
    (setq
    AttLst (ALE_vlax-GetAttributes BlkObj)
    SrcTag (strcase SrcTag)
    AttTgs (strcase AttTgs)
    Obj_Id (caddr (assoc SrcTag AttLst))
    StrVal (strcat
    "%<\\AcObjProp Object(%<\\_ObjId "
    (itoa Obj_Id) ">%).TextString>%"
    )
    )
    (foreach ForElm AttLst
    (cond
    ( (= Obj_Id (caddr ForElm)) )
    ( (wcmatch (car ForElm) AttTgs)
    (vla-put-textstring (cadddr ForElm) StrVal)
    )
    )
    )
    (vla-update BlkObj)
    )
    ( T
    (prompt "\nBlock non found or not valid, or no attribute to update. ")
    )
    )
    (princ)
    )
    ;
    ; Function: ALE_vlax-GetAttributes
    ;
    ; Version 1.00 - 19/02/2005
    ;
    ; Description:
    ; Reads attribute values from a block Object
    ;
    ; Arguments:
    ; BlkObj: Block Object with Attributes [VLA-OBJECT]
    ;
    ; Return Value:

    • ; '(("Tag1" "Val1" 2130160792 #<VLA-OBJECT IAcadAttributeReference
      0abb21e4>) ...)
      ; ObjectID
      ;
      (defun ALE_vlax-GetAttributes (BlkObj / )
      (mapcar
      '(lambda (LmbDat)
      (list
      (vla-get-TagString LmbDat)
      (vla-get-TextString LmbDat)
      (vla-get-ObjectID LmbDat)
      LmbDat
      )
      )
      (vlax-invoke BlkObj 'GetAttributes)
      )
      )
      ;
      (princ)
     
    Marc'Antonio Alessi, Feb 19, 2005
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.