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

AutoCad: draw the table view on the drawing file in AutoCad through C# .Net

4 REPLIES 4
Reply
Message 1 of 5
dhanashribZZC6R
579 Views, 4 Replies

AutoCad: draw the table view on the drawing file in AutoCad through C# .Net

Hello Team,

Greetings...!

 

I am trying to draw table structure on Drawing file through C# code and open that file into AutoCad application.

I am able to find the drawing and open into AutoCad Application. But not getting solution for draw lines or shapes on it.

Can you please help me?

4 REPLIES 4
Message 2 of 5

This tutorial by Autodesk is a great place to start for beginners to AutoCAD .NET Customization.

 

http://usa.autodesk.com/adsk/servlet/index?id=18162650&siteID=123112

 

There are also several Autodesk blogs that are available for your help also.

 

AEC DevBlog 
Around the Corner 
AutoCAD DevBlog 
Beyond the Box 
Cloud & Mobile DevBlog 
Dances with Elephants 
Infrastructure Modeling DevBlog 
It's All Just Ones and Zeros 
Manufacturing DevBlog 
Mod the Machine 
The Building Coder 
Through the Interface 

 

Good Luck! And don't forget to come back and post about your success!

Message 3 of 5

Here is a simple method that will add a line to your drawing from -10 to positive 10 along the X-Axis in the XY Plane.  Note the Attribute to signify to AutoCAD that you have created a new command.

 

        [CommandMethod("LineAdd")]
        public void LineAddCommand()
        {
            // Get the database from the active document
            Database db = HostApplicationServices.WorkingDatabase;

            // A transaction should be used anytime that you are reading from or writing to a database. (There are a few exceptions)
            // Wrapping it up in a using statement will mean that it is automatically disposed when we are finished.
            // Transactions are used to read/write objects in the database by their ObjectId
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                // Lets open up the drawing blocktable for read.  We can get its ObjectId from the database.
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                // The block table is a collection of BlockTableRecords.  ModelSpace happens to be a BlockTableRecord so look up its
                // ObjectId in the blockTable.
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                // A new line can be created by just its start point and its end point.
                Line line = new Line();
                line.StartPoint = new Point3d(-10, 0, 0);
                line.EndPoint = new Point3d(10, 0, 0);

                // Once created we need to add it to ModelSpace.
                ms.AppendEntity(line);

                // Once added to ModelSpace we need to notify the transaction that it was added.
                tr.AddNewlyCreatedDBObject(line, true);

                // We must now commit the transaction so that the database knows we are successfully complete.  We could have aborted
                // also canceled the transaction which would nullify the additon of the line to the database.
                tr.Commit();
            }
        }
Message 4 of 5

Hello Keith,

Thanks for your reply.

I just want to send the draw command or simply draw line on drawing file open by my WPF application.

Can I communicate with autocad 2017 through my C# WPF application?

Message 5 of 5

While this forum's name is ".NET", it mainly focuses on AutoCAD ObjectARX .NET API. So, if you are trying to control/automate AutoCAD from external application, you cannot use AutoCAD .NET API (at least not directly), thus majorities of discussion in this forum would not help you.

 

There are a number of ways to communicate/control AutoCAD from external application with .NET technology, such as NET remoting, WCF, or even latest ASP.NET Web API, SignalR..., but if the external app runs with AutoCAD in the same computer, the most straightforward way is to use the good old COM API. In your app project, open "Add References..." dialog box, in the "COM" tab, find and addd references to AutoCAD Type library and AutoCAD Common ObjectDBX Type Library, then off you go. However, if you are not very familiar with AutoCAD and its API, you need to be a good enough AutoCAD user to understand/use AutoCAD API.

Norman Yuan

Drive CAD With Code

EESignature

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