The workings of Attsync?

Discussion in 'AutoCAD' started by T.Willey, Nov 19, 2004.

  1. T.Willey

    T.Willey Guest

    Can anyone tell me how attsync works?
    I need to write a routine like it, but I can't use it.

    Thanks.
    Tim
     
    T.Willey, Nov 19, 2004
    #1
  2. T.Willey

    Kelie Feng Guest

    I'd say redefine the block and re-insert.
     
    Kelie Feng, Nov 19, 2004
    #2
  3. T.Willey

    T.Willey Guest

    I am doing that. I am copying the defination from another drawing and bringing it in, and changing the current defination. The problem is when you have attribute (more in the new block def then the old one) attsyne only works once. So that is why I am looking for a new method to do the syncing. I hope it is possible. I think it is if someone has done it, why can't I? But we will see.

    Thanks.
    Tim
     
    T.Willey, Nov 19, 2004
    #3
  4. T.Willey

    Joe Burke Guest

    Hi Tim,

    An example of how you might workaround the attsync problem you mentioned. Which BTW,
    I haven't investigated.

    The idea is by dealing with each block reference, and each attribute reference
    contained, the function does what attsync would do. While avoiding an attempt to
    update an attribute reference, which may not exist in a block reference, because
    attribute definitions were added to a revised block definition.

    IOW, it should do the same thing as the function I posted recently in your other
    thread. But it doesn't use (command "attsync" ... )

    (defun c:AttSyncColor (/ doc blocks clr ename blkref blkname blkdef attlst)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (setq blocks (vla-get-blocks doc))
    (setq clr (getint "\nEnter attribute color number: "))
    (setq ename (car (entsel "\nSelect block with attributes: ")))
    (setq blkref (vlax-ename->vla-object ename))
    (setq blkname (vlax-get blkref 'Name))
    (setq blkdef (vla-item blocks blkname))
    (vlax-for x blkdef
    (if (equal "AcDbAttributeDefinition" (vlax-get x 'ObjectName))
    (vlax-put x 'Color clr)
    )
    )
    (ssget "x" (list (cons 0 "INSERT") (cons 2 blkname)))
    (vlax-for x (vlax-get doc 'ActiveSelectionSet)
    (setq attlst (vlax-invoke x 'GetAttributes))
    (foreach x attlst
    (vlax-put x 'Color clr)
    )
    )
    (princ)
    ) ;end

    BTW, AFAIK there is no VLISP method which does what (command "attsync" ... ) does.
    Though maybe I simply haven't discovered such.

    Joe Burke
     
    Joe Burke, Nov 20, 2004
    #4
  5. T.Willey

    James Allen Guest

    Hi Tim,
    AFAIK, the re-insert part of what Kelie mentioned is the key to "adding"
    attribute references to existing block references. I'm guessing you
    probably already know that syncing the properties of existing attribute
    references is relatively easy; something like what Joe posted. And I have
    found that removing attribute references from block references is even
    easier and I actually use that ability, though I myself question the wisdom
    of doing so. But directly adding attribute references to existing block
    references (without reinserting after redefining) is another matter. I do
    not think it is possible with ActiveX methods (I've checked, but would love
    to be informed that I just missed it), and personally do not think it would
    be worth it, if possible (and it might well be), with dxf manipulation. Of
    course, if you re-insert to add attribute references without changing the
    existing ones, you will have to record the existing properties so you can
    re-apply them after the re-insert.
    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO

    bringing it in, and changing the current defination. The problem is when
    you have attribute (more in the new block def then the old one) attsyne only
    works once. So that is why I am looking for a new method to do the syncing.
    I hope it is possible. I think it is if someone has done it, why can't I?
    But we will see.
     
    James Allen, Nov 22, 2004
    #5
  6. T.Willey

    T.Willey Guest

    Joe,

    My problem seems to be more when I change a block definition with more attributes then the old one had. I need to be able to make all the blocks look the way they should, but the problems lie there. If the old def had only one attribute and the new def has two, then only one is displayed until I run the attsync command. I was trying to figure out how to make it show both and in the right locations without having to reinsert each block. I haven't found a way yet either.

    That was my feat, that there is no lisp/vlisp/activex method to do what it does.
    Thanks for trying.
    Tim
     
    T.Willey, Nov 22, 2004
    #6
  7. T.Willey

    T.Willey Guest

    James,

    The way I have it working right now is:
    Change the block definition
    Grab the attribute info
    Run attsync
    Put the attribute info back

    The problem is that attsync will stop working on blocks that have different numbers of attributes. I was hoping for a way where I wouldn't have to re-insert the blocks. If there was a way to add attributes like there is to delete them, or even if there was a way to update the block to the new definition (attributes and all) then all would be solved, but that is wishing for a miracle (at least that is the way it is looking as of now).

    Thanks for trying.
    Tim
     
    T.Willey, Nov 22, 2004
    #7
  8. Tim,

    You will have to get a selection set of all existing inserts
    and add the new attribute(s) to each insertion based on
    the block definition. Attdefs are subentities of the block
    definition, Attribs are subentities of the insert definition.

    You should have a file on your system called attredef.lsp
    which should provide some information for you.


    --
    Autodesk Discussion Group Facilitator



    attributes then the old one had. I need to be able to make all the blocks
    look the way they should, but the problems lie there. If the old def had
    only one attribute and the new def has two, then only one is displayed until
    I run the attsync command. I was trying to figure out how to make it show
    both and in the right locations without having to reinsert each block. I
    haven't found a way yet either.
     
    Jason Piercey, Nov 22, 2004
    #8
  9. T.Willey

    T.Willey Guest

    Jason,

    Thanks. I will look into that when I get a chance. Deadlines came up this morning, have to do drafting now =( .

    Tim
     
    T.Willey, Nov 22, 2004
    #9
  10. Real work... bummer ;) If you are sticking with
    activeX and want to use this with objectDBX
    you won't be able to use selection sets, just thought
    I should mention that.

    --
    Autodesk Discussion Group Facilitator



    this morning, have to do drafting now =( .
     
    Jason Piercey, Nov 22, 2004
    #10
  11. T.Willey

    James Allen Guest

    Hi Jason,
    Are you saying that you *can* directly add attribute references? Because a
    quick look over attredef.lsp looks to me like it is actually re-inserting
    blocks to get the effect of "adding" attributes. And looking at it now it
    seems to me like the only way to entmake it is to entmake the entire complex
    block reference, in which case you have to delete the old one because you
    just effectively re-inserted it. Am I missing something (I hope)?
     
    James Allen, Nov 22, 2004
    #11
  12. T.Willey

    James Allen Guest

    IMHO, re-inserting is how to "update the block to the new definition
    (attributes and all)". Something like this should take care of your miracle
    unless I am missing something.

    ssget your inserts
    foreach insert:
    insert new
    match all props
    delete old

    James


    different numbers of attributes. I was hoping for a way where I wouldn't
    have to re-insert the blocks. If there was a way to add attributes like
    there is to delete them, or even if there was a way to update the block to
    the new definition (attributes and all) then all would be solved, but that
    is wishing for a miracle (at least that is the way it is looking as of now).
     
    James Allen, Nov 22, 2004
    #12
  13. I guess that statement was a bit misleading and
    after reviewing the reference I mentioned, you
    are correct. Attredef.lsp does just re-insert
    each instance of the block reference. For some
    reason I had, in the back of my mind, a thought
    of adding the missing attribute references.

    Looks like a re-insert is the way to go.
     
    Jason Piercey, Nov 22, 2004
    #13
  14. T.Willey

    T.Willey Guest

    I just want to say thanks for everyone's help. I guess the only way is to search the drawing, find all instances, grab the info needed, delete old blocks, and insert new ones.

    Tim
     
    T.Willey, Nov 22, 2004
    #14
  15. T.Willey

    T.Willey Guest

    Here is how I did it.

    Tim

    (defun ReInsertBlock (BlockName DocBlock / temp1 temp2 temp3 temp4 temp5 temp6
    cnt1 EndList BlkColl SpaceList BlkList)

    (if (not DocBlock)
    (setq DocBlock (vla-get-ActiveDocument (vlax-get-ACAD-Object)))
    )
    (setq BlkColl (vla-get-Blocks DocBlock))
    (vlax-for item BlkColl
    (if
    (or
    (vl-string-search "*MODEL_SPACE" (strcase (vla-get-Name item)))
    (vl-string-search "*PAPER_SPACE" (strcase (vla-get-Name item)))
    )
    (setq SpaceList (cons item SpaceList))
    )
    )
    (foreach item SpaceList
    (setq cnt1 0)
    (while (/= cnt1 (vla-get-Count item))
    (setq temp1 (vla-Item item cnt1))
    (if
    (and
    (vlax-property-available-p temp1 'Name)
    (= (vla-get-Name temp1) BlockName)
    )
    (setq BlkList (cons temp1 BlkList))
    )
    (setq cnt1 (1+ cnt1))
    )
    )
    (foreach item BlkList
    (setq temp2 (vla-get-OwnerID item))
    (foreach item2 (safearray-value (vlax-variant-value (vla-GetAttributes item)))
    (setq temp3 (cons (vla-get-TextString item2) temp3))
    )
    (setq temp3 (reverse temp3))
    (foreach item2 SpaceList
    (if (= temp2 (vla-get-ObjectID item2))
    (setq temp4 item2)
    )
    )
    (setq temp5
    (vla-InsertBlock
    temp4
    (vla-get-InsertionPoint item)
    BlockName
    (vla-get-XScaleFactor item)
    (vla-get-YScaleFactor item)
    (vla-get-ZScaleFactor item)
    (vla-get-Rotation item)
    )
    )
    (setq temp6 (safearray-value (vlax-variant-value (vla-GetAttributes temp5))))
    (while
    (and
    (> (length temp3) 0)
    (> (length temp6) 0)
    )
    (vla-put-TextString (car temp6) (car temp3))
    (setq temp3 (cdr temp3))
    (setq temp6 (cdr temp6))
    )
    (setq temp3 nil)
    (vla-put-Layer temp5 (vla-get-Layer item))
    (vla-Delete item)
    )
    )
     
    T.Willey, Nov 22, 2004
    #15
  16. T.Willey

    Jürg Menzi Guest

    Hi James
    No problem to do that, see thread from Laura:
    'blockswap with extra attribute', Tue, 9 Nov 2004
    my answer from Mon, 15 Nov 2004

    Cheers
     
    Jürg Menzi, Nov 23, 2004
    #16
  17. T.Willey

    Joe Burke Guest

    Hi Juerg,

    I missed that thread when it was current. Thanks for the pointer.

    The code you posted looks interesting, though I haven't studied it in depth.

    Joe Burke
     
    Joe Burke, Nov 23, 2004
    #17
  18. In that code you are adding the attribute reference to
    the block definition, not the insert definition (which
    is what James was asking about) then running the
    attsync command to update the insertions.

    You can't simply add an attribute to an insert in the
    same way you can add one to block, can you?
     
    Jason Piercey, Nov 23, 2004
    #18
  19. T.Willey

    James Allen Guest

    Hi Jürg, ditto what Jason said.

    Add attribute definition to block definition = no problem.
    Add attribute reference to block reference?

    My study leads me to believe that the latter requires replacing the block
    reference.

    Thank you,

    James
     
    James Allen, Nov 23, 2004
    #19
  20. T.Willey

    Jürg Menzi Guest

    Hi Jason
    AFAIK, you must copy the block reference to a new name, add there the
    attribute definition and set the desired insert to the new name.

    For cloning a block reference to a new name visit my homepage -> Free Stuff
    and search for 'VxCloneBlockRef'.

    Cheers
     
    Jürg Menzi, Nov 23, 2004
    #20
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.