Author Topic: REPLACING BLOCKS with ObjectDBX?  (Read 3568 times)

0 Members and 1 Guest are viewing this topic.

ArgV

  • Guest
REPLACING BLOCKS with ObjectDBX?
« on: March 10, 2010, 10:52:41 PM »

Of course, I can't find much or any real documentation on ODBX, so, if anyone knows..

I want to replace blocks in several drawings. The blocks will be in the form of .DWG files from a folder.

vla-insertblock doesn't work of course, so... how would I do that? (or is it possible?)

thanks in advance.




Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #1 on: March 10, 2010, 11:26:04 PM »
But see, vla-insertblock should work..... from the help for Insertblock:
Quote
The name of the AutoCAD drawing file or the name of the block to insert. If it is a file name, include the .dwg extension and any path information necessary for AutoCAD to find the file.
So, have you tried it?

Oops, I missed the REPLACE part.....sorry.
« Last Edit: March 11, 2010, 12:04:44 AM by Jeff_M »

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #2 on: March 11, 2010, 12:14:05 AM »
And after testing it....it does work to REPLACE as well....
With a drawing named Test and a block inserted to it named ramp, altered to know if it gets revised, this code updates it just fine.
Code: [Select]
  (setq fname (findfile "c:\\MyProjects2010\\ramp.dwg"))
  (setq *acad* (vlax-get-acad-object))
  (setq oDBX (vla-GetInterfaceObject
       *acad* "ObjectDBX.AxDbDocument.18"))
  (vla-open odbx "c:\\MyProjects2010\\test.dwg")
  (setq blk (vlax-invoke (vla-get-modelspace oDBX) 'insertblock '(0.0 0.0 0.0) fname 1.0 1.0 1.0 0))
  (vla-saveas odbx "c:\\MyProjects2010\\test.dwg")
  (vlax-release-object oDBX)

ArgV

  • Guest
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #3 on: March 11, 2010, 12:17:43 AM »
And after testing it....it does work to REPLACE as well....
With a drawing named Test and a block inserted to it named ramp, altered to know if it gets revised, this code updates it just fine.
Code: [Select]
  (setq fname (findfile "c:\\MyProjects2010\\ramp.dwg"))
  (setq *acad* (vlax-get-acad-object))
  (setq oDBX (vla-GetInterfaceObject
       *acad* "ObjectDBX.AxDbDocument.18"))
  (vla-open odbx "c:\\MyProjects2010\\test.dwg")
  (setq blk (vlax-invoke (vla-get-modelspace oDBX) 'insertblock '(0.0 0.0 0.0) fname 1.0 1.0 1.0 0))
  (vla-saveas odbx "c:\\MyProjects2010\\test.dwg")
  (vlax-release-object oDBX)

Oh, duh. I was trying to use vla-insertblock instead of the vlax-invoke method. I thought I'd read that ODBX can't insert a full drawing. Maybe thats incorrect.

thanks, Jeff. :)

ArgV

  • Guest
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #4 on: March 11, 2010, 12:36:31 AM »
No, I keep getting the "; error: Parameter not optional" when it tries to run the insert method.

??


** UPDATE **

Ok, so I tried it again, with pretty much your exact code, and it worked great. thank you!! :)

thats pretty handy.
« Last Edit: March 11, 2010, 01:05:25 AM by ArgV »

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #5 on: March 11, 2010, 01:12:31 AM »
Not sure....the code I posted worked for me, which uses the InsertBlock method. Once you get it to actually insert the block, since you are merely updating, make sure to delete the inserted block object in the blk variable.

Glad I could help!

stevesfr

  • Newt
  • Posts: 54
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #6 on: March 11, 2010, 04:36:39 AM »
Not sure....the code I posted worked for me, which uses the InsertBlock method. Once you get it to actually insert the block, since you are merely updating, make sure to delete the inserted block object in the blk variable.

Glad I could help!

it works great, thanks, but ....
What to add to code to delete the inserted revised block ? 
Steve
Can't remember what I'm supposed to forget.

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #7 on: March 11, 2010, 10:44:00 AM »
What to add to code to delete the inserted revised block ? 
Before the oDBX document is saved:
(vla-delete blk)

stevesfr

  • Newt
  • Posts: 54
Re: REPLACING BLOCKS with ObjectDBX?
« Reply #8 on: March 11, 2010, 11:14:58 AM »
What to add to code to delete the inserted revised block ? 
Before the oDBX document is saved:
(vla-delete blk)

many thanks for the experience !     :angel:
Can't remember what I'm supposed to forget.