Basics of the API

Basics of the API

ThomasRambach
Advisor Advisor
2,510 Views
7 Replies
Message 1 of 8

Basics of the API

ThomasRambach
Advisor
Advisor

I'm trying to wrap my head around the AutoCAD API and I have some very basic questions. Please correct me if I'm way off on some of these assumptions.

 

I see a lot of examples with two different methods to launch AutoCAD:

The first uses Autodesk.AutoCAD.Interop.AcadApplication (referencing  Autodesk.AutoCAD.Interop.dll) and the other examples show Autodesk.AutoCAD.ApplicationServices.Core (referencing accoremgd.dll)

 

I have some code that works using Interop but I can't quite figure out how to start a transaction which seems like the only way to interact with block definitions. 

 

I guess my basic questions is what should I be using to start? What's the preferred method? If Interop is all I need, how do you initiate a transaction? I apologize if these sound like dumb questions. I've been using the Inventor API for years and it just seems so much more straightforward and better documented. I may have follow-up questions if anyone responds to this post. Thanks in advance!

 

 

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

norman.yuan
Mentor
Mentor

Firstly, you need to know there are 2 AutoCAD APIs that can be used with MS .NET framework environment: COM API and .NET API, and make things further confusing is COM API code can be easily mixed together with .NET API code (not the other way around).

 

This form is main for .NET API discussion, but because of what I just mentioned, COP API topics come up from time to time.

 

An important thing with Acad .NET API is that .NET API code runs INSIDE AutoCAD process: it DOES NOT LAUNCH AutoCAD, it loads into AutoCAD and runs ONLY in a running AutoCAD session (that is, AFTER AutoCAD is launched in some way). So, there is no straightforward preference between COM API interop/.NET API, it all depends the business situations/requirements.

 

So, you might as well explain in detail what is the possible process/workflow in your mind that you would want to develop from AutoCAD API (COM or .NET, or combination of both).

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 8

ThomasRambach
Advisor
Advisor

@norman.yuan  Thanks for the response. The first thing I'm trying to do is open a DWG file, search for all block references that match specific names, change a specifically named attribute from constant to normal, update the text value and refresh any instances where the block was inserted.

Secondly, I want to update all inserted blocks where an attribute name exists and move the text value to another attribute. 

This needs to be done in .NET('ish) where the code will reside within a Vault Job Processor custom job.

 

I already have the interop method to process the DWG (open ACAD, open the DWG, save and close) but all the other details of how to actually process the file is what is confusing right now.

 

 

0 Likes
Message 4 of 8

_gile
Consultant
Consultant
Accepted solution

Hi,

You can "process" the file with the COM API (as with VBA or Visual LISP). See the ActiveX documentation.

As @norman.yuan said, if you want to use the .NET API, you have to build a DLL with the .NET API and netload this DLL from a running AutoCAD session (possibly opened with COM). See this topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 8

ThomasRambach
Advisor
Advisor

@_gile It's as complicated as I feel like AutoCAD is compared to Inventor, but it's starting to make sense. Thank you. Going to work on this for awhile and I'll post how it's going.

0 Likes
Message 6 of 8

ThomasRambach
Advisor
Advisor

@_gile  I think this is working. My only issue now is I can't figure out how to be able to refresh inserted blocks after I update the block definition. 

0 Likes
Message 7 of 8

_gile
Consultant
Consultant

@ThomasRambach  a écrit :

@_gile  I think this is working. My only issue now is I can't figure out how to be able to refresh inserted blocks after I update the block definition. 


Did you try calling Editor.Regen() ?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 8 of 8

ThomasRambach
Advisor
Advisor

@_gile  Yes, but that had no affect. This post resolved it: https://forums.autodesk.com/t5/net/attsync-in-vb-net/td-p/4645057.

 

Thanks for all your help!

0 Likes