Curve.CreateFromGeCurve( ) get wrong result, when parameter Curve3d is come from Curve3d.GetSplitCurves ()

Curve.CreateFromGeCurve( ) get wrong result, when parameter Curve3d is come from Curve3d.GetSplitCurves ()

465340553
Mentor Mentor
1,504 Views
5 Replies
Message 1 of 6

Curve.CreateFromGeCurve( ) get wrong result, when parameter Curve3d is come from Curve3d.GetSplitCurves ()

465340553
Mentor
Mentor

English is not my native language and there may be quite a few mistakes,

Thank you for your understanding。

 

Here's the test code

var per1 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity("\nPick Polyline");
if (per1.Status != PromptStatus.OK) return;

var ptr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nPick a Point");
if (ptr.Status != PromptStatus.OK) return;
using (Transaction tr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
{
    BlockTable bt = (BlockTable)tr.GetObject(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.BlockTableId, OpenMode.ForRead, false);
    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
    var pl = per1.ObjectId.GetObject(OpenMode.ForRead) as Curve;
    //Geometry Curve3d
    var geoC = pl.GetGeCurve();
    // splited Curve3d
    var scs = geoC.GetSplitCurves(geoC.GetParameterOf(geoC.GetClosestPointTo(ptr.Value).Point));

    foreach (Curve3d subC in scs)
    {
        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nGeo Curve3d's startpoint and endpoint \t" + subC.StartPoint.ToString() + "\t" + subC.EndPoint.ToString());
        // database Curve
        var dbc = Curve.CreateFromGeCurve(subC);

        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\ndbbase Curve's startpoint and endpoint\t" + dbc.StartPoint.ToString() + "\t" + dbc.EndPoint.ToString());

        btr.AppendEntity(dbc);
        tr.AddNewlyCreatedDBObject(dbc, true);
    }

    tr.Commit();
}

 

I need split Curve3d into segments,

and then Create database Curve,

when I select a Line or a Arc,

the result is right,

But when I select a ployline,

the result is wrong,

the "sub polyline" is as long as the source polyline。

465340553_0-1664696702681.png

465340553_1-1664696763115.png

 

Who can help test the above code,

Find out where my error is。

Thank you so much!

 

 

 

 

王磊
您认为此帖子是否有用?欢迎为此帖点赞。
您的问题是否已得到解答?请点击“接受解答”按钮。

EESignature

0 Likes
Accepted solutions (1)
1,505 Views
5 Replies
Replies (5)
Message 2 of 6

hosneyalaa
Advisor
Advisor
0 Likes
Message 3 of 6

_gile
Consultant
Consultant

Hi,

Why do you convert the selected Curve object into a Curve3d object and then back to curves?

Converting a Polyline into a Curve3d generates a CompositeCurve3d which is a sort of array of Curve3d objects (LineSegment3d and/or CircularArc3d).

The Curve type provides a GetSplitCurves method which you could directly use.

 

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var peo = new PromptEntityOptions("\nSelect a curve: ");
            peo.SetRejectMessage("\nSelected object is not a curve.");
            peo.AddAllowedClass(typeof(Curve), false);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) 
                return;
            var ppr = ed.GetPoint("\nPick a point: ");
            if (ppr.Status != PromptStatus.OK)
                return;
            var point = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curve = (Curve)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
                var points = new Point3dCollection();
                points.Add(curve.GetClosestPointTo(point, false));
                var splitCurves = curve.GetSplitCurves(points);
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                foreach (Entity entity in splitCurves)
                {
                    curSpace.AppendEntity(entity);
                    tr.AddNewlyCreatedDBObject(entity, true);
                }
                curve.Erase();
                tr.Commit();
            }
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 6

465340553
Mentor
Mentor

Thank you for your reply。

 

The test code is a simplified version,

I need to use the method “Curve3d.GetTrimmedOffset Method (double, Vector3d, OffsetCurveExtensionType)”,

And it needs to be calculated with other elements(BoundedPlane),

So I convert the DatabaseServices.Curve into Geometry.Curve3d.

I know the method “ Curve.GetSplitCurves (Point3dCollection) ”。

When my code runs incorrectly,

I thought it was my fault,

So I wrote the test code to ask for advice。

 

My current workaround is to use the method “ Curve.GetSplitCurves (Point3dCollection)”。

 

Thanks!

 

 

 

王磊
您认为此帖子是否有用?欢迎为此帖点赞。
您的问题是否已得到解答?请点击“接受解答”按钮。

EESignature

0 Likes
Message 5 of 6

465340553
Mentor
Mentor
Accepted solution

I found a workaround:

Create a new CompositeCurve3d use the Splitted segment,

var newSegment=new CompositeCurve3d(new Curve3d[] { tmp });

the new CompositeCurve3d is the one I needed!

 

王磊
您认为此帖子是否有用?欢迎为此帖点赞。
您的问题是否已得到解答?请点击“接受解答”按钮。

EESignature

0 Likes
Message 6 of 6

465340553
Mentor
Mentor

后续问题见相关链接

 

See the related links for follow-up questions

王磊
您认为此帖子是否有用?欢迎为此帖点赞。
您的问题是否已得到解答?请点击“接受解答”按钮。

EESignature

0 Likes