Hi,
I am just learning about classes and how to use them to save time writing code.
I would like some help or direction on how I could create 1000 circles 8 feet apart from each other starting at 0,0.
I can make one circle thanks help file, but I am quite vague on the clearest way to accomplish more.
Thanks
[CommandMethod("AddManyCircle")] public static void ManyCircles() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Create a circle that is at 2,3 with a radius of 4.25 using (Circle acCirc = new Circle()) { acCirc.Center = new Point3d(2, 3, 0); acCirc.Radius = 4.25; acBlkTblRec.AppendEntity(acCirc); acTrans.AddNewlyCreatedDBObject(acCirc, true); } acTrans.Commit(); } }
Solved! Go to Solution.
Solved by Keith.Brown. Go to Solution.
Just create a loop around your circle creation code and increment an integer. Use that integer as either your x, y, or z value to increment the placement of the circle.
so instead of
using (Circle acCirc = new Circle()) { acCirc.Center = new Point3d(2, 3, 0); acCirc.Radius = 4.25; acBlkTblRec.AppendEntity(acCirc); acTrans.AddNewlyCreatedDBObject(acCirc, true); }
You would have something like
for(i = 0, i < 1000, i++) { int x = 96 * i // increment by 8ft or 96 inches using (Circle acCirc = new Circle()) { acCirc.Center = new Point3d(2 + x, 3, 0); acCirc.Radius = 4.25; acBlkTblRec.AppendEntity(acCirc); acTrans.AddNewlyCreatedDBObject(acCirc, true); } }
I did this off the top of my head and did not test it but I believe that it is correct.