.NET

Reply
Distinguished Contributor
wesbird
Posts: 359
Registered: ‎12-05-2003
Message 1 of 5 (261 Views)

How to offset pline?

261 Views, 4 Replies
09-22-2005 11:23 AM
Hi
I am new of .net. In VBA, RT = oPl.Offset(dist) will return the offset result of oPl. How do I do it in .net?
I want get the offset polyline point list. I found this in ObjectARX help file, AcGeOffsetCurve2d class. Am I on the right track? is there any sample about it?


Thank you
Wes
Vault Pro 2014, Windows 7 64 bit, AutoCAD (ACA, Map) 2014
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 2 of 5 (261 Views)

Re: How to offset pline?

09-22-2005 01:23 PM in reply to: wesbird
Best would be to use the Autodesk.AutoCAD.Geometry.OffsetCurve2d method If you want to stay with dot net. This is the same as the AcGeOffsetCurve2d class.

You can also do it with COM interop with the
Autodesk.AutoCAD.Interop.Common.IAcadPolyline.Offset method. This is the same as VBA.

Chris Arps
Distinguished Contributor
wesbird
Posts: 359
Registered: ‎12-05-2003
Message 3 of 5 (261 Views)

Re: How to offset pline?

09-22-2005 02:19 PM in reply to: wesbird
Thank you.
when I working in the code, I found I have problem to create a object as Curve2d. Could you what's wrong in my code? Thank you very much.

here is the code:
using System ;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

[assembly: CommandClass(typeof(ClassLibrary.RSClass))]

namespace ClassLibrary
{
///
/// Summary description for RSClass.
///

public class RSClass
{

// Define Command "AsdkCmd1"
[CommandMethod("OffsetEnt")]
static public void test() // This method can have any name
{
// Put your command code here
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Transaction trans = db.TransactionManager.StartTransaction();

try
{
PromptEntityOptions prEnt = new PromptEntityOptions("Select a polyline:");
PromptEntityResult prEntRes = ed.GetEntity(prEnt);

if (prEntRes.Status != PromptStatus.OK )
{
return;
}
ObjectId id = prEntRes.ObjectId;
Entity opl = (Entity)trans.GetObject(id,OpenMode.ForWrite,true);
Curve2d cvPl = (Curve2d)opl; // <<<--- here is my problem.
OffsetCurve2d oOff = new OffsetCurve2d(cvPl, 2);
}
finally
{
}
}

}
} Message was edited by: weslleywang
Vault Pro 2014, Windows 7 64 bit, AutoCAD (ACA, Map) 2014
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 4 of 5 (261 Views)

Re: How to offset pline?

09-23-2005 06:41 AM in reply to: wesbird
I tried using the curve2d class until I saw the methods on the polyline object itself. It is probably not as efficient as getting the AcGe objects to work, but this code does work.

Notice the transaction manager code, you must commit your modifications when done, you must abort if an exception is done, and it is good to call dispose in the finally clause to clean up.

Excuse the vb.net reply, you can always translate it online.


Try
Dim prEnt As New PromptEntityOptions("Select a polyline:")
Dim prEntRes As PromptEntityResult = editor.GetEntity(prEnt)
If prEntRes.Status <> PromptStatus.OK Then Return

Dim id As ObjectId = prEntRes.ObjectId
' get input polyline
Dim ent As Entity = DirectCast(trans.GetObject(id, OpenMode.ForRead), Entity)
Dim pl As Polyline = DirectCast(ent, Polyline)

Dim curves As DBObjectCollection = pl.GetOffsetCurves(2.0)
Dim i As Integer
Dim s As String
For i = 0 To curves.Count - 1
Dim newPl As Polyline = DirectCast(curves.Item(i), Polyline)
Dim isNew As Boolean = newPl.IsNewObject
Dim numSegs As Integer = newPl.NumberOfVertices
If newPl.Closed = False Then numSegs -= 1
Dim j As Integer
For j = 0 To numSegs - 1
Dim segType As SegmentType = newPl.GetSegmentType(j)
If segType = SegmentType.Line Then
Dim seg2 As LineSegment2d
Dim seg3 As LineSegment3d
seg2 = newPl.GetLineSegment2dAt(j)
seg3 = newPl.GetLineSegmentAt(j)
ElseIf segType = SegmentType.Arc Then
Dim a2 As CircularArc2d = newPl.GetArcSegment2dAt(j)
Dim a3 As CircularArc3d = newPl.GetArcSegmentAt(j)
End If
Next
Next
curves.Dispose()
trans.Commit()
Catch ex As Exception
trans.Abort()
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
Distinguished Contributor
wesbird
Posts: 359
Registered: ‎12-05-2003
Message 5 of 5 (261 Views)

Re: How to offset pline?

09-23-2005 07:39 AM in reply to: wesbird
Thank you very much. it works like a clock.



Wes
Vault Pro 2014, Windows 7 64 bit, AutoCAD (ACA, Map) 2014
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.