Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Last active November 18, 2025 07:06
Show Gist options
  • Select an option

  • Save benkoshy/3e3102f4d871bebe1b34c26e779f5ee3 to your computer and use it in GitHub Desktop.

Select an option

Save benkoshy/3e3102f4d871bebe1b34c26e779f5ee3 to your computer and use it in GitHub Desktop.
A method to create a rotated dimension using the AutoCAD .net API

A method to create a rotated dimension using the AutoCAD .net API

protected void drawDimensions(Point3d dimensionPoint, Point3d point1, Point3d point2, double rotation)
{
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
        BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

       
        using (RotatedDimension rotatedDimension = getRotatedDimension(point1, point2, dimensionPoint, rotation))
        {
                // Add the new object to Model space and the transaction
                modelSpace.AppendEntity(rotatedDimension);
                tr.AddNewlyCreatedDBObject(rotatedDimension, true);                        
        }        

        tr.Commit();
    }
}


        protected RotatedDimension getRotatedDimension(Point3d xLinePoint1, Point3d xLinePoint2, Point3d dimensionPoint, double rotation)
        {
            RotatedDimension rotatedDimension = new RotatedDimension();

            rotatedDimension.XLine1Point = xLinePoint1;
            rotatedDimension.XLine2Point = xLinePoint2;
            rotatedDimension.Rotation = rotation;

            // get point returns in UCS, so we need to transform it into WCS coordinates.
            // Editor.CurrentUserCoordinateSystem property which returns the transformation matrix from UCS to WCS
            rotatedDimension.DimLinePoint = dimensionPoint;
            rotatedDimension.DimensionStyle = db.Dimstyle;

            return rotatedDimension;
        }

Video tutorial: https://vimeo.com/1137983762?share=copy&fl=sv&fe=ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment