Windows Forms App

Windows Forms App

Jerry.Hanco
Participant Participant
1,080 Views
8 Replies
Message 1 of 9

Windows Forms App

Jerry.Hanco
Participant
Participant

Hello,

 

about 25 years ago I wrote a stand alone exe using VB6. The user inputs some data and a contur consisting of lines and arcs was drawn into an open drawing. My problem is that I have no idea how I did it and I can't find any information on how to do it using visual studio. I find a lot on making Add-Ins but not how to make a Windows Form App that connects to Autocad.

For starters, I like to make a windows form with inputs for the dimensions of a rectangle and an OK button. When OK is pressed the app should draw the rectangle in Autocad. Could someone point me in the right direction to what I'm looking for? Any tutorials or books? My preferred language is VB.

 

Thanks,

Jerry

0 Likes
Accepted solutions (3)
1,081 Views
8 Replies
Replies (8)
Message 2 of 9

_gile
Consultant
Consultant

@Jerry.Hanco  a écrit :

My preferred language is VB.


First, you should switch to C# because you'll have much more valuable help in C# than in VB and because Windows stopped updating VB.

 


@Jerry.Hanco  a écrit :

The user inputs some data and a contur consisting of lines and arcs was drawn into an open drawing.


Second, in my opinion, using a stand alone application to interact with a runing AutoCAD session is not a good idea because stand alone applications can only use the AutoCAD COM API.

To be able to use the .NET API, you have to build an add-in and this add-in can be called from the runing AutoCAD session and display some windows form (as modal or modeless dialog).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 9

ActivistInvestor
Mentor
Mentor
Accepted solution

Since you're having trouble remembering how you built the VB6 automation client, it would be a safe assumption that building an in-process AutoCAD extension that uses the .NET API is going to require you to climb a steep learning curve. So, if you want to get something done quickly, without first spending a year learning the AutoCAD .NET API and the C# language, I would probably just take the route you're trying to take for the time being. If your needs are relatively-simple like what you described above, then the ActiveX API should suffice. If you plan to continue developing AutoCAD-based apps, then I would recommend learning C# and the AutoCAD .NET API as a long-term goal.

 

To get up and running ASAP using your preferred approach, You can follow these ChatGPT instructions.

 

When you get to the Add a new project dialog, enter ".NET Framework" in the search box at the top (see below), and it will narrow down the available project templates to the one you should use. To avoid complications resulting from the removal of GetActiveObject() in recent framework versions (which would pose a hurdle that you must overcome), you can target the legacy .NET Framework 4.x, by selecting the project template shown below.

 

ActivistInvestor_2-1747423266607.png

 

On the next window, accept the defaults shown below.

ActivistInvestor_3-1747423671163.png

 

If you want to target more recent framework versions, you will have to deal with the removal of GetActiveObject() from the API. For that, you can find some helpful information by browsing through this search result.

0 Likes
Message 4 of 9

Jerry.Hanco
Participant
Participant

@ActivistInvestor Thanks. I'll try that and dig into ActiveX API.

 

We design tools and I have several apps running for our calculations. These are written in VB .Net. What I need now is to write the the results into an open DWG. So because I'm extending the functionality I need to stay in VB.

0 Likes
Message 5 of 9

Jerry.Hanco
Participant
Participant

I was able to get an app up and running. It connects to Autoad and I managed to draw lines, circles and insert some text. What I can't find is how to for eg zoom extents or set layers. Is there any referenz or help on this?

0 Likes
Message 6 of 9

_gile
Consultant
Consultant
Accepted solution

ActiveX Reference Guide.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 9

Jerry.Hanco
Participant
Participant

I thought for COM there was a different referece. I found my mistake. I have

Dim acAppComObj As AcadApplication
Dim acDocComObj As AcadDocument

I was trying to zoomall with

acDocComObj.ZoomExtents()

instead of

acAppComObj.ZoomExtents()



 

0 Likes
Message 8 of 9

GTVic
Advisor
Advisor
Accepted solution

If you download the latest ObjectARX there is a VB.Net project supplied that can get you started with VB.Net which may be easier for you than C# and long term better than VB although you will have to learn how to use .NET with AutoCAD.

Here is a video to get you going on VB.Net:

https://www.autodesk.com/autodesk-university/class/Hands-Introduction-VBNET-Add-Ins-AutoCAD-2018#vid...

ObjectARX download for 2024:

https://www.autodesk.com/developer-network/platform-technologies/autocad/objectarx-download

Note that the 2025 and 2026 versions are harder to get as you have to go through a licensing rigmarole so the above link is easier but only gives you 2024 and earlier.

Anyway, once you download and extract you should find a VB.Net project called: \samples\dotNet\Ents which you can compile to a DLL file, then load into AutoCAD using the NETLOAD command and then type MKENTS to run the command.

If you want to use a form then the HelloWorld example uses a form, also TabExtension and EventsWatcher.

Message 9 of 9

Jerry.Hanco
Participant
Participant

Great! Thanx

0 Likes