C# Razor (asp.net) Run AutoCAD Electrical

C# Razor (asp.net) Run AutoCAD Electrical

david.faunce
Enthusiast Enthusiast
1,868 Views
6 Replies
Message 1 of 7

C# Razor (asp.net) Run AutoCAD Electrical

david.faunce
Enthusiast
Enthusiast

I've made an intranet website (employees only) using C# Razor Templates. On the same server that hosts the website, I have AutoCAD Electrical 2017 installed. 

 

My goal is be able to create AutoCAD Projects (and manipulate them) using C# from the Razor website. 

 

I've already gone through the "First Plug-in Training" and I've been able to successfully create a desktop application that can do these tasks I need it to do. 

 

Now I want to translate that code in my Razor C# website.

 

I've installed all of the DLL references (AcDbMgd, AcDx, AcMgd, AcCoreMgd) yet my C# classes are not recognizing some of the crucial AutoDesk libraries.

 

For example:

 

using Autodesk.AutoCAD.Interop;    //<-- Works great

 

using Autodesk.AutoCAD.Runtime;  //<-- ERROR: does not recognize

 

 

Am I doing something wrong? Can someone help point me in the right direction.

 

Any help is appreciated

0 Likes
Accepted solutions (1)
1,869 Views
6 Replies
Replies (6)
Message 2 of 7

norman.yuan
Mentor
Mentor

"Razor" is the .NET language translator engine that allows C#/VB.NET statements directly mixed with ASP.NET pages' HTML. It is used in ASP.NET application, which runs on server side (typically by Windows IIS). It has no direct impact/effect to what you are trying to do (automating AutoCAD, I believe, although your did not describe it clearly).

 

Using server side web application to automating AutoCAD is not an easy task. to say the least, because you need to run 2 different processes (web app on server side; and AutoCAD instance), and have the 2 processes communicate to each other.

 

Since you said "using Autodesk.AutoCAD.Interop" is OK, which means your web app automate AutoCAD with COM API. In this case, you need to start/run AutoCAD on the server. This is a bad option, IMO, because AutoCAD is a very complicated, resources-hungary desktop app, and there are so many chances that AutoCAD would stop (such as popping up a message) and wait for user interaction. Are you going to have an administrator sitting in front of the web server, waiting to respond any possible AutoCAD message?

 

Secondly, since the web app automate AutoCAD as external EXE app, you cannot use AutoCAD .NET API in your web app (that is why you get error on "using Autodesk.AutoCAD.Runtime"

 

If your business solution has to be web app, then you could consider to use your web app to drive AutoCAD console, instead of full AutoCAD as desktop app, or consider using Autodesk' cloud services, which is almost the same as using AutoCAD console.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 7

david.faunce
Enthusiast
Enthusiast

Thank you for your response,  Norman.

 

No there will not be an administrator sitting in front of the application - and yes I do understand that this option is risky as I have experienced the frequent popups even when FILEDIA=0, however, it is a requirement of my employer to have the system be completely automated from the click of a website button.

 

The best approach I can think of right now is using C# (from the website) to open up an instance of AutoCAD (if not already open and not busy) and run a script.  I have been able to accomplish this with a simple script that creates a circle and it seems promising.

 

Any thoughts on if this seems feasible?

0 Likes
Message 4 of 7

dgorsman
Consultant
Consultant

Since this can allow multiple users to run the program from a single license by running on a server, it may very well be in violation of the license terms of use.  You *really* need to talk to Autodesk on this to ensure you're in compliance.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 5 of 7

david.faunce
Enthusiast
Enthusiast

I appreciate your concern, but all users who have access to this web-tool already have a stand-alone license of AutoCAD Electrical 2017 installed - so that isn't a concern.

 

Are there any thoughts on how I can approach this?

0 Likes
Message 6 of 7

norman.yuan
Mentor
Mentor
Accepted solution

Automating an full AutoCAD desktop app instance via COM API on web server side is the worst option one can choose, IMO, it may run OK in a very limited development environment, but for production, it would be nightmare, for sure. And yes, this would violate Autodesk's license.

 

For a web application to manipulate drawing file, the feasible options are:

 

1. using Autodesk's RealDwg SDK (no AutoCAD is required);

2. using Autodesk's cloud services (Autodesk Forge - data management API)

3. AutoCAD core console (comes with AutoCAD installation since Acad2013)

 

In your case, using core console would be the best option, your solution base on it would be easily moved to use Autodesk's cloud services, because the core business logic of your solution could be done with AutoCAD .NET API as an AutoCAD add-in, which can also be used with AutoCAD desktop with or without modification.

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 7 of 7

david.faunce
Enthusiast
Enthusiast

Thank you for the recommendations. I will check out the Core Console.

 

But just to let you know, again, my original plan DOES NOT violate AutoDesk licensing agreement. I spoke with our Vendor about this and they confirmed what I originally planned is legal and within the agreement. 

 

 

There is very minimal automation involved, most of which will be accomplished via LISP. I will not be creating new symbols and drawing wires. It is simply shuffling sheets and changing attributes of blocks. 

 

The project is setup such that each wiring diagram sheet is specific to a particular component.

 

(ie: Sheet #3 of a unique project is Process Fans - This sheet details everything to wire a (or multiple) process fans. There may be 5 different variations of Sheet #3)

 

I have a total of 62 different sheets, however a unique project will produce exactly 16 sheets (the remaining sheets are unused variations).

 

The automation process would be:

1)  Copy a project template (with the 62 sheets) to a new folder with a new name

2)  Remove the sheets that I don't need.

3)  Update the title block to reflect the unique Job Number

4)  In each sheet go through specific symbols and update the part numbers and other meta data.

5)  Update the panel layout drawing (similar to #4)

6) Save

 

This could easily be accomplished with a desktop application, however my hopes were that it could be completely automated through a web-site and I understand now that its not feasible.

 

Anyways, I do appreciate the input from both of you.

 

Thank you

 

 

 

0 Likes