.NET

Reply
Active Contributor
pva75
Posts: 48
Registered: ‎07-22-2012
Message 1 of 4 (398 Views)
Accepted Solution

How to set Polyline.StartPoint ?

398 Views, 3 Replies
08-12-2012 01:48 PM

I tried to set Polyline.StartPoint to new position (Point3d):

 

Polyline.StartPoint = myNewPoint3d;

 

I have "not implemented" exception.

 

Also, I tried to do it as:

 

var seg0 = acEnt.GetLineSegmentAt(0);

seg0.Set(newPoint3d(0, 0, 0), seg0.EndPoint);

 

It doesn't work also.

 

I can do it as:

 

acEnt.SetPointAt(0, my2dPoint);

 

But it's 2D point, not 3d

 

Of course I can remove polyline and create it again, but...

 

How to set start point correctly for 3d point?

 

Pavel

Here is a quick and dirty snip you will be use as framework,

change to your suit

 

 [CommandMethod("SPT")]
public void chageStartPoint()
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a segment where to add a vertex: ");
peo.SetRejectMessage("\nIncorrect entity");
peo.AllowNone = false;
peo.AllowObjectOnLockedLayer = false;
peo.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
ObjectId id = per.ObjectId;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Polyline pline = tr.GetObject(id, OpenMode.ForRead, false) as Polyline;
if (pline != null)
{
pline.UpgradeOpen();
Point3d pt = ed.GetPoint("\nPick new start point location: ").Value;
Point2d sp = pt.Convert2d(new Plane(Point3d.Origin, pline.Normal));
pline.AddVertexAt(0, sp, 0, pline.ConstantWidth, pline.ConstantWidth);
pline.RemoveVertexAt(1);
}
tr.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteMessage( ex.Message);
}
}
} 

 

~'J'~

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (396 Views)

Re: How to set Polyline.StartPoint ?

08-12-2012 02:16 PM in reply to: pva75

Here is a quick and dirty snip you will be use as framework,

change to your suit

 

   [CommandMethod("SPT")]  
        public void chageStartPoint()
        {
                PromptEntityOptions peo = new PromptEntityOptions("\nSelect a segment where to add a vertex: ");
            peo.SetRejectMessage("\nIncorrect entity"); 
            peo.AllowNone = false; 
            peo.AllowObjectOnLockedLayer = false;
            peo.AddAllowedClass(typeof(Polyline), true);
            PromptEntityResult per = ed.GetEntity(peo); 
            if (per.Status == PromptStatus.OK) 
            {
 
                ObjectId id = per.ObjectId; 
                try 
                { 
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    { 
                        Polyline pline = tr.GetObject(id, OpenMode.ForRead, false) as Polyline; 
                        if (pline != null)
                        {
                            pline.UpgradeOpen();
                            Point3d pt = ed.GetPoint("\nPick new start point location: ").Value;
                            Point2d sp = pt.Convert2d(new Plane(Point3d.Origin, pline.Normal));
                            pline.AddVertexAt(0, sp, 0, pline.ConstantWidth, pline.ConstantWidth);
                            pline.RemoveVertexAt(1);

                        }
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                
                    ed.WriteMessage( ex.Message);
                }
            }
        } 

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
pva75
Posts: 48
Registered: ‎07-22-2012
Message 3 of 4 (374 Views)

Re: How to set Polyline.StartPoint ?

08-12-2012 09:42 PM in reply to: Hallex

Thanks a lot! I think it will work for me.

 

Pavel.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 4 (365 Views)

Re: How to set Polyline.StartPoint ?

08-13-2012 12:55 AM in reply to: pva75

You need to extend this code

Add in there the part to work with different

coordinate system etc

You're welcome

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!