.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create 1000 Circles

1 REPLY 1
SOLVED
Reply
Message 1 of 2
JONTHEPOPE
295 Views, 1 Reply

Create 1000 Circles

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();
    }
}

 

 

1 REPLY 1
Message 2 of 2
Keith.Brown
in reply to: JONTHEPOPE

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.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost