TheSwamp

CAD Forums => CAD General => Topic started by: Verticalmojo#2 on January 24, 2012, 03:03:52 PM

Title: replace block with another block that has attributes
Post by: Verticalmojo#2 on January 24, 2012, 03:03:52 PM
Hello!

Is there a way to replace a block with another block and transfer the new attributes, without syncing? I would like to keep the position of the existing attributes... Syncing would place the attributes back to the original orientation....

Thanks in advance...
Title: Re: replace block with another block that has attributes
Post by: ronjonp on January 24, 2012, 04:58:09 PM
Does the new block have the same attributes and tags as the old block? If so, I'd think you'd just be able to redefine the block.
Title: Re: replace block with another block that has attributes
Post by: Rob... on January 24, 2012, 07:42:30 PM
Good answer.
Title: Re: replace block with another block that has attributes
Post by: danallen on January 24, 2012, 09:24:27 PM
Try this one from here:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Amends/td-p/806704/page/2 (http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Amends/td-p/806704/page/2)

Code: [Select]
REPLACE.LSP - (Block Replace) - (c) 1990 Richard D. Howard
all rights reserved - no warranty, express or implied

The included files may be used and copied for non-profit
purposes only. If you wish to include any of the files in a
commercial program, contact the author.

---------------

REPLACE, replaces selected blocks with a specified block,
retaining all of the original properties. REPLACE handles blocks
with attribute data correctly, and can optionally allow entry of
new attributes at runtime. This makes REPLACE ideal for updating
blocks whose definition has changed (AutoCAD does not updates the
attributes in such instances). When replacing attributes, REPLACE
actually erases the old block and substitutes the new one
retaining as much of the former data as possible. The two fields
that are definately modified are "entity name", and "handle
number" (because the block really is new). If you require these
to remain the same, don't use REPLACE. If no attributes are
present, REPLACE simply updates the name attached to the original
block insert. This retains ALL the inserts data, including the
entity name and handle.
Title: Re: replace block with another block that has attributes
Post by: Verticalmojo#2 on January 25, 2012, 12:59:27 PM
Does the new block have the same attributes and tags as the old block? If so, I'd think you'd just be able to redefine the block.

Yes it does, with an additional attribute that does not show unless you redefine the block. Redefining loses the attributes orientation. I would like to be able to have the new attribute available without losing the orientation of the original ones.


Try this one from here:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Amends/td-p/806704/page/2 (http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Amends/td-p/806704/page/2)



Isn't this the same as the express tool?
Title: Re: replace block with another block that has attributes
Post by: danallen on January 25, 2012, 01:13:17 PM
No, the lisp in the post is by Richard D. Howard and will keep attributes if the name is the same
Title: Re: replace block with another block that has attributes
Post by: Mark on January 25, 2012, 01:15:25 PM
Long time no see there Mojo! Welcome back stranger. :)
Title: Re: replace block with another block that has attributes
Post by: Verticalmojo#2 on January 25, 2012, 06:21:29 PM
I tried to post earlier today but couldn't get to the swamp... glad to see its working again. :)

No, the lisp in the post is by Richard D. Howard and will keep attributes if the name is the same

I may not be understanding correctly, but the express tool does the same thing as well. If the new block has extra attributes and I replace the old block, the information is transferred just fine, but the the block needs to be redefined to show the additional attributes. This causes the block and its attributes to lose its position... I have to reposition everything, to me that's over 1000 blocks, and with 6 attributes per block.... UGH! if I can cut it down to just possibly having to just move one attribute that would be awesome....

Long time no see there Mojo! Welcome back stranger. :)


Hello Mark! thanks! Good to be back. Can you send me my password for my original account to verticalmojo@gmail? seems that when I try to reset it sends it to the @swamp.org email I used to use and I'm not sure if it exists and if it did I wouldn't have a clue how to get into it. No rush, just when you get a chance... Thanks!
Title: Re: replace block with another block that has attributes
Post by: ronjonp on January 25, 2012, 07:35:37 PM
Not the prettiest thing but give it a try  :laugh:  Keep in mind this only looks at the insertion points and tries to place them in the original location found.

Have fun  :-)

