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

GEt Dimension geometry vb.net[2010] and AutoCAD over 2012

3 REPLIES 3
Reply
Message 1 of 4
thenndral
1908 Views, 3 Replies

GEt Dimension geometry vb.net[2010] and AutoCAD over 2012

Hello,

 

Is it possible to get Gimension geometry data?

I'm using Vb.net 2010 with AutoCAD 2012 or 2013.

 

please give me some source sample or suggestion.

 

Please check the image for reference.

dimension.png

 

 

Thanks in advance,

thenndral.

 

 

3 REPLIES 3
Message 2 of 4
cdinten
in reply to: thenndral

Have you read about the class "Autodesk.AutoCAD.DatabaseServices.Dimension"? it is an abstract class which is the base class for all the Dimensions(such as AlignedDimension, LineAngularDimension2 and so on). The class Dimension has some properties, but not much. These properties could be used by the derived classes.

As for the "Angular" dimension, ObjectARX.NET got 2 classes: LineAngularDimension2 and Point3AngularDimension. the LineAngularDimension2 class has some other properties like ArcPoint,XLine1Start, XLine1End,XLine2Start, XLine2End, when you encouter other dimensions , say AlignedDimension, the properties are DimLinePoint, Oblique, XLine1Point, XLine2Point .

By using these properties and some other properties from Entity, I can assure you get what you wish. Hope this be helpful to you.

BTW, I use C# rather than VB.NET, so I  do not have source~

Message 3 of 4
thenndral
in reply to: cdinten

Thank you so much for your reply.

 

If you have a source in C# Please share with me. It will guide me more.

 

Thanks again,

thenndral

Message 4 of 4
thenndral
in reply to: thenndral

Hello,

 

I got this source code here

This code is create in C#, I don't have an experience in C# so, Can anyone help me how to make this in vb.net?

It will be really helpful to finish my task.

 

Code:

 // Get the geometry from a dimension entity
        // translated on C# from article by  Augusto Goncalves:
        // http://adndevblog.typepad.com/autocad/2013/01/get-the-geometry-from-a-dimension-entity.html
        [CommandMethod("dgeom", CommandFlags.UsePickSet)]
        public void GetDimensionLinesData()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Database db = doc.Database;

            Transaction tr = doc.TransactionManager.StartOpenCloseTransaction();

            using (tr)
            {

                Dimension diment = null;

                PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Dimension>>");
                peo.SetRejectMessage("\nSelect Dimension only >>");
                peo.AddAllowedClass(typeof(Dimension), false);
                PromptEntityResult res;
                res = ed.GetEntity(peo);
                if (res.Status != PromptStatus.OK)
                    return;
                Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                if (ent == null)
                    return;
                diment = (Dimension)ent as Dimension;
                if (diment == null)
                {
                    ed.WriteMessage("\nError: selected entity is not a Dimension");
                    return;
                }
                //get current space
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                //get dimension block definition
                BlockTableRecord dimbtr = tr.GetObject(diment.DimBlockId, OpenMode.ForRead) as BlockTableRecord;
                MessageBox.Show(dimbtr.Name);
                BlockTableRecordEnumerator iter = dimbtr.GetEnumerator();
                Entity obj;
                // Iterate every entity stored in the 
                // block definition of the dimension.
                while (iter.MoveNext())
                {
                   
                    obj = tr.GetObject((ObjectId)iter.Current, OpenMode.ForRead) as Entity;

                    Line ln = obj as Line;

                    if (ln != null)
                    {

                        // Get the start and end point.  

                        Point3d sp, ep;

                        sp = ln.StartPoint;
                        ep = ln.EndPoint;


                        //     // Transform the start and end point.   

                        //     // Get the transformation matrix.   

                        Matrix3d mat = new Matrix3d();

                        // Get the axis of the dimension entity. 

                        Vector3d zAxis = diment.Normal;

                        Vector3d xAxis = zAxis.GetPerpendicularVector();

                        Vector3d yAxis = zAxis.CrossProduct(xAxis);

                        // Build the transformation matrix.    
                        
                        mat = Matrix3d.AlignCoordinateSystem(Point3d.Origin, new Vector3d(1.0, 0.0, 0.0),

                          new Vector3d(0.0, 1.0, 0.0),

                          new Vector3d(0.0, 0.0, 1.0),

                          Point3d.Origin,

                          xAxis, yAxis, zAxis);
                     

                        // To test this matrix create a new line   

                        // using the start and endpoint of the line 

                        // from the block definition, and transform   

                        // the line using the calculated transformation matrix.     

                        Line newln = new Line(sp, ep);

                        newln.TransformBy(mat);

                        Point3d nptStart, nptEnd;

                        nptStart = newln.StartPoint;

                        nptEnd = newln.EndPoint;

                        newln.ColorIndex = 4;

                        // Append the new line to the model space and close it.    

                        // The new line should be at the location     

                        // of the dimension entity.     

                        
                        btr.AppendEntity(newln);
                        tr.AddNewlyCreatedDBObject(newln, true);
               
                    }

                    tr.Commit();

                }
            }
        }

 

 

 

Thanks in advance,

thenndral.

 

 

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