Import a particular defined block from another drawing

Import a particular defined block from another drawing

ahmad_a1054
Explorer Explorer
767 Views
7 Replies
Message 1 of 8

Import a particular defined block from another drawing

ahmad_a1054
Explorer
Explorer

Hi. I have a drawing with three defined blocks named B1, B2 & B3.

how can I import only B1 in a new drawing using:

1. Commands

2. VB.NET or VBA

 

Thanks

 

 

0 Likes
Accepted solutions (1)
768 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor
0 Likes
Message 3 of 8

norman.yuan
Mentor
Mentor

You might want to describe in more details about what you really want to do/what you really need/why. Since this is AutoCAD VBA/COM API programming discussion forum, do you intend to write VBA code to bring a block definition from a drawing into another? Or you want an existing command that you as user can do it (which the other reply from @paullimapa provides an answer). You also mentioned VB.NET, which cannot be used directly in AutoCAD VBA, so, are you implying that you want AutoCAD .NET API programming solution, or are you using VB.NET to build an EXE app that automates AutoCAD, in which you need to import block definition from one drawing into another?

 

With all these things are not clear, the short answer to your question, if you indeed look for a programming solution from AutoCAD COM API/VBA, is to look into AcadDocument.CopyObjects()/AcadDatabase.CopyObjects() method. You can see the sample code in VBA document (in Object Browser window, find CopyObjects method, click "?" Object Browser toolbar's "?" button).

 

In case you are also interested in .NET API solution via VB.NET/C#, you would then look into Database.WBlockCloneObjects() method.

 

Search this forum/internet for CopyObjects or WBlockCloneObjects would bring you many links/sample code.

 

Again, you may want to provide more details about what you really want, if it really related to AutoCAD programming.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 8

ahmad_a1054
Explorer
Explorer

hugh appreciation for your reply.

actually I'm programing an .exe file with vb.net. I have a dwg file as my initial frame which is designed for my company drawings. first, the program opens this dwg as the initial drawing and then fills is with defined shapes and object. in the end, a particular block (for example B1) from another drawing should be imported to the current drawing. I can use "ModelSpace.InsertBlock", but it import the whole drawing which is not required.

I hope I explained it well.

 

 

0 Likes
Message 5 of 8

norman.yuan
Mentor
Mentor

Firstly, using an EXE app to automate AutoCAD is hardly a good solution in most cases. But since I do not know your business requirements, I am not going to say more than "I would avoid it as much as possible".

 

Now, you are limited to use AutoCAD COM API, so, you use AcadDocument.CopyObjects to copy needed block definition(s) from a drawing to another. Obviously, you need to open the source drawing in AutoCAD, in order to find the ObjectId of the block definition(s) as copy source. You can open the source drawing in AutoCAD editor (AcadDocuments.Open()), or you can open it in memory only as AxDbDocument via ObjectDBX API (You can search this forum/the Internet for "AxDbDocument"and/or "ObjectDBX"). 

 

Again, you want to take look at the VBA code sample of "CopyObjects" in VBA document.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 8

ahmad_a1054
Explorer
Explorer
Thanks.
1. I became curious about what you said. the story is that we want to use
Forms firstly, get inputs from user, secondly, do some mathematical
calculations and finally draw the desired blocks. what do you suggest other
than vb.net?
2. I tried the copyobject method. but the thing is the program is written
so that there's no need for any references (using AS OBJECT instead of sth
like AS ACADCIRCLE enables us to do so). but I got "invalid object array"
error. Is there any way to use the mentioned method without importing any
reference? so far, the program is independent from Autocad references.
thanks.
0 Likes
Message 7 of 8

norman.yuan
Mentor
Mentor
Accepted solution

To your point 1:

 

Using Forms/UI does not mean you have to do it from EXE. While you can do it with VBA, it is an out-of-date technology, especially in terms of its lack of support64-bit UI component. However, it still does not make an external EXE a good choice in most cases. Again, I do not know your specific business case of why you have to do it from external EXE, so, not much to say, except for "I would avoid it, if possible". As for collecting user/calculating and finally drawing something with code, all can be done (and should be done, in most cases) within AutoCAD (VBA, or .NET API add-in).

 

To your point 2:

 

Yes, there is known issue with some AutoCAD COM API methods with late binding, where input parameter is "object", such as AcadHatch.AddHatch(), as you asked in another post. I did not try with with CopyObjects(), though (because I have moved on to .NET API and left VBA in the dust for long). I do not see a workaround, if you insist to use late binding with COM API.

 

If you still want to use EXE, for certain reasons, and want to take advantage .NET framework's rich UI for user input, one solution would be to use the EXE to collect the user input and then save the input to a data file (it can be plain text file). Then when input is done, the exe start AutoCAD and run a VBA macro, which read the input data from saved data file and do the CAD work inside AutoCAD. This way, the EXE app would only be used as user data collecting, and the CAD work is done with VBA, which would execute a lot faster than the CAD work being driven from the external EXE.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 8

ahmad_a1054
Explorer
Explorer
thanks a lot.
seems like there's nothing to do with reference requiring for acadhatch and copyobject.
I will consider your insights in my work.
huge appreciation.
0 Likes