.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BLOCK INSERTION

8 REPLIES 8
Reply
Message 1 of 9
lbayas
518 Views, 8 Replies

BLOCK INSERTION

Hi everyone.
What I am trying to accomplish is very simple. I want to open up a drawing (filename), insert another autocad drawing (block) into it. Then save and close the drawing using the COM interface.

This is what I have so far: (C#.NET)

gbl_app.Documents.Open(filename, 0, 0); //open the specified file in AutoCAD instance
AcadDocument doc = gbl_app.ActiveDocument; //set to the active document
AcadBlocks blkcoll = doc.Blocks; //get the block collection of the active document -- used later
//blkcoll.Add(object InsertionPoint, string dwg_file_to_add); // ???????

From here I would like to know the next few steps. I initially thought that you could easily add a block to the block collection and see it in modelspace, but looking at what others have been doing -- that sounds too easy. Is there a way to insert a DWG file into the currently active document seamlessly via COM? Thanks!
8 REPLIES 8
Message 2 of 9
cadMeUp
in reply to: lbayas

Which version of AutoCAD are you using? There's an easy way using the managed classes! Do you want to get a block that is defined in another dwg or insert the model space of an entire dwg as a block?
Message 3 of 9
lbayas
in reply to: lbayas

Hi Larry-
Thanks for your reply. I want to insert the model space of an entire dwg as a block. Is this possible?
Message 4 of 9
cadMeUp
in reply to: lbayas

Yes it is for sure possible! See the attached file for a good working example of this. You can copy and paste all of the contents of the attached file into an empty code file or rename the file with an extension of '.cs' instead of '.txt' and add it to your project. This file has quite a bit more code than what you presented in your original post, but it will give you a good idea of how to work with the managed classes without using COM.

One thing to note with this routine is it does not check for any attributes that may be present in the model space of the dwg that will be inserted. These would have to be handled with additional code, if present.

This should work with AutoCAD 2007 or 2008.
I do not believe it will work with 2006, but I am not able to test it on 2006 to be sure myself.

Let me know if you have any problems.
Message 5 of 9
Anonymous
in reply to: lbayas

LarryB,

Thank you for posting such a documented working program. This is definitely
a program that people can learn from.

Jon
wrote in message news:5780490@discussion.autodesk.com...
Yes it is for sure possible! See the attached file for a good working
example of this. You can copy and paste all of the contents of the attached
file into an empty code file or rename the file with an extension of '.cs'
instead of '.txt' and add it to your project. This file has quite a bit more
code than what you presented in your original post, but it will give you a
good idea of how to work with the managed classes without using COM.

One thing to note with this routine is it does not
check for any attributes that may be present in the model space of the dwg
that will be inserted. These would have to be handled with additional code,
if present.

This should work with AutoCAD 2007 or 2008.
I do not believe it will work with 2006, but I am not able to test it on
2006 to be sure myself.

Let me know if you have any problems.
Message 6 of 9
lbayas
in reply to: lbayas

Thanks Larry B!!!

That helped so much. I appreciate it.
Message 7 of 9
cadMeUp
in reply to: lbayas

Thanks Jon! I appreciate the kind words!
I have had a problem with documenting my code in the past, I've been terrible about it, but I have learned that it is worthwhile to take the time to comment your code as much as you can. I have kicked myself a few times going back to old code that I did not comment, and got lost trying to figure out what was going on! It can be scary!!

Hopefully you can take the code and expand on it! It would be nice to see something like this go around for awhile, see it come around again, and see how it has developed!
Message 8 of 9
Mohamed Allabakash
in reply to: lbayas

hi how to set a active document in Vb.net and How to insert a set of blocks(one by one) in Vb.Net..
it will help me a lot
Thanks a lot in advance.....
Message 9 of 9
jason.brenton
in reply to: lbayas

unfortunately the active document cannot really be set as it is the current drawing in cad. If you need to open/use another file, you can do it tho.

you do it in paralell to your current drawing.

dim dbOutside as ACDB.Database = new ACDB.Database(false, false)

dbOutisde.ReadDwgFile("", System.IO.Filshare.ReadWrite, True, "")
'this line is real easy to follow, put the filepath param to where ever the file is. the last pararm is a password var, but such things are rarely used.

'now use that db just like standard db, liek many sample here use the working database of the current drawing.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost