TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: domenicomaria on January 23, 2023, 04:14:56 AM

Title: dynamic blocks to static blocks via ObjectDBX
Post by: domenicomaria on January 23, 2023, 04:14:56 AM
I have a folder, which contains many subfolders which in turn contain other subfolders...

All these folders contain DWGs files

These DWGs files contain dynamic blocks.

I want to convert these dynamic blocks to static blocks
but WITHOUT OPENING all these DWGs, and doing all this with one Lisp command.

I don't need the code, I JUST WANT TO KNOW IF IT'S POSSIBLE
use ObjectDBX API and vla-ConvertToStaticBlock function

However, I've already seen some examples using Lee Mac's LM:ODBX ...
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: ronjonp on January 23, 2023, 05:42:07 PM
Why not try a quick test to see if it works?
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: BIGAL on January 23, 2023, 09:13:38 PM
Like ronjonp start at beginning how do you take 1 dynamic block in a dwg and save as a new dwg ? Given a question does dynamic block have a true effective name as when inserting dynamic blocks you end up with a block name like *U23.

Big hint A loop can get each block in a single dwg insert at 0,0 at scale 1, then wblock with a name for each block, say dwg name plus block name.

It would be better management for the output to group common blocks so I have like 20 car blocks Car1, car1E, Car1p and so on for elev, plan etc. Some 3d.

So before exporting 300 blocks and having a mess of block names have a think about how to organise.
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: domenicomaria on January 24, 2023, 02:33:07 AM
what I would like to get is this:
* open (via odbx) the dwg file
* create a selection set containing all the blocks inserted in the drawing
* for each of these blocks, check if the block is dynamic
* and in this case convert it to a static block
* then save the drawing
...
that's all
...
the first problem is:
how do i access all the blocks inserted in the dwg,
since it is not possible to use SSGET ?

Is there a workaround ?
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: mhupp on January 24, 2023, 07:55:03 AM
the first problem is:
how do i access all the blocks inserted in the dwg,
since it is not possible to use SSGET ?

Is there a workaround ?

Start of example 4.
http://www.lee-mac.com/odbxbase.html
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: ronjonp on January 24, 2023, 11:04:47 AM
the first problem is:
how do i access all the blocks inserted in the dwg,
since it is not possible to use SSGET ?

Is there a workaround ?

Start of example 4.
http://www.lee-mac.com/odbxbase.html
Exactly. Here's an example converting to anonymous so we don't have to check for duplicate names.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test4 (/ _staticblock)
  2.   (defun _staticblock (doc /)
  3.     (vlax-for layout (vla-get-layouts doc)
  4.       (vlax-for object (vla-get-block layout)
  5.         (if (and (= "AcDbBlockReference" (vla-get-objectname object))
  6.                  (= :vlax-true (vla-get-isdynamicblock object))
  7.             )
  8.           (vla-converttoanonymousblock object)
  9.         )
  10.       )
  11.     )
  12.   )
  13.   (lm:odbx '_staticblock nil t)
  14.   (princ)
  15. )
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: domenicomaria on January 24, 2023, 12:00:37 PM
thanks everyone for the suggestions and also for the code
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: domenicomaria on January 25, 2023, 03:16:16 AM
@ronjonp

Great !

It works !

The ODBX API is really a great thing !

LM:ODBX is awesome, like everything Lee Mac does !

And the EXAMPLE 4 of Lee Mac and your code
are a great workaround to the impossibility of use SSGET !

Thank you everyone again !

Ciao
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: ronjonp on January 25, 2023, 01:25:25 PM
@ronjonp

Great !

It works !

The ODBX API is really a great thing !

LM:ODBX is awesome, like everything Lee Mac does !

And the EXAMPLE 4 of Lee Mac and your code
are a great workaround to the impossibility of use SSGET !

Thank you everyone again !

Ciao
Glad to help .. although Lee did 99% of the heavy lifting.  :-)
Title: Re: dynamic blocks to static blocks via ObjectDBX
Post by: Lee Mac on January 25, 2023, 04:34:16 PM
Glad you could make use of it - thanks for the nod Ron  :-)