Connecting Tech Pros Worldwide Forums | Help | Site Map

reading autocad parameters in c#.net

Newbie
 
Join Date: Mar 2008
Posts: 3
#1: Apr 18 '08
Hi friends,
I want to open an autocad file using C# program in asp.net and read the parameters of that .dwg file.I could able to open the .dwg file but dont know how to read the parameters like length,height of wall,doors,window and number of windows etc.
I opened the file by following code
Expand|Select|Wrap|Line Numbers
  1. using AutoCAD;
  2.  
  3. public static AcadApplication gbl_open;
  4.     public  static AcadApplication gbl_app;
  5.     public static AcadDocument gbl_doc;
  6.     public static AcadModelSpaceClass gbl_modSpace;
  7.     public static AcadAcCmColor gbl_color;
  8.     public static double gbl_pi = 3.14159;
  9.     public static AcadLayer TerminalsLayer;
  10.     public static AcadLayer SwitchLayer;
  11.     public static AcadLayer TerminationPoints; 
  12.  
  13. public void OpenDocument(string DocumentName)
  14.     {
  15.         gbl_open = new AcadApplication();
  16.         gbl_doc=gbl_open.Documents.Open(DocumentName,true,"gg");
  17.         gbl_open.Application.Visible = false;
  18.         ExtractData();
  19.     }
  20.     public void ExtractData()
  21.     { 
  22.     // Create some settings for the extraction
  23.         int height=gbl_doc.Height;
  24.         int width = gbl_doc.Width;
  25.  
  26.  
  27.     }
(Purpose is that by reading those parameter the program must be able to calculate the cost.)

I'm new to autocad.so I'm confused.can anyone help me?

dim505

Newbie
 
Join Date: Jul 2009
Posts: 1
#2: Jul 7 '09

re: reading autocad parameters in c#.net


Hi, the below code can be useful to you..
Expand|Select|Wrap|Line Numbers
  1. using AutoCAD;
  2.  
  3. public string ExtractContent()
  4.         {            
  5.             AcadApplication app = null;
  6.             AcadDocument doc;
  7.             AcadModelSpace modelspace;
  8.             StringBuilder buf = new StringBuilder();
  9.             try
  10.             {
  11.                 string inFileName = "DocumentName(file path...)";
  12.                 app = new AcadApplication();
  13.                 //To open the file in readonly mode
  14.                 doc = app.Documents.Open(inFileName, true, string.Empty);
  15.                 app.Application.Visible = false;
  16.                 modelspace = doc.ModelSpace;
  17.  
  18.                 for (int i = 0; i < modelspace.Count; i++)
  19.                 {
  20.                     AcadEntity entity = modelspace.Item(i);
  21.                     if (entity.EntityType == 32)
  22.                     {
  23.                         AcadText text = (AcadText)entity;
  24.                         buf.Append(text.TextString);
  25.                         buf.Append(' ');
  26.                     }
  27.                 }
  28.                 return buf.ToString();
  29.             }
  30.             catch (Exception ex)
  31.             {
  32.                 Trace.WriteLine("Exception in indexing asset" + asset.AssetId + ex.Message);                
  33.             }
  34.             finally
  35.             {
  36.                 if (app != null)
  37.                 {
  38.                     app.Documents.Close();
  39.                     app.Quit();
  40.                 }
  41.             }
  42.             return buf.ToString();
  43.         } 

Model space gives the entity objects like line, rectangle, circle and text etc. using that entities we ill get the parameters

-jyothi
Reply


Similar .NET Framework bytes