Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just started studying C#. Yes I'm a newbie.
Through Microsoft Visual Studio 2010, I would like to import the drawing I created in Autocad.

http://exchange.autodesk.com/autocadarchitecture/enu/online-help/browse#WS73099cc142f48755f2fc9df120970276f7-5354.htm[^]
is the autodesk website where I followed the process, and here's the following code I copied.

-------------------------------------------------------------------------------

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

 
[assembly: CommandClass(typeof(MyFirstProject1.Class1))]
 
namespace MyFirstProject1
{
  public class Class1
  {
      [CommandMethod("AdskGreeting")]
      public void AdskGreeting()
      {
          // Get the current document and database, and start a transaction
          Document acDoc = Application.DocumentManager.MdiActiveDocument;
          Database acCurDb = acDoc.Database;
 
          // Starts a new transaction with the Transaction Manager
          using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
          {
              // Open the Block table record for read
              BlockTable acBlkTbl;
              acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
 
              // Open the Block table record Model space for write
              BlockTableRecord acBlkTblRec;
              acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
 
              /* Creates a new MText object and assigns it a location,
              text value and text style */
              MText objText = new MText();
 
              // Specify the insertion point of the MText object
              objText.Location = new Autodesk.AutoCAD.Geometry.Point3d(2, 2, 0);
 
              // Set the text string for the MText object
              objText.Contents = "Greetings, Welcome to the AutoCAD .NET Developer's Guide";
 
              // Set the text style for the MText object
              objText.TextStyleId = acCurDb.Textstyle;
 
              // Appends the new MText object to model space
              acBlkTblRec.AppendEntity(objText);
 
              // Appends to new MText object to the active transaction
              acTrans.AddNewlyCreatedDBObject(objText, true);
 
              // Saves the changes to the database and closes the transaction
              acTrans.Commit();
          }
      }
  }
}

--------------------------------------------------------------------------------

I'm getting errors on CommandClass, CommandMethod, Document, and Document Manager.
I referecned acdbmgd.dll, acmgd.dll(Autocad .NET API ) files, and added
using Autodesk.AutoCAD.Runtime;

However, the error says that The type or namespace could not be found.I don't get it!!
Posted
Updated 12-Jun-12 23:27pm
v2
Comments
Member 12934059 1-Feb-17 0:35am    
I want to use the dxf and iges file format in c#,it should import and export the files in iges and dxf format.
what should i do to do this ?

1 solution

The keyword your'e lookin for is ObjectARX.

http://www.objectarx.com/[^]

That is (one of) Autodesk's interface to AutoCAD. There sould be also a bunch of examples comming with the SDK.

good luck ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900