.NET C# dwg editing library

.NET C# dwg editing library

adam_luER5XJ
Contributor Contributor
6,682 Views
12 Replies
Message 1 of 13

.NET C# dwg editing library

adam_luER5XJ
Contributor
Contributor

I'm looking for a C# (.NET Framework 4.8) library to directly edit .dwg files.

I want to do this within a C# application, regardless of whether AutoCAD needs to be open.

 

However, all the documentation I've found seems to focus on "writing AutoCAD commands using C# and then manually executing those commands within AutoCAD".

So, I'm wondering if it's possible to directly edit existing .dwg files and save them within a C# application?

Thank you for any response.

 

(Since I couldn't find an AutoCAD Support email, I'm not sure if this is the right place to ask. Please let me know if there's a more suitable channel, thank you.)

0 Likes
Accepted solutions (3)
6,683 Views
12 Replies
Replies (12)
Message 2 of 13

Ed__Jobe
Mentor
Mentor
Accepted solution

No, it's not possible to do it with just C#. A plugin has to run within the AutoCAD process. If you wish to do something without relying on AutoCAD to be installed, you need to use the RealDWG API. Or you could do it in the cloud using Platform Services.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 13

adam_luER5XJ
Contributor
Contributor

Thank you for your responses. Since I only started working with AutoCAD a few days ago, I’ve spent a lot of time searching online and even asked ChatGPT. However, there’s very little publicly available information or examples, so I’m still unsure if my understanding is correct.

 

I’ll list my understanding below; please let me know if there’s anything wrong:

For C# solutions, there are the following options:

 

ObjectARX:

Also known as ObjectARX and Managed .NET, this is used to develop AutoCAD command plugins that users can execute within AutoCAD.

 

ObjectARX SDK:

This refers to the SDK used for developing ObjectARX.

 

AutoCAD .NET API:

This is a term I got from GPT, which said it could run independently in a C# application. However, I couldn’t find any related information online. The only thing I found was some posts on the Autodesk forums: Search AutoCAD .NET API 
But from what I’ve seen, it also seems to involve writing AutoCAD command plugins. I think this is probably ObjectARX? It seems like GPT might have made a mistake.

 

RealDWG:

I just looked into RealDWG, which you mentioned, and it does seem like the solution I’m looking for. However, based on the pricing and some online introduction videos, it appears to be used for developing new software for end users to work with .dwg files. But due to the lack of documentation and shared resources online, I’m still unsure if my understanding is correct. Have you used it before?

 

Platform Services:

I also looked into Platform Services, but since my data cannot go on the cloud, this solution isn’t an option for me.

0 Likes
Message 4 of 13

Ed__Jobe
Mentor
Mentor

This page lists the various API's. ObjectARX comes in two flavors, unmanaged (C++) and managed (.NET). You will need to download the sdk for either. I have not use RealDWG because I only develop for in-house, everyone has acad installed. The main reason for using RealDwg is so that you can distribute your software and not rely on users subscribing to Autodesk. Often, developers want to create a streamlined interface that does only what the developer needs to do.

 

Also, if you want to learn the AutoCAD .NET API, @_gile has created a plugin called Inspector. It allows you to browse the dwg database and see it's structure.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 13

adam_luER5XJ
Contributor
Contributor

Actually, I’m also developing a program for internal use, with the goal of automating the editing of certain text in DWG files. We do have AutoCAD, but we hope to use the automation program to minimize the time needed to open AutoCAD for text editing. (Of course, this automation program will not have a user interface for user interaction.)

 

I looked at the Inspector plugin you provided, but it seems to be for viewing only and cannot edit.

Perhaps I should look into RealDWG or other third-party solutions. Thank you for your suggestions.

0 Likes
Message 6 of 13

_gile
Consultant
Consultant

Hi,

Assuming you can process the DWG files from a running AutoCAD session, you can use a 'side database' with the ReadDwgFile method to open the DWGs 'in memory' which is much more faster than opening them id the AutoCAD editor. See an example here.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 13

adam_luER5XJ
Contributor
Contributor

Hi,

Thank you for your responses.

Do you mean that I would write a command to be executed within the AutoCAD program, and then all the operations would be carried out in memory, making it faster?

However, I hope to execute it within a C# program. Can this function (the DetachAllXrefsCmd command from the example you provided) be executed directly in C#?

0 Likes
Message 8 of 13

_gile
Consultant
Consultant
Accepted solution

@adam_luER5XJ  a écrit :

Do you mean that I would write a command to be executed within the AutoCAD program, and then all the operations would be carried out in memory, making it faster?


Yes.

 


@adam_luER5XJ  a écrit :

However, I hope to execute it within a C# program. Can this function (the DetachAllXrefsCmd command from the example you provided) be executed directly in C#?


No, as said upper you can only use the AutoCAD .NET API from a running session of AutoCAD.

 

Another way could be creating a custom command (as the DetachAllXrefsCmd) which does not reference the AcMgd.dll (only AcCoreMgd.dll and AcDbMgd.dll) and use the AutoCAD Core Console to netload the DLL and run the command on each dwg.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

norman.yuan
Mentor
Mentor
Accepted solution

@adam_luER5XJ wrote:

Hi,

Thank you for your responses.

Do you mean that I would write a command to be executed within the AutoCAD program, and then all the operations would be carried out in memory, making it faster?

However, I hope to execute it within a C# program. Can this function (the DetachAllXrefsCmd command from the example you provided) be executed directly in C#?


It looks like you are not very familiar to technologies used to deal with AutoCAD/AutoCAD drawing. It might be better for you to provide more information about your business case of why you want to use "C# program" to edit drawing file (by "C# program", I assume it is an stand-alone EXE, or some kind of service type app). For example, if it is an EXE that interact with user, then why do you want to create your own "AutoCAD" without visual functionality with RealDwg SDK, which comes with quite high license fee? If the app is a service type, using Platform API cloud is much cheaper that buying RealDwg, unless your service could have big enough user base; or you can use AutoCAD core console in the service app. The good thing with Platform API or AutoCAD core console is that the code for DWG file process are the same as when directly used i n AutoCAD plugin.

 

RealDwg SDK would be my last option and only when the business return/user base would be expected being worth it, not only the license fee, but the development effort. If you are not familiar to AutoCAD/DWG, you may still need to learn from doing .NET API AutoCAD plugin as start point. That is, before you want to deal with DWG without AutoCAD, you might need to know very well how to deal with DWG with AutoCAD.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 10 of 13

adam_luER5XJ
Contributor
Contributor

If I can only use it within an AutoCAD, it will be challenging to achieve my automation goals. I'll explain my goal in more detail in my following response.

 

I'm not familiar with AutoCAD core console, but I'll investigate it further. Any suggestions would be greatly appreciated.

0 Likes
Message 11 of 13

adam_luER5XJ
Contributor
Contributor

Thank you for your responses. I'm actually quite new to AutoCAD and am looking for a solution to automate a specific task.

 

We need to create a service that combines multiple dwg files into a single one and adds text based on user-provided input. The process needs to be fully automated. The reason I'm using C# is because our existing services are built on .NET MVC.

 

Currently, I'm exploring various options to achieve this. Based on my research and inquiries, it seems that RealDWG, Platform API cloud, and third-party solutions are the most viable choices.
Given our use case, it’s indeed difficult for us to afford the RealDWG license fee, although it is one of the possible options. However, we are inclined to consider it as a last resort.
Since our data cannot be uploaded to the cloud, Platform API cloud is not a feasible solution.

 

I'm not familiar with AutoCAD core console, but I'll investigate it further. Any suggestions would be greatly appreciated.

0 Likes
Message 12 of 13

norman.yuan
Mentor
Mentor

OK, you correctly identified 3 possible solution to manipulate DWG file in service type application. It is unfortunate that you shou the door to use external/cloud services, which would be the easiest and economically viable solution.

 

Platform API hosts AutoCAD core console in remotely with service environment setup API support so we as cloud API users could easily build our own apps (services or user-facing apps) easily. If you use AutoCAD core console locally, you would nee to build/configure the it running environment correctly. Also, core console only available with full AutoCAD desktop license (i.e. you need to install full AutoCAD in order to have the core console available), and you may want to consult Autodesk/your AutoCAD reseller about possible license issue regarding using the full license in service type app/process.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 13 of 13

adam_luER5XJ
Contributor
Contributor

I looked into AutoCAD Core Console, which can run scripts to perform certain automated tasks. The scripts can be written in AutoLISP or ObjectARX, and I think this might help me achieve my goal. However, according to the official documentation, there are some usage limitations, and I’m not sure how much these might impact the automation I want to implement.

Here’s a screenshot of the usage limitations from the official documentation:

擷取.PNG

So far, I understand that if I use ObjectARX, I won’t be able to use the AutoCAD user interface (UI). For example, I might not be able to import or link an Excel table into a DWG, since this action typically requires the UI in AutoCAD. Is this understanding correct? If I use AutoLISP, would this limitation be removed, allowing me to accomplish this task?

Has anyone used AutoCAD Core Console before who could offer some advice on which script type (ObjectARX or AutoLISP) might be better in terms of functionality or maintainability?

@_gile@norman.yuan, have you ever used AutoCAD Core Console?

0 Likes