Code: [Select]
(defun c:attsync2 (/ _name _gettatts _lst atts e name ss)
  (defun _lst (ss / e n out)
    (setq n -1)
    (if (= (type ss) 'pickset)
      (while (setq e (ssname ss (setq n (1+ n)))) (setq out (cons (vlax-ename->vla-object e) out)))
    )
  )
  (defun _attpositions (block / att result)
    (foreach att (vlax-invoke block 'getattributes)
      (setq result (cons (list (vla-get-handle att)
       (vlax-get att 'insertionpoint)
       (vlax-get att 'textalignmentpoint)
)
result
   )
      )
    )
  )
  (defun _name (b)
    (cond ((vlax-property-available-p b 'effectivename) (vla-get-effectivename b))
  ((vlax-property-available-p b 'name) (vla-get-name b))
    )
  )
  (if (and (setq e (car (entsel "\nSelect block to sync: ")))
   (setq name (_name (vlax-ename->vla-object e)))
   (setq ss (ssget "_x" (list (cons 0 "insert"))))
      )
    (progn (foreach x (_lst ss) (and (eq (_name x) name) (setq atts (cons (_attpositions x) atts))))
   (command "._attsync" "_s" e "_yes")
   (foreach x (apply 'append atts)
     (if (and (setq e (handent (car x))) (setq e (vlax-ename->vla-object e)))
       (progn (vl-catch-all-apply 'vlax-put (list e 'insertionpoint (cadr x)))
      (vl-catch-all-apply 'vlax-put (list e 'textalignmentpoint (caddr x)))
       )
     )
   )
    )
  )
  (princ)
)
Title: Re: replace block with another block that has attributes
Post by: danallen on January 26, 2012, 01:13:17 AM
I tried to post earlier today but couldn't get to the swamp... glad to see its working again. :)

You are correct, my mistake, I misunderstood your request.
Title: Re: replace block with another block that has attributes
Post by: Mark on January 26, 2012, 08:58:04 AM
Hello Mark! thanks! Good to be back. Can you send me my password for my original account to verticalmojo@gmail? seems that when I try to reset it sends it to the @swamp.org email I used to use and I'm not sure if it exists and if it did I wouldn't have a clue how to get into it. No rush, just when you get a chance... Thanks!

Quote
The profile for VerticalMojo has been updated successfully.

Try that. :)
Title: Re: replace block with another block that has attributes
Post by: VerticalMojo on January 27, 2012, 03:23:50 PM
You are correct, my mistake, I misunderstood your request.
Perhaps I could have explained my request better, so I'm sure that I am to blame for that!  :laugh:

Not the prettiest thing but give it a try  :laugh:  Keep in mind this only looks at the insertion points and tries to place them in the original location found.

Perfect! Thanks!

Try that. :)

Thanks! Wow its been awhile!  :kewl:

You can delete that other profile (verticalmojo#2), no need for it.
Title: Re: replace block with another block that has attributes
Post by: ronjonp on January 27, 2012, 03:29:18 PM
Glad it worked for you  :-D
Title: Re: replace block with another block that has attributes
Post by: Hugo on June 06, 2012, 01:21:08 AM
Thank ronjonp
 Something I've been looking for.  :-) :-) :-) :-)


Danke ronjonp

Sowas habe ich schon lange gesucht. 
Title: Re: replace block with another block that has attributes
Post by: ronjonp on June 06, 2012, 09:22:32 AM
Thank ronjonp
 Something I've been looking for.  :-) :-) :-) :-)


Danke ronjonp

Sowas habe ich schon lange gesucht.

 :-D
Title: Re: replace block with another block that has attributes
Post by: Hugo on March 08, 2017, 07:32:13 AM
Hello ronjonp

Can you change the me the rotation is also taken over.
I can not do this

Thank you

(Vl-catch-all-apply 'vlax-put (list e' rotation (cadr x))) :-(


Hallo ronjonp

Kannst du mir das änder das die Drehung auch übernommen wird.
ich schaffe das nicht

Danke
Title: Re: replace block with another block that has attributes
Post by: ronjonp on March 08, 2017, 10:57:51 AM
Try this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:attsync2 (/ _attpositions _name atts e name ss)
  2.   (defun _attpositions (block / att result)
  3.     (foreach att (vlax-invoke block 'getattributes)
  4.       (setq result (cons (list att
  5.                                (vlax-get att 'insertionpoint)
  6.                                (vlax-get att 'textalignmentpoint)
  7.                                (vlax-get att 'rotation)
  8.                          )
  9.                          result
  10.                    )
  11.       )
  12.     )
  13.   )
  14.   (defun _name (b)
  15.     (cond ((vlax-property-available-p b 'effectivename) (vla-get-effectivename b))
  16.           ((vlax-property-available-p b 'name) (vla-get-name b))
  17.     )
  18.   )
  19.   (if (and (setq e (car (entsel "\nSelect block to sync: ")))
  20.            (setq name (_name (vlax-ename->vla-object e)))
  21.            (setq ss (ssget "_x" (list '(0 . "insert") '(66 . 1))))
  22.       )
  23.     (progn (foreach x (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))
  24.              (and (eq (_name x) name) (setq atts (cons (_attpositions x) atts)))
  25.            )
  26.            (command "_.attsync" "_s" e "_yes")
  27.            (foreach x (apply 'append atts)
  28.              (vl-catch-all-apply 'vlax-put (list (car x) 'insertionpoint (cadr x)))
  29.              (vl-catch-all-apply 'vlax-put (list (car x) 'textalignmentpoint (caddr x)))
  30.              (vl-catch-all-apply 'vlax-put (list (car x) 'rotation (last x)))
  31.            )
  32.     )
  33.   )
  34.   (princ)
  35. )
Title: Re: replace block with another block that has attributes
Post by: Hugo on March 08, 2017, 11:44:44 AM
Super Thank you this works Perfectly  :-) :-) :-)

The best Lisp in my collection
Title: Re: replace block with another block that has attributes
Post by: ronjonp on March 08, 2017, 12:09:04 PM
Super Thank you this works Perfectly  :) :) :)

The best Lisp in my collection
:)