Author Topic: dynamic blocks to static blocks via ObjectDBX  (Read 371 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Bull Frog
  • Posts: 431
dynamic blocks to static blocks via ObjectDBX
« 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 ...

ronjonp

  • Needs a day job
  • Posts: 7474
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #1 on: January 23, 2023, 05:42:07 PM »
Why not try a quick test to see if it works?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1137
  • 40 + years of using Autocad
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #2 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.
A man who never made a mistake never made anything

domenicomaria

  • Bull Frog
  • Posts: 431
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #3 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 ?

mhupp

  • Bull Frog
  • Posts: 231
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #4 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

ronjonp

  • Needs a day job
  • Posts: 7474
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #5 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. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

domenicomaria

  • Bull Frog
  • Posts: 431
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #6 on: January 24, 2023, 12:00:37 PM »
thanks everyone for the suggestions and also for the code

domenicomaria

  • Bull Frog
  • Posts: 431
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #7 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
« Last Edit: January 25, 2023, 03:23:06 AM by domenicomaria »

ronjonp

  • Needs a day job
  • Posts: 7474
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #8 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.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12752
  • London, England
Re: dynamic blocks to static blocks via ObjectDBX
« Reply #9 on: January 25, 2023, 04:34:16 PM »
Glad you could make use of it - thanks for the nod Ron  :-)