Author Topic: replace block with another block that has attributes  (Read 6909 times)

0 Members and 1 Guest are viewing this topic.

Verticalmojo#2

  • Guest
replace block with another block that has attributes
« 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...

ronjonp

  • Needs a day job
  • Posts: 6112
Re: replace block with another block that has attributes
« Reply #1 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.

Windows 10 x64 - AutoCAD 2017

Custom Build PC

Rob...

  • King Gator
  • Posts: 3630
  • Take a little time to stop and smell the roses.
Re: replace block with another block that has attributes
« Reply #2 on: January 24, 2012, 07:42:30 pm »
Good answer.
Senior Mechanical Designer/Model Manager
Building Systems

danallen

  • Guest
Re: replace block with another block that has attributes
« Reply #3 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

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.

Verticalmojo#2

  • Guest
Re: replace block with another block that has attributes
« Reply #4 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



Isn't this the same as the express tool?

danallen

  • Guest
Re: replace block with another block that has attributes
« Reply #5 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

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 27875
Re: replace block with another block that has attributes
« Reply #6 on: January 25, 2012, 01:15:25 pm »
Long time no see there Mojo! Welcome back stranger. :)
TheSwamp.org  (serving the CAD community since 2003)

Verticalmojo#2

  • Guest
Re: replace block with another block that has attributes
« Reply #7 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!

ronjonp

  • Needs a day job
  • Posts: 6112
Re: replace block with another block that has attributes
« Reply #8 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)
)

Windows 10 x64 - AutoCAD 2017

Custom Build PC

danallen

  • Guest
Re: replace block with another block that has attributes
« Reply #9 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.

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 27875
Re: replace block with another block that has attributes
« Reply #10 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. :)
TheSwamp.org  (serving the CAD community since 2003)

VerticalMojo

  • Guest
Re: replace block with another block that has attributes
« Reply #11 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.
« Last Edit: January 27, 2012, 04:20:34 pm by VerticalMojo »

ronjonp

  • Needs a day job
  • Posts: 6112
Re: replace block with another block that has attributes
« Reply #12 on: January 27, 2012, 03:29:18 pm »
Glad it worked for you  :-D

Windows 10 x64 - AutoCAD 2017

Custom Build PC

Hugo

  • Bull Frog
  • Posts: 300
Re: replace block with another block that has attributes
« Reply #13 on: June 06, 2012, 01:21:08 am »
Thank ronjonp
 Something I've been looking for.  :-) :-) :-) :-)


Danke ronjonp

Sowas habe ich schon lange gesucht. 

ronjonp

  • Needs a day job
  • Posts: 6112
Re: replace block with another block that has attributes
« Reply #14 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

Windows 10 x64 - AutoCAD 2017

Custom Build PC

Hugo

  • Bull Frog
  • Posts: 300
Re: replace block with another block that has attributes
« Reply #15 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

ronjonp

  • Needs a day job
  • Posts: 6112
Re: replace block with another block that has attributes
« Reply #16 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.    )
  17.  )
  18.  (if (and (setq e (car (entsel "\nSelect block to sync: ")))
  19.   (setq name (_name (vlax-ename->vla-object e)))
  20.   (setq ss (ssget "_x" (list '(0 . "insert") '(66 . 1))))
  21.      )
  22.    (progn (foreach x (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))
  23.     (and (eq (_name x) name) (setq atts (cons (_attpositions x) atts)))
  24.   )
  25.   (command "_.attsync" "_s" e "_yes")
  26.   (foreach x (apply 'append atts)
  27.     (vl-catch-all-apply 'vlax-put (list (car x) 'insertionpoint (cadr x)))
  28.     (vl-catch-all-apply 'vlax-put (list (car x) 'textalignmentpoint (caddr x)))
  29.     (vl-catch-all-apply 'vlax-put (list (car x) 'rotation (last x)))
  30.   )
  31.    )
  32.  )
  33.  (princ)
  34. )
« Last Edit: March 08, 2017, 12:23:06 pm by ronjonp »

Windows 10 x64 - AutoCAD 2017

Custom Build PC

Hugo

  • Bull Frog
  • Posts: 300
Re: replace block with another block that has attributes
« Reply #17 on: March 08, 2017, 11:44:44 am »
Super Thank you this works Perfectly  :-) :-) :-)

The best Lisp in my collection
« Last Edit: March 08, 2017, 11:50:10 am by Hugo »

ronjonp

  • Needs a day job
  • Posts: 6112
Re: replace block with another block that has attributes
« Reply #18 on: March 08, 2017, 12:09:04 pm »
Super Thank you this works Perfectly  :) :) :)

The best Lisp in my collection
:)

Windows 10 x64 - AutoCAD 2017

Custom Build PC