.NET

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

How to offset pline?

245 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
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 2 of 5 (245 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: 349
Registered: ‎12-05-2003
Message 3 of 5 (245 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
Distinguished Contributor
ChrisArps
Posts: 311
Registered: ‎07-29-2004
Message 4 of 5 (245 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: 349
Registered: ‎12-05-2003
Message 5 of 5 (245 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community