Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DBX help please

17 REPLIES 17
Reply
Message 1 of 18
Anonymous
472 Views, 17 Replies

DBX help please

I would like to copy a block from another drawing into my current drawing.
I'm able to open/close a file. The following returns the block I need from
the other drawing:

(vla-item (vla-get-blocks DBX_DOCUMENT) "TEST-BLOCK")
#

2 questions:
- How do I copy this block into my current drawing?
- Will it redefine the existing block? (I want it to.)

Thanks,
Allen
17 REPLIES 17
Message 2 of 18
Anonymous
in reply to: Anonymous

This should help you.

http://discussion.autodesk.com/thread.jspa?messageID=4163431

--

Tim
"A blind man lets nothing block his vision."



"Allen Bennett" wrote in message
news:5124188@discussion.autodesk.com...
I would like to copy a block from another drawing into my current drawing.
I'm able to open/close a file. The following returns the block I need from
the other drawing:

(vla-item (vla-get-blocks DBX_DOCUMENT) "TEST-BLOCK")
#

2 questions:
- How do I copy this block into my current drawing?
- Will it redefine the existing block? (I want it to.)

Thanks,
Allen
Message 3 of 18
Anonymous
in reply to: Anonymous

'CopyObjects.......
If the block does not exist in the current drawing, Add it first.
If it does exist, delete all objects from it.
Use the CopyObjects from the DBX_DOCUMENT and specify the block object in
the current drawing as the new owner.

Yes, it will redefine the block.

"Allen Bennett" wrote in message
news:5124188@discussion.autodesk.com...
I would like to copy a block from another drawing into my current drawing.
I'm able to open/close a file. The following returns the block I need from
the other drawing:

(vla-item (vla-get-blocks DBX_DOCUMENT) "TEST-BLOCK")
#

2 questions:
- How do I copy this block into my current drawing?
- Will it redefine the existing block? (I want it to.)

Thanks,
Allen
Message 4 of 18
Anonymous
in reply to: Anonymous

Thanks Tim, some good stuff there.

Allen

"T.Willey" wrote in message
news:5124217@discussion.autodesk.com...
This should help you.

http://discussion.autodesk.com/thread.jspa?messageID=4163431

--

Tim
"A blind man lets nothing block his vision."
Message 5 of 18
Anonymous
in reply to: Anonymous

Hi Jeff,

Ok, I can successfully copy the block into my drawing, but if it already
exists, it doesn't seem to redefine it. When you say "If it does exist,
delete all objects from it", are you saying delete all occurrences of that
block in my current drawing? If so, I need to keep them and have them
redefined by the block I'm bringing in from the DBX_DOC.

Any more direction would be greatly appreciated.
Thanks,
Allen

"Jeff Mishler" wrote in message
news:5124255@discussion.autodesk.com...
'CopyObjects.......
If the block does not exist in the current drawing, Add it first.
If it does exist, delete all objects from it.
Use the CopyObjects from the DBX_DOCUMENT and specify the block object in
the current drawing as the new owner.

Yes, it will redefine the block.
Message 6 of 18
Anonymous
in reply to: Anonymous

Here's what I have:

(vl-catch-all-apply 'vla-CopyObjects
(list DBX_DOCUMENT
(vlax-safearray-fill
(vlax-make-safearray vlax-vbObject '(0 . 0))
(list (vla-item DBX_BLOCKS "TEST-BLOCK")))
CURRENT_BLOCKS
)))
Message 7 of 18
Anonymous
in reply to: Anonymous

First off, I'd suggest forgetting the (vl-catch-all-apply) until you have it
working, THEN go back and add it. It will make your debugging life much
easier.

