.NET

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

How to set Polyline.StartPoint ?

405 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 (403 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 (381 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 (372 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
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.