replace block inside blocks and mantain properties

replace block inside blocks and mantain properties

kibitotato
Advocate Advocate
449 Views
7 Replies
Message 1 of 8

replace block inside blocks and mantain properties

kibitotato
Advocate
Advocate

From here,

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-modifiing-a-replace-block-scrip...

I take this from @Kent1Cooper 

 

(defun BlockReplace (old new)

  (vl-load-com)
  (foreach
    x
    (mapcar 'cadr (ssnamex (ssget "_X" (list (cons 2 old)))))
    (vla-put-name (vlax-ename->vla-object x) new)

  ); foreach
); defun

 

Usage for your example: (blockreplace "Supply Diffuser 24x24*" "V01")

It works, but...

I have this problem. The dwg was flattened in the past and I use the generic definition to replace the door block. But the replaced doors lost their properties of rotation, simmetry and scale. Is it possible to hace this definition but mantains the properties of the replaced block?

 

Also, this lsp doesn´t replace blocks inside blocks... Is it possible to fix it?

 

 

kibitotatogmail_com_0-1698135147010.jpeg

kibitotatogmail_com_1-1698135169792.jpeg

 

Thanks to all

 

 

0 Likes
450 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:

.... But the replaced doors lost their properties of rotation, simmetry and scale. ....


The image looks like they have not lost rotation or scale, but just their insertion point.  Where is the insertion point of those Blocks in the image?  Do you just need to redefine the Block with its insertion point in a logical location?  It is essential that the new and old Blocks share an insertion point location relative to their drawn content.

Kent Cooper, AIA
0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant

@kibitotato wrote:

.... this lsp doesn´t replace blocks inside blocks... Is it possible to fix it?


Not by merely "fixing" that routine, but if you want to replace all occurrences of BlockOld with BlockNew, including inside Blocks, and do not want to leave any BlockOld occurrences anywhere, you can do this:

 

Have BlockNew as a drawing file in a folder somewhere that AutoCAD knows to look in.  Not a drawing with that Block inserted in it, but as a top-level drawing file with that name.  If you made that drawing by WBLOCKing the Block out of another drawing, its insertion point should be good.  If not, use the BASE command in it to tell it where you want its insertion point to be when it's INSERTed in other drawings.

 

In your current drawing, start an _.-INSERT command [note the hyphen prefix, to use the command line, not the dialog box].  When it asks for the Block name, give it:

BlockOld=BlockNew

That will make it "reach out" to the BlockNew drawing file for the definition of BlockOld in the current drawing.  It will ask whether you want to redefine it -- say Yes.  You can then cancel the INSERT command if you don't want to add another.

 

If the names are different the new definition will still be under the old name, which you may want to RENAME.  If the Block name is the same, use just:
BlockOld=

which will cause it to look outside the current drawing for an external drawing file with the same name.

 

Then the definition of the Block will be changed to match that external drawing, which will cover those inside other Blocks, too.  Of course, the two definitions must have their parts in the same relationship to their insertion points, as to position and size and rotation.

Kent Cooper, AIA
0 Likes
Message 4 of 8

kibitotato
Advocate
Advocate

don´t know why happen this...

Attached 2 .dwg

0 Likes
Message 5 of 8

kibitotato
Advocate
Advocate
same problem with rotation like my last message.
doens´t work wildcards like "*" and this is very important
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

As I said, you need to define the Blocks in the same way as to their insertion point relative to the drawn contents, and the configuration of those drawn contents in relation to it.  Yours are not drawn the same way.  Here, each Block is inserted at scale factors of 1 and rotation of zero:

Kent1Cooper_0-1698236413673.png

If you replace one of the ... a-flat4 or 5 Blocks with the new one at left, it will keep the old one's scales and rotation, so of course it will aim differently under the new Block definition.

And why are the insertion points [the blue grips] in such a meaningless position?  They almost look like they might be at a door's width out from the latch side, but they're not.  They should be at the hinge points, or somewhere else with a real and logical relationship to the parts.  And why are the pieces drawn at the odd angle?  It should be something like this, at scales of 1 and rotation of zero:

Kent1Cooper_1-1698236848739.png

I chose to have the direction from the hinge toward the latch be 0°, but you could choose to use the direction of the door leaf instead.  But there should be some logic to it.

Kent Cooper, AIA
0 Likes
Message 7 of 8

kibitotato
Advocate
Advocate
I can see your point right now. This thing is a big mess. I´m new into my office and the .dwg are really messed up. I´m trying to find a method to fix things but it is... complicated... Thanks for your time.
0 Likes
Message 8 of 8

kibitotato
Advocate
Advocate
¿Is it possible to do this using wildcards like "*"?
0 Likes