How to replace torus as cylinder in Autocad via .net

How to replace torus as cylinder in Autocad via .net

Anonymous
Not applicable
521 Views
2 Replies
Message 1 of 3

How to replace torus as cylinder in Autocad via .net

Anonymous
Not applicable

Hi

 

I have autocad file with 600 torus solid3d inside and the question is how to replace this torus as cylinders with this same property?

Maybe more specific how to take info from solid3d SolidType = "torus" like TorusRadius ?

It is possible ?

0 Likes
522 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant

Hi,

 

Here's an example using the Boudary Representation API (acmgdbrep.dll have to be referenced):

 

        [CommandMethod("TEST")]
        public void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var opts = new PromptEntityOptions("\nSelect a torus: ");
            opts.SetRejectMessage("\nSelected object is not a Solid 3D.");
            opts.AddAllowedClass(typeof(Solid3d), true);
            var res = ed.GetEntity(opts);
            if (res.Status != PromptStatus.OK)
                return;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var solid = (Solid3d)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                using (var brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(solid))
                {
                    if (brep.Faces.Count() != 1)
                    {
                        ed.WriteMessage("\nSelected object is not a torus.");
                        return;
                    }
                    var surf = (ExternalBoundedSurface)brep.Faces.First().Surface;
                    var torus = surf.BaseSurface as Torus;
                    if (torus == null)
                    {
                        ed.WriteMessage("\nSelected object is not a torus.");
                        return;
                    }
                    ed.WriteMessage("\nTorus" +
                        $"\n\tCenter: {torus.Center}" +
                        $"\n\tAxis: {torus.AxisOfSymmetry}" +
                        $"\n\tMajor radius: {torus.MajorRadius}" +
                        $"\n\tMinor radius: {torus.MinorRadius}");
                }
                    tr.Commit();
          

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

Anonymous
Not applicable

Great Thank you !

0 Likes