Sweeping solid along polyline path

Sweeping solid along polyline path

A_Taha
Participant Participant
2,026 Views
7 Replies
Message 1 of 8

Sweeping solid along polyline path

A_Taha
Participant
Participant

I'm writing a code that should sweep solid entities using 3d polylines as sweeping paths. I downloaded a function form Through the interface to use it as a base. I tried to sweep a solid using a Circle entity as sweep entity and Polylines as sweep path  but I get a GeneralModelingFailure error; either with a 2d or 3d Polyline. It works fine with Line and Spline entities as sweeping paths. The strange thing is that When I do a Sweep command on AutoCAD and select the Polyline as a path it works perfectly without any problem. Is there any explanation for why this can't be done programmatically? Any suggestions for workaround?

Thanks

A. Taha

0 Likes
Accepted solutions (1)
2,027 Views
7 Replies
Replies (7)
Message 2 of 8

A_Taha
Participant
Participant

Here is the link to the original code I'm using:

https://www.keanw.com/2010/01/sweeping-an-autocad-solid-using-net.html

 

0 Likes
Message 3 of 8

_gile
Consultant
Consultant

Hi,

 

You should also attach the drawing with which you got the error.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 8

A_Taha
Participant
Participant

I'm attaching the file here.

I was making random trials before it wasn't working on 2d and 3d polylines. When I was preparing this file to upload, it worked on 3d polyline, but gave same error on 2d polyline. There is still something weird!

0 Likes
Message 5 of 8

_gile
Consultant
Consultant
Accepted solution

Hi,

try removing the SweepOptionsBuilder.BasePoint and SweepOptionsBuilder.Bank sttings.

 

This works for me:

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

            var options = new PromptEntityOptions("\nSelect circle: ");
            options.SetRejectMessage("\nInvalid selection.");
            options.AddAllowedClass(typeof(Circle), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK) return;
            var sweepId = result.ObjectId;

            options.Message = "\nSelect the path Curve; ";
            options.AddAllowedClass(typeof(Curve), false);
            result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK) return;
            var pathId = result.ObjectId;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var sweepEnt = (Circle)tr.GetObject(sweepId, OpenMode.ForRead);
                var pathEnt = (Curve)tr.GetObject(pathId, OpenMode.ForRead);
                using (var solid = new Solid3d())
                {
                    var sob = new SweepOptionsBuilder();
                    sob.Align = SweepOptionsAlignOption.AlignSweepEntityToPath;
                    solid.CreateSweptSolid(sweepEnt, pathEnt, sob.ToSweepOptions());
                    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 6 of 8

rfoda
Explorer
Explorer

--

0 Likes
Message 7 of 8

A_Taha
Participant
Participant

It worked perfectly by removing these two lines. I think they have a function in some other cases; but for me it's doing the job correctly when they're eliminated.

Thanks
A. Taha

0 Likes
Message 8 of 8

Anonymous
Not applicable
I also encountered these problems when I was doing sweeping, but I still did not solve them after reading what you said. Is it convenient to look at your code? Thank you
0 Likes