(if (tblsearch "BLOCK" "TEST-BLOCK")
(progn
(setq blk (vla-item CURRENT_BLOCKS "TEST-BLOCK"))
(vlax-for ent blk
(vla-delete ent)
)
);progn
;else
(setq blk (vla-add CURRENT_BLOCKS "TEST-BLOCK))
);if

(vlax-for ent (vla-item DBX_BLOCKS "TEST-BLOCK")
(setq ents (cons ent ents))
)
(vlax-invoke DBX_DOCUMENT 'copyobjects ents blk)

Not tested but should work.

"Allen Bennett" wrote in message
news:5124311@discussion.autodesk.com...
Here's what I have:

(vl-catch-all-apply 'vla-CopyObjects
(list DBX_DOCUMENT
(vlax-safearray-fill
(vlax-make-safearray vlax-vbObject '(0 . 0))
(list (vla-item DBX_BLOCKS "TEST-BLOCK")))
CURRENT_BLOCKS
)))
Message 8 of 18
Anonymous
in reply to: Anonymous

What Jeff is talking about is. Once you know that the block exist in the
current draiwng, then erase all the objects that define the block in the
block collection, and then copy all the new items into it. If you have
attributes, then you will need to find all the old version, and use
attsynce, or reinsert them as I did in my code in the thread I posted
before.

--

Tim
"A blind man lets nothing block his vision."



"Allen Bennett" wrote in message
news:5124283@discussion.autodesk.com...
Hi Jeff,

Ok, I can successfully copy the block into my drawing, but if it already
exists, it doesn't seem to redefine it. When you say "If it does exist,
delete all objects from it", are you saying delete all occurrences of that
block in my current drawing? If so, I need to keep them and have them
redefined by the block I'm bringing in from the DBX_DOC.

Any more direction would be greatly appreciated.
Thanks,
Allen

"Jeff Mishler" wrote in message
news:5124255@discussion.autodesk.com...
'CopyObjects.......
If the block does not exist in the current drawing, Add it first.
If it does exist, delete all objects from it.
Use the CopyObjects from the DBX_DOCUMENT and specify the block object in
the current drawing as the new owner.

Yes, it will redefine the block.
Message 9 of 18
Anonymous
in reply to: Anonymous

Hi Jeff,

The (if... returns "too few actual parameters". I don't know were to go
from here.

Thanks for your time,
Allen

"Jeff Mishler" wrote in message
news:5124329@discussion.autodesk.com...
First off, I'd suggest forgetting the (vl-catch-all-apply) until you have it
working, THEN go back and add it. It will make your debugging life much
easier.

(if (tblsearch "BLOCK" "TEST-BLOCK")
(progn
(setq blk (vla-item CURRENT_BLOCKS "TEST-BLOCK"))
(vlax-for ent blk
(vla-delete ent)
)
);progn
;else
(setq blk (vla-add CURRENT_BLOCKS "TEST-BLOCK))
);if

(vlax-for ent (vla-item DBX_BLOCKS "TEST-BLOCK")
(setq ents (cons ent ents))
)
(vlax-invoke DBX_DOCUMENT 'copyobjects ents blk)

Not tested but should work.
Message 10 of 18
Anonymous
in reply to: Anonymous

I missed the closing " in this line:
(setq blk (vla-add CURRENT_BLOCKS "TEST-BLOCK))



"Allen Bennett" wrote in message
news:5124454@discussion.autodesk.com...
Hi Jeff,

The (if... returns "too few actual parameters". I don't know were to go
from here.

Thanks for your time,
Allen
Message 11 of 18
Anonymous
in reply to: Anonymous

Sorry, I closed the string before I tried it - still getting the error.
:o)


"Jeff Mishler" wrote in message
news:5124455@discussion.autodesk.com...
I missed the closing " in this line:
(setq blk (vla-add CURRENT_BLOCKS "TEST-BLOCK))



"Allen Bennett" wrote in message
news:5124454@discussion.autodesk.com...
Hi Jeff,

The (if... returns "too few actual parameters". I don't know were to go
from here.

Thanks for your time,
Allen
Message 12 of 18
Anonymous
in reply to: Anonymous

Hi Allen,
I dunno why it gives that error. What version Acad? It may be due to your
version insisting on the IDPAIRS to be set.....here's a slightly revised
version that I tested in a drawing. Yes, I said A drawing......like I said
before, I like to make sure something works in a simple form, then go from
there.

In a new drawing I drew a line and a circle. I then created 2 blocks,
TEST-BLOCK & TEST-BLOCK2, each one using one of the 2 objects, and had them
"convert to block"s. So now my drawing is just 2 inserts showing a line and
a circle. Then I run the following lines of code and I end up with 2
inserts, both showing identical objects.

(setq *doc* (vla-get-activedocument
(vlax-get-acad-object))
current_blocks (vla-get-blocks *doc*)
dbx_document *doc*)

(if (tblsearch "BLOCK" "TEST-BLOCK")
(progn
(setq blk (vla-item CURRENT_BLOCKS "TEST-BLOCK"))
(vlax-for ent blk
(vla-delete ent)
)
);progn
;else
(setq blk (vla-add CURRENT_BLOCKS "TEST-BLOCK"))
);if

(vlax-for ent (vla-item (vla-get-blocks DBX_document) "TEST-BLOCK2")
(setq ents (cons ent ents))
)
(vlax-invoke DBX_DOCUMENT 'copyobjects ents blk 'idpairs)
(vla-regen *doc* acAllViewports)



"Allen Bennett" wrote in message
news:5124514@discussion.autodesk.com...
Sorry, I closed the string before I tried it - still getting the error.
:o)
Message 13 of 18
Anonymous
in reply to: Anonymous

Using 2006, stand-alone, USA. I've got it working. The correct block is now
visible, but it looks like it's dynamic block properties are unavailable,
and are actually missing when I open the block in Bedit. :o\ Is this a
known problem?

Well, thank you for your time & patience Jeff.
Allen
Message 14 of 18
Anonymous
in reply to: Anonymous

Hi Tim,

Thanks for your time.
Allen

"T.Willey" wrote in message
news:5124338@discussion.autodesk.com...
What Jeff is talking about is. Once you know that the block exist in the
current draiwng, then erase all the objects that define the block in the
block collection, and then copy all the new items into it. If you have
attributes, then you will need to find all the old version, and use
attsynce, or reinsert them as I did in my code in the thread I posted
before.

--

Tim
"A blind man lets nothing block his vision."



"Allen Bennett" wrote in message
news:5124283@discussion.autodesk.com...
Hi Jeff,

Ok, I can successfully copy the block into my drawing, but if it already
exists, it doesn't seem to redefine it. When you say "If it does exist,
delete all objects from it", are you saying delete all occurrences of that
block in my current drawing? If so, I need to keep them and have them
redefined by the block I'm bringing in from the DBX_DOC.

Any more direction would be greatly appreciated.
Thanks,
Allen

"Jeff Mishler" wrote in message
news:5124255@discussion.autodesk.com...
'CopyObjects.......
If the block does not exist in the current drawing, Add it first.
If it does exist, delete all objects from it.
Use the CopyObjects from the DBX_DOCUMENT and specify the block object in
the current drawing as the new owner.

Yes, it will redefine the block.
Message 15 of 18
Anonymous
in reply to: Anonymous

You're welcome. Hope you can learn something new. I don't use a2006 yet,
so I don't know anyting about dynamic blocks.

--

Tim
"A blind man lets nothing block his vision."



"Allen Bennett" wrote in message
news:5124600@discussion.autodesk.com...
Hi Tim,

Thanks for your time.
Allen

"T.Willey" wrote in message
news:5124338@discussion.autodesk.com...
What Jeff is talking about is. Once you know that the block exist in the
current draiwng, then erase all the objects that define the block in the
block collection, and then copy all the new items into it. If you have
attributes, then you will need to find all the old version, and use
attsynce, or reinsert them as I did in my code in the thread I posted
before.

--

Tim
"A blind man lets nothing block his vision."



"Allen Bennett" wrote in message
news:5124283@discussion.autodesk.com...
Hi Jeff,

Ok, I can successfully copy the block into my drawing, but if it already
exists, it doesn't seem to redefine it. When you say "If it does exist,
delete all objects from it", are you saying delete all occurrences of that
block in my current drawing? If so, I need to keep them and have them
redefined by the block I'm bringing in from the DBX_DOC.

Any more direction would be greatly appreciated.
Thanks,
Allen

"Jeff Mishler" wrote in message
news:5124255@discussion.autodesk.com...
'CopyObjects.......
If the block does not exist in the current drawing, Add it first.
If it does exist, delete all objects from it.
Use the CopyObjects from the DBX_DOCUMENT and specify the block object in
the current drawing as the new owner.

Yes, it will redefine the block.
Message 16 of 18
Anonymous
in reply to: Anonymous

I have not tried this with dynamic blocks. I'll have some time tonight to
play with them a bit. I'll see what I can come up with.

You're welcome!

Jeff

"Allen Bennett" wrote in message
news:5124599@discussion.autodesk.com...
Using 2006, stand-alone, USA. I've got it working. The correct block is now
visible, but it looks like it's dynamic block properties are unavailable,
and are actually missing when I open the block in Bedit. :o\ Is this a
known problem?

Well, thank you for your time & patience Jeff.
Allen
Message 17 of 18
Anonymous
in reply to: Anonymous

Well I couldn't stop thinking about this so I went back and ran a number of
tests......

Copying a Dyn.Block's definition from a ODBX doc to another drawing works,
providing the name of the Dyn. Block does not already exist in the
destination drawing.

Copying to a drawing that already has a block of that name could cause
undesired problems since said block may have been inserted and dynamicly
altered any number of times....and once altered the insert becomes an
anonymous block with the only link back to the original by the EffectiveName
property which is ReadOnly. To update these blocks they will all be reset to
the default block properties.

This works, but is subject to the above resetting issue.
[code]
(defun c:dblk (/ *DOC* BLK1 BLK3 BLKORIG CURRENT_BLOCKS DBX_DOCUMENT)
(setq *doc* (vla-get-activedocument
(vlax-get-acad-object)
)
current_blocks (vla-get-blocks *doc*)
dbx_document (vla-getinterfaceobject
(vlax-get-acad-object)
"ObjectDBX.AxDbDocument.16"
)
)
(vla-open dbx_document "c:\\testblock.dwg")
(setq blk1 (vla-item (vla-get-blocks DBX_document) "TEST-BLOCK"))
(if (not (tblsearch "BLOCK" "TEST-BLOCK"))
(progn
(vlax-invoke
dbx_document
'copyobjects
(list blk1)
current_blocks
'pairs
)
) ;progn
;else
(progn
(setq blkorig (vla-item current_blocks "test-block"))
(setq blk3 (vla-add current_blocks
(vlax-3d-point '(0 0 0))
"temp99999"
)
)
(vlax-for blk current_blocks
(vlax-for ent blk
(if (and (eq (vla-get-objectname ent) "AcDbBlockReference")
(or (eq (vla-get-name ent) "test-block")
(eq (vla-get-effectivename ent) "test-block")
)
)
(vla-put-name ent "temp99999")
)
)
)
(vla-delete blkorig)
(vla-save *doc*)
(vlax-invoke
dbx_document
'copyobjects
(list blk1)
current_blocks
'pairs
)
(vlax-for blk current_blocks
(vlax-for ent blk
(if (and (eq (vla-get-objectname ent) "AcDbBlockReference")
(or (eq (vla-get-name ent) "temp99999")
(eq (vla-get-effectivename ent) "temp99999")
)
)
(vla-put-name ent "test-block")
)
)
)
(vla-delete blk3)
)
) ;if
(vla-regen *doc* acAllViewports)
(vlax-release-object dbx_document)
(princ)
)
[/code]

"Jeff Mishler" wrote in message
news:5124678@discussion.autodesk.com...
I have not tried this with dynamic blocks. I'll have some time tonight to
play with them a bit. I'll see what I can come up with.

You're welcome!

Jeff

"Allen Bennett" wrote in message
news:5124599@discussion.autodesk.com...
Using 2006, stand-alone, USA. I've got it working. The correct block is now
visible, but it looks like it's dynamic block properties are unavailable,
and are actually missing when I open the block in Bedit. :o\ Is this a
known problem?

Well, thank you for your time & patience Jeff.
Allen
Message 18 of 18
Anonymous
in reply to: Anonymous

Hi Jeff,

Thank you so much. I was hoping to not need so much help with this one - my
first try with DBX so I'm wanting to learn what's going on here. It works
like a champ.

Scenario - I'm bring updated (dynamic blocks) into a drawing which has the
older version of the block which is NOT dynamic - both have the same
attributes. Dynamic properties & attributes seem to be fine. Very odd that
the dynamic properties were being lost before.

Again, thank you very much.
Allen

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost