Entities to add to DB

Entities to add to DB

Anonymous
Not applicable
448 Views
2 Replies
Message 1 of 3

Entities to add to DB

Anonymous
Not applicable

If I wanted to create an extruded instance of Solid3d then I'd like to know what entities along the way would i need to add to the DB.

 

first I will be creating a polyline then a region from it and then extrude the region. there are 3 entities being created so should i add all 3 entities or adding just the last one (extruded solid) would suffice?

 

0 Likes
Accepted solutions (1)
449 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Adding the polyline and the regionto the database is not mandatory but you're responsible to dispose the newly created entites you do not add to the database (and transaction).

Here's a simple example:

 

        static void ExtrudPolyline()
        {
            var db = HostApplicationServices.WorkingDatabase;
            using (var tr = db.TransactionManager.StartTransaction())
            using (var pline = new Polyline(4))
            using (var curves = new DBObjectCollection())
            {
                pline.AddVertexAt(0, new Point2d(10.0, 5.0), 0.0, 0.0, 0.0);
                pline.AddVertexAt(1, new Point2d(20.0, 5.0), 0.0, 0.0, 0.0);
                pline.AddVertexAt(2, new Point2d(20.0, 15.0), 0.0, 0.0, 0.0);
                pline.AddVertexAt(3, new Point2d(10.0, 15.0), 0.0, 0.0, 0.0);
                pline.Closed = true;
                curves.Add(pline);
                using (var regions = Region.CreateFromCurves(curves))
                using (var region = (Region)regions[0])
                using (var solid = new Solid3d())
                {
                    solid.Extrude(region, 10.0, 0.0);
                    var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    curSpace.AppendEntity(solid);
                    tr.AddNewlyCreatedDBObject(solid, true);
                }
                tr.Commit();
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks and very much appreciated!

0 Likes