.NET

Reply
Active Contributor
lbayas
Posts: 26
Registered: ‎12-06-2006
Message 1 of 9 (176 Views)

BLOCK INSERTION

176 Views, 8 Replies
11-16-2007 12:15 PM
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!
Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 2 of 9 (176 Views)

Re: BLOCK INSERTION

11-16-2007 01:11 PM 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?
Active Contributor
lbayas
Posts: 26
Registered: ‎12-06-2006
Message 3 of 9 (176 Views)

Re: BLOCK INSERTION

11-17-2007 08:38 AM 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?
Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 4 of 9 (176 Views)

Re: BLOCK INSERTION

11-17-2007 06:12 PM 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.
*Jon Clien
Message 5 of 9 (176 Views)

Re: BLOCK INSERTION

11-19-2007 05:13 AM 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.
Active Contributor
lbayas
Posts: 26
Registered: ‎12-06-2006
Message 6 of 9 (176 Views)

Re: BLOCK INSERTION

11-19-2007 07:21 AM in reply to: lbayas
Thanks Larry B!!!

That helped so much. I appreciate it.
Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 7 of 9 (176 Views)

Re: BLOCK INSERTION

11-19-2007 07:28 AM 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!
Active Member
Mohamed Allabakash
Posts: 8
Registered: ‎01-23-2008
Message 8 of 9 (176 Views)

Re: BLOCK INSERTION

01-23-2008 04:32 AM 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.....
Active Contributor
jason.brenton
Posts: 38
Registered: ‎10-02-2007
Message 9 of 9 (176 Views)

Re: BLOCK INSERTION

02-07-2008 07:56 AM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community