Changing the z-coordinate of one of vertex in Polyline3d

Changing the z-coordinate of one of vertex in Polyline3d

imranhasmi54341
Community Visitor Community Visitor
249 Views
2 Replies
Message 1 of 3

Changing the z-coordinate of one of vertex in Polyline3d

imranhasmi54341
Community Visitor
Community Visitor

Please somebody help. Why it does not work? I have Polyline3d in AutoCAD and the target co-ordination to move one of vertex on it. But is does not work. No error, all is clear. But vertex does not move to target position. Where am i mistake? Site

private void MoveOneVertex(Polyline3d poly3d, Point3d old_pozition, Point3d new_pozition)
        {
            Document doc = AuAcApSerApp.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   edt = doc.Editor;           

            using (var trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    //Sorting through all vertexes of polyline
                    ObjectId[] verts = poly3d.Cast<ObjectId>().ToArray();

                    for (int i = 0; i < verts.Length; i++)
                    {
                        PolylineVertex3d vertex = trans.GetObject(verts[i], OpenMode.ForWrite) as PolylineVertex3d;

                        if (vertex.Position == old_pozition)
                        {                           
                            vertex.Position = new_pozition; //moving vertex to new pozition                                                     
                        } 
                    }

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    edt.WriteMessage("\nError encountered " + ex.Message);
                    trans.Abort();
                }
            }           
        }

 

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

ВeekeeCZ
Consultant
Consultant

This should have been posted to the dedicated forum HERE 


0 Likes
Message 3 of 3

hosneyalaa
Advisor
Advisor

HI @imranhasmi54341 

TRY

 

 

private void MoveOneVertexAS(Polyline3d poly3d, Point3d old_pozition, Point3d new_pozition)
        {


            //Document doc = Application.DocumentManager.MdiActiveDocument;

            //Database db = doc.Database;

            //Editor ed = doc.Editor;

            Document doc = AuAcApSerApp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor edt = doc.Editor;

            using (var trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    //Sorting through all vertexes of polyline
                    ObjectId[] verts = poly3d.Cast<ObjectId>().ToArray();

                    for (int i = 0; i < verts.Length; i++)
                    {
                        PolylineVertex3d vertex = trans.GetObject(verts[i], OpenMode.ForWrite) as PolylineVertex3d;

                        if (vertex.Position == old_pozition)
                        {
                            vertex.Position = new_pozition; //moving vertex to new pozition  

                            poly3d.UpgradeOpen();

                            poly3d.RecordGraphicsModified(true);
                        }
                    }

                    trans.Commit();
                }
                catch (System.Exception ex)
                {
                    edt.WriteMessage("\nError encountered " + ex.Message);
                    trans.Abort();
                }
            }
        }

 

0 Likes