Creating cylinder (Solid3d object) using .NET API.

By Virupaksha Aithal

 To insert a cylindrical solid object into the AutoCAD database, you can use a Solid3d database object. To define a cylinder, you use the Solid3d.CreateFrustum() method. Remember to call RecordHistory to record solid history.

<CommandMethod("CreateCylinder")> _

       Public Shared Sub CreateCylinder()

            Dim radius As Double = 1.2345

            Dim height As Double = 2.3456

 

            Dim doc As Document = _

                        Application.DocumentManager.MdiActiveDocument

            Dim db As Database = _

                        doc.Database

            Dim tm As Transaction = _

                            db.TransactionManager.StartTransaction()

            Using tm

                Dim solid As New Solid3d()

                solid.RecordHistory = True

                solid.CreateFrustum(height, radius, radius, radius)

 

                Dim bt As BlockTable = _

                    tm.GetObject(db.BlockTableId, OpenMode.ForRead)

                Dim btr As BlockTableRecord = _

                    tm.GetObject(bt(BlockTableRecord.ModelSpace), _

                                        OpenMode.ForWrite)

                btr.AppendEntity(solid)

                tm.AddNewlyCreatedDBObject(solid, True)

                tm.Commit()

            End Using

        End Sub


Comments

2 responses to “Creating cylinder (Solid3d object) using .NET API.”

  1. One remark: If you like to insert cylinders with a certain start point and direction you would need to
    a) define an appropriate UCS before creating the cylinder or
    b) transform the entity to reflect these parameters after creating the cylinder

  2. Virupaksha aithal Avatar
    Virupaksha aithal

    Thanks for the comments. I will update the post with your remarks

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading