We looked at various DCS flavors including Model Viewport DCS, Paper Viewport DCS, and Paper Space DCS (PSDCS) and performed almost all possible transformations among them, WCS, and UCS in the past. Single Viewport and Multiple were both addressed. Many implications and tips were also presented.

In this series of articles, we talk and demonstrate about OCS (ECS) as far as AutoCAD .NET is concerned.

We output AutoCAD .NET ARC Object Properties directly, transformed them to get the ARC properties as displayed by the Properties UI or as the DXF code. In this post, let’s create a pattern into an ARC regardless of the current AutoCAD UCS/WCS or the OCS/ECS of the Arc itself.

The pattern looks as the following.

Here is the sample code and command.

[CommandMethod("TestOCS20")]

public static void CreateArcPattern()

{

Document curDoc = MgdAcApplication.DocumentManager.MdiActiveDocument;

try

{

PromptEntityResult prEntRes1 = curDoc.Editor.GetEntity("\nPick an arc");

if (prEntRes1.Status == PromptStatus.OK && prEntRes1.ObjectId.ObjectClass.DxfName == "ARC")

{

using (Transaction trans = curDoc.TransactionManager.StartTransaction())

{

Arc arc = (Arc)trans.GetObject(prEntRes1.ObjectId, OpenMode.ForRead);

Matrix3d ocs2wcs = Matrix3d.PlaneToWorld(arc.Normal);

Matrix3d ecs2wcs = ocs2wcs.PostMultiplyBy(Matrix3d.Displacement(arc.Center.TransformBy(ocs2wcs.Inverse()) - Point3d.Origin));

double radius = arc.Radius / (1 + 1 / Math.Sin(arc.TotalAngle / 2));

Point3d center = new Point3d(Math.Cos(arc.TotalAngle / 2 + arc.StartAngle), Math.Sin(arc.TotalAngle / 2+arc.StartAngle), 0) * (arc.Radius - radius);

BlockTableRecord btr = (BlockTableRecord)trans.GetObject(arc.BlockId, OpenMode.ForWrite);

using (Line line1 = new Line())

{

line1.EndPoint = new Point3d(Math.Cos(arc.StartAngle), Math.Sin(arc.StartAngle), 0) * arc.Radius;

line1.ColorIndex = 1;

line1.TransformBy(ecs2wcs);

btr.AppendEntity(line1);

trans.AddNewlyCreatedDBObject(line1, true);

}

using (Line line2 = new Line())

{

line2.EndPoint = new Point3d(Math.Cos(arc.EndAngle), Math.Sin(arc.EndAngle), 0) * arc.Radius;

line2.ColorIndex = 1;

line2.TransformBy(ecs2wcs);

btr.AppendEntity(line2);

trans.AddNewlyCreatedDBObject(line2, true);

}

using (Circle cir = new Circle())

{

cir.Center = center;

cir.Radius = radius;

cir.ColorIndex = 1;

cir.TransformBy(ecs2wcs);

btr.AppendEntity(cir);

trans.AddNewlyCreatedDBObject(cir, true);

}

trans.Commit();

}

}

}

catch (System.Exception ex)

{

curDoc.Editor.WriteMessage(ex.ToString());

}

}

AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides many project wizards, item wizards, coders and widgets to help automate AutoCAD conveniently and professionally using the AutoCAD .NET API.

## Recent Comments

Spiderinnet1:Karl, it seems the BasePoint was assigned to th... | more »karl:my rubberband does not center on my chosen poin... | more »Spiderinnet1:Karl, you are welcome. In terms of rotating a b... | more »