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.

Earlier, we created concentric circles to an existing one through either specifying the circle normal, center, and radius directly in WCS or using OCS (ECS) transformation. We also created tangent circles both internally and internally to an existing circle along either the OCS (ECS) X-axis or the current UCS X-axis using OCS (ECS) transformation as well.

Previously, we created ten circles tangent to each other but all along an existing circle, or internally tangent to, or externally tangent to another circle. In this post, let’s create a circle pattern into an existing circle. Here we go:

[CommandMethod("TestOCS15")]

public static void CreateCirclePattern4()

{

Document curDoc = MgdAcApplication.DocumentManager.MdiActiveDocument;

try

{

PromptEntityResult prEntRes1 = curDoc.Editor.GetEntity("\nPick a circle");

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

{

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

{

Circle cir = (Circle)trans.GetObject(prEntRes1.ObjectId, OpenMode.ForRead);

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

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

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

double alpha = Math.Asin(1.0 / 3);

int number = 120;

for (int i = 0; i < number; i++)

{

double angle = Math.PI * 2 * i / number;

Point3d pt = new Point3d(cir.Radius * Math.Cos(angle), cir.Radius * Math.Sin(angle), 0);

Point3d pt1 = new Point3d(cir.Radius * Math.Cos(angle + Math.PI - 2 * alpha), cir.Radius * Math.Sin(angle + Math.PI - 2 * alpha), 0);

Point3d pt2 = new Point3d(cir.Radius * Math.Cos(angle + Math.PI + 2 * alpha), cir.Radius * Math.Sin(angle + Math.PI + 2 * alpha), 0);

using (Line line1 = new Line())

{

line1.StartPoint = pt;

line1.EndPoint = pt1;

line1.ColorIndex = i * 2;

line1.TransformBy(ecs2wcs);

btr.AppendEntity(line1);

trans.AddNewlyCreatedDBObject(line1, true);

}

using (Line line2 = new Line())

{

line2.StartPoint = pt;

line2.EndPoint = pt2;

line2.ColorIndex = i * 2 + 1;

line2.TransformBy(ecs2wcs);

btr.AppendEntity(line2);

trans.AddNewlyCreatedDBObject(line2, true);

}

}

trans.Commit();

}

}

}

catch (System.Exception ex)

{

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

}

}

Here is the output, as expected:

The ocs2wcs matrix variable in the code corresponds to the OCS concept as commonly used. However, the ecs2wcs here is not the same as the ocs2wcs. It rather represents the real circle ECS, its Z-axis still as the circle normal, its X-axis the same as the X-axis of the circle OCS, but its origin as the center point of the circle. In this way, the ECS is both natural and very easy to use. As can be seen, with the further transformation applied, we only need to specify the centers and the radii of the new circles to make a nice circle pattern into an existing circle.

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 »