- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day. I'm new to AutoCAD programming.
I'm trying to add rotated dimensions objects to the line I created programmatically.
I set the properties
XLine1Point = to the start X, Y of the line,
XLine2Point = to the end X, Y of the line.
But after generating the objects I have noticed that the RotDim Objects display wrong measurements.
Please see attached image below.
Red Dimension - Generated by the program
White Dimension - Manual
Here is my function to generate the RotDim Object.
public void CreateRotatedDimension(double xLine1_X, double xLine1_Y, double xLine2_X, double xLine2_Y, double dimLine_X, double dimLine_Y, string pos, string col)
{
// Get the current database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
using (DocumentLock docLock = acDoc.LockDocument())
{
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Create the rotated dimension
RotatedDimension acRotDim = new RotatedDimension();
acRotDim.SetDatabaseDefaults();
acRotDim.XLine1Point = new Point3d(xLine1_X, xLine1_Y, 0);
acRotDim.XLine2Point = new Point3d(xLine2_X, xLine2_Y, 0);
acRotDim.DimLinePoint = new Point3d(dimLine_X, dimLine_Y, 0);
acRotDim.DimensionStyle = acCurDb.Dimstyle;
if (col == "green")
{
acRotDim.Dimclrt = green;
acRotDim.Dimtxt = 320;
}
else
{
acRotDim.Dimclrt = red;
acRotDim.Dimtxt = 300;
}
if (pos == "V")
{
acRotDim.Rotation = 1.57;
}
else
{
acRotDim.Rotation = 3.14;
}
// Add the new object to Model space and the transaction
acBlkTblRec.AppendEntity(acRotDim);
acTrans.AddNewlyCreatedDBObject(acRotDim, true);
// Commit the changes and dispose of the transaction
acTrans.Commit();
}
}
}
Here is my code to call the function to generate the object.
GenerateObjects obj = new GenerateObjects();
obj.CreateRotatedDimension(AA_C_Line_StartX, AA_C_Line_StartY, AA_C_Line_EndX, AA_C_Line_EndY, AA_C1_RotDimText_PosX, AA_C1_RotDimText_PosY, "H", "red");
obj.CreateRotatedDimension(AA_C_Line_StartX, AA_C_Line_StartY, AA_C_Line_EndX, AA_C_Line_EndY, AA_C2_RotDimText_PosX, AA_C2_RotDimText_PosY, "V", "red");
I already double-checked the values passed to the function.
I also uploaded the sample drawing file. Please see attached file.
Your response is highly appreciated. Thanks.
Solved! Go to Solution.