Automatically merging drawings

Automatically merging drawings

basnederveen
Advocate Advocate
2,108 Views
7 Replies
Message 1 of 8

Automatically merging drawings

basnederveen
Advocate
Advocate

Hello everyone,

 

I've been doing a lot of Inventor customization, but not yet any ACAD, now someone has asked me if it possible to merge ACAD drawings.

 

I have a bunch of drawings all with one exported drawing from inventor. These drawings contain a sheet in model space. I would like to write some program (don't know if it should be LISP, .NET, VBA, but prefer .NET or VBA since I know this from inventor) that loops through a folder and merge's all drawings with a matching drawing number. 

 

The actions that the program should take:

 - Open x drawings with the same drawing nr 

 - Create a new drawing and paste the contents of the opened drawings in the empty one, with a known distance between each sheet 

 - Or add the the sheets to the first sheet drawing and rename

 

The thing that I really dont know if it's possible is the copying and pasting of a drawing. I do know the location of the objects since its an inventor export it will always be within the same sheet borders.   I've searched a bit but I can't really find what I am looking for. Does anyone know if this is at all possible?

 

Thanks in advance

 

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

maratovich
Advisor
Advisor

This is possible when using additional programs.
Try it:
https://www.kdmsoft.net/revers.html
I attached an example picture of the program settings

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 3 of 8

norman.yuan
Mentor
Mentor
Accepted solution

Since you have not yet done any AutoCAD programming, it would be a bit difficult to go into very details of actual code. But yes, it is possible to program AutoCAD via its APIs to "Copy/Paste" drawing content from one drawing to another, be it LISP, VBA or .NET API, or ObjectARX C++.

 

Considering your preference, both AutoCAD VBA and .NET API programming can do it, but you need to know that VBA uses AutoCAD COM API and AutoCAD .NET API uses, well, .NET API, thus the coding would be different. And most importantly, you need to how AutoCAD works before you jump into learning AutoCAD programming.

 

Without going to deep into programming, here is what your program/application need to do, assuming you want to start a blank drawing, and copy drawing content from all target drawings into it:

 

1. With a proper configured blank drawing open, the app get a drawing file list in the target folder. 

2. For each drawing file, "open" it (either in AutoCAD visibly, or in memory as side document/database, depending on which API you use).

3. Identify the drawing content in the opened drawing. In your case, it seems quite simple: everything in ModelSpace

4. "select" entities to be copied, and then call proper copying operation supported by corresponding API: for COM API, it is CopyObjects(), for .NET API, it is WBlockCloneObjects(). This would transfer the selected entities in one drawing into the other drawing (the blank one). 

5. After the entities being transferred the other drawing, you may want to transform them according to the needs (move, rotate...).

6. repeat 4 and 5.

 

On the other hand, if you know all drawing contents are in ModelSpace, you can simply programmatically insert these drawing as Block, and then, if necessary, explode it. The code of doing this would be much simpler.

 

While it can be done quite easily by either VBA or .NET API, if you expect thing would get more complicated once the basic works, such as adding UIs to allow user to select target folders/files, or even allow user to preview before merging, ... (it is very often once things get started, more requirements/demands comes), I'd go with .NET API and not waste time in VBA (because of its very limited support resources on 64-bit AutoCAD platform).

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 8

basnederveen
Advocate
Advocate

 

@maratovich Revers looks very promising. Hope will also be able to take a folder with 100+ subfolders, then it is exactly what I am looking for. Otherwise I am afraid I have to create a script for this! Trying it out right now!

 

@norman.yuan Thanks alot! I do not think I will need any UI, the drawings are placed in a large folder with subfolders for each drawing which contain all sheets of one drawing. These need to be merged per folder. Think I can get away with just inputting a folder and then looping through each subfolder. 

 

I'll let you guys know once I've spent some more time on this. Thanks again for the replies!

0 Likes
Message 5 of 8

basnederveen
Advocate
Advocate

Hi, 

 

I've been trying this out for a bit today, the copying is going well, until I use big files with alot of objects (was trying with one with 50000 objects, this took a while). Which is not really a problem, Ill just have the script run overnight, but I was wondering if there is a faster method?

 

 

0 Likes
Message 6 of 8

maratovich
Advisor
Advisor

50,000 objects are long to process - this is normal. (for your decision).
100 subfolders is not normal.
Your first post had other tasks.
Maybe you will show an example of what you want in the end result?
Have you tried the program I was talking about?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 7 of 8

basnederveen
Advocate
Advocate

Okay, but when I manually copy - paste its way faster, maybe there is a way to get this behaviour programmatically. Yes the program (Revers) works great, it actually does exactly what I want to do, but for one drawing (i.e. 5 sheets). If I have 100 drawings consisting of 5 sheets each, but I need a separate DWG file for each drawing, I will need to use the program 100 times right?

 

I have x amount of sheets in folders like in the screenshot. All sheets of the same drawing number should be merged. 

 



0 Likes
Message 8 of 8

maratovich
Advisor
Advisor

Yes, you understood correctly.
But the program can be improved. This can be solved.
Where should the new file be created? (which will be common)
Inside each folder?
What is the name of the file?
Can you send an example of 2-3 folders to my mail (for tests)?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes