reading autocad parameters in c#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dim505
    New Member
    • Mar 2008
    • 3

    reading autocad parameters in c#.net

    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,wind ow and number of windows etc.
    I opened the file by following code
    Code:
    using AutoCAD;
    
    public static AcadApplication gbl_open;
        public  static AcadApplication gbl_app;
        public static AcadDocument gbl_doc;
        public static AcadModelSpaceClass gbl_modSpace;
        public static AcadAcCmColor gbl_color;
        public static double gbl_pi = 3.14159;
        public static AcadLayer TerminalsLayer;
        public static AcadLayer SwitchLayer;
        public static AcadLayer TerminationPoints; 
    
    public void OpenDocument(string DocumentName)
        {
            gbl_open = new AcadApplication();
            gbl_doc=gbl_open.Documents.Open(DocumentName,true,"gg");
            gbl_open.Application.Visible = false;
            ExtractData();
        }
        public void ExtractData()
        { 
        // Create some settings for the extraction
            int height=gbl_doc.Height;
            int width = gbl_doc.Width;
    
          
        }
    (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
    Last edited by Frinavale; Jul 7 '09, 02:17 PM. Reason: Added code tags. Please post code in [code] [/code] tags.
  • SaiJyothi
    New Member
    • Jul 2009
    • 1

    #2
    reading entities from cad drawing using c#.net

    Hi, the below code can be useful to you..
    Code:
    using AutoCAD;
    
    public string ExtractContent()
            {            
                AcadApplication app = null;
                AcadDocument doc;
                AcadModelSpace modelspace;
                StringBuilder buf = new StringBuilder();
                try
                {
                    string inFileName = "DocumentName(file path...)";
                    app = new AcadApplication();
                    //To open the file in readonly mode
                    doc = app.Documents.Open(inFileName, true, string.Empty);
                    app.Application.Visible = false;
                    modelspace = doc.ModelSpace;
    
                    for (int i = 0; i < modelspace.Count; i++)
                    {
                        AcadEntity entity = modelspace.Item(i);
                        if (entity.EntityType == 32)
                        {
                            AcadText text = (AcadText)entity;
                            buf.Append(text.TextString);
                            buf.Append(' ');
                        }
                    }
                    return buf.ToString();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Exception in indexing asset" + asset.AssetId + ex.Message);                
                }
                finally
                {
                    if (app != null)
                    {
                        app.Documents.Close();
                        app.Quit();
                    }
                }
                return buf.ToString();
            }

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

    -jyothi
    Last edited by Frinavale; Jul 7 '09, 02:18 PM. Reason: Added code tags. Please post code in [code] [/code] tags.

    Comment

    Working...