Dimension In 3d Using VB.Net

Dimension In 3d Using VB.Net

NEP_perpetual
Participant Participant
1,037 Views
2 Replies
Message 1 of 3

Dimension In 3d Using VB.Net

NEP_perpetual
Participant
Participant

I'm writing a .Net extension for AutoCAD and I've been unsucessful in trying to make dimensions in 3d (i.e. on the z axis).  Here is the code that I'm have to try to accomplish this:

 

Dim doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db = doc.Database
Dim ed = doc.Editor

Using trx As Transaction = db.TransactionManager.StartTransaction()

	' Open the Block table for read
	Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
	' Open the Block table record Model space for write
	Dim acBlkTblRec As BlockTableRecord = trx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

	' Create the dimension
	Dim acRotDim As RotatedDimension = New RotatedDimension()
	acRotDim.SetDatabaseDefaults()
	acRotDim.XLine1Point = New Point3d(120, 120, 0)
	acRotDim.XLine2Point = New Point3d(120, 120, 120)
	acRotDim.DimLinePoint = New Point3d(140, 120, 0)

	' Add the new object to Model space and the transaction
	acBlkTblRec.AppendEntity(acRotDim)
	trx.AddNewlyCreatedDBObject(acRotDim, True)

	trx.Commit()
End Using

 

 

When this code is run the dimension is created and the extension line snaps are in the correct places.  However, the lines and text are stuck on the "ground" and it's shows a distance of 0.  How can I create the dimension so that it's on the right plane?

0 Likes
Accepted solutions (1)
1,038 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You also need to set the Rotation, Normal and Elevation properties.

 

            Document doc = AcAp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var space = (BlockTableRecord)tr.GetObject(
                    SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
                var dim = new RotatedDimension();
                dim.SetDatabaseDefaults();
                dim.XLine1Point = new Point3d(120.0, 120.0, 0.0);
                dim.XLine2Point = new Point3d(120.0, 120.0, 120.0);
                dim.DimLinePoint = new Point3d(140.0, 120.0, 0.0); 
dim.Rotation = Math.PI / 2.0; // 90° for vertical rotated dimension dim.Normal = new Vector3d(0.0, -1.0, 0.0); // parallel to XZ plane dim.Elevation = -120.0; // Elevation on the XZ plane space.AppendEntity(dim); tr.AddNewlyCreatedDBObject(dim, true); tr.Commit(); }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

NEP_perpetual
Participant
Participant

Thanks, that works perfectly!

0 Likes