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

Accessing a .dwg file from VB.NET

4 REPLIES 4
Reply
Message 1 of 5
dbillion
803 Views, 4 Replies

Accessing a .dwg file from VB.NET

I've been doing a lot of programming using VBA for AutoCAD. I want to convert all this to VB.NET.

Before I insert a block into a drawing, or draw a line on a drawing, I first have to tell VB.NET to access the active file.

I imagine I have to dimension the drawing, or something, right?

How do I tell VB.NET to access, insert, draw to an active AutoCAD .dwg file?
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: dbillion

With VB.NET (or C# for that matter), you can do two type of Acad
programming:

1. COM automation, which is almost the same as you do in VBA, except for
doing it slower (mainly coding, due to the similar but different syntex,
lacking of convenience provided by Acad VBA IDE...). In my opinion, it does
not make much sense in general to convert VBA to VB.NET code in this
respect. Converting to VB(5/6) ActiveXDLL make better sense. In this case,
you access acad drawing in very similar wya as you do in VBA.

2. ObjectARX .NET API (the main topics of this NG, at least most visitors to
this NG thought so). If you want to do .NET API, you have steep learning
curve both on .NET API and .NET programming itself. The VBA code would be
not convertable (unless you consider re-write entire thing as converting).
You access Acad drawing/object in very different way from VBA. The good
thing is you can still use COM model in .NET API as you do in VBA, if you
really needs it.

So, before you can ask something in detail with VB.NET or C# and expect
someone to answer, first make up you mind: which way to go or which way you
are in: COM or .NET API.


wrote in message news:5750898@discussion.autodesk.com...
I've been doing a lot of programming using VBA for AutoCAD. I want to
convert all this to VB.NET.

Before I insert a block into a drawing, or draw a line on a drawing, I first
have to tell VB.NET to access the active file.

I imagine I have to dimension the drawing, or something, right?

How do I tell VB.NET to access, insert, draw to an active AutoCAD .dwg file?
Message 3 of 5
dbillion
in reply to: dbillion

I have no idea what COM or API means.

I have experience writing stand-alone VB (version 6 and .NET) programs. I want to use VB.NET to write programs to automate some standard AutoCAD commands, such as drawing schematics, inserting blocks, etc.

Now, I know how to do this in VBA. I want to do this with VB.NET. I don't care if it's COM, API or whatever.

There is some string of code somewhere out there that tells VB to look at and act upon an active AutoCAD drawing. It'd be nice to know what that code is.

Once I can tell VB that we'll be working with an AutoCAD file, I can then apply the code to do what I want it to with that file.
Message 4 of 5
ethomson
in reply to: dbillion

You're not going to get alot of help with a response like that.

I suggest you do some research before you ask that again, because like the previous poster very kindly explained in pretty good detail it's not as simple as you are trying to make it.

See the following page for a break down of your programming options.
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627

I would recommend also looking at the two stickied topics on the Augi Dot Net API forums

http://forums.augi.com/forumdisplay.php?f=215

There is plenty of information that will answer your question between those two resources
Message 5 of 5
orrg
in reply to: dbillion

After placing the appropriate references in your project, place the following lines in the Public declarations of your Module:

Public AcadApp as AcadApplication
Public ThisDrawing as AcadDocument

For AutoCAD 2008 ,In the procedure where you would usually place your "ThisDrawing" reference precede it with:
acadapp = GetObject(, "AutoCAD.Application.17")
ThisDrawing = AcadApp.ActiveDocument

Checking for other versions, for a running instance of autocad, etc. would require altering this code, but this will get you to your question of:
...snip...
How do I tell VB.NET to access ... to an active AutoCAD .dwg file?
...snip...

Then ignore this forum as you will not get much help from the "programmers" at this site as they are focused on true ".net" aspects of programming. Stay, instead, with the VBA group as most functions will then be usable (what the above code does is to create a VB version of the built-in VBA reference to "ThisDrawing").
Note also that VB2005 Exp Ed. does not require the "Set " that would precede the "acadApp" and "ThisDrawing". In older VB versions those lines would appear as follows:
set acadapp = GetObject(, "AutoCAD.Application.17")
set ThisDrawing = AcadApp.ActiveDocument

Gary

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