.NET

## .NET

Valued Contributor
Posts: 53
Registered: ‎07-18-2005
Message 1 of 6 (141 Views)

# Define a polyline.

141 Views, 5 Replies
08-23-2005 08:30 AM
I have three point3d objects defined as follows:

Dim corner1 As New Point3d(0, 0, 0)
Dim corner2 As New Point3d(10, 0, 0)
Dim corner3 As New Point3d(10, 10, 0)

I have been looking at the following line out of a sample program that defines a circle:

Dim center As New Point3d(10, 10, 0)

My question is what code do I need to add to my program similar to the line above that will connect my three point3d objects with a polyline.

Thank you,
Eric Sepich
Valued Contributor
Posts: 53
Registered: ‎07-18-2005
Message 2 of 6 (141 Views)

# Re: Define a polyline.

08-23-2005 08:30 AM in reply to: sepich4567
Addendum:

Circle code was actually

Dim circle As Circle = New Circle(center, Vector3d.ZAxis, 2.0)
*Mike Tuersley
Message 3 of 6 (141 Views)

# Re: Define a polyline.

08-23-2005 09:41 AM in reply to: sepich4567
You need to determine whether you are going to draw a PolyLine or a
LWPolyLine. Both require a point list with the LWP requiring it to be only
2D points. So assuming you want an open LWPline, it'd look something like:

Dim corner1 As New Point3d(0, 0, 0)
Dim corner2 As New Point3d(10, 0, 0)
Dim corner3 As New Point3d(10, 10, 0)
Dim dPtList(6) As Double
dPtList(0) = corner1.X
dPtList(1) = corner1.Y
dPtList(2) = corner2.X
dPtList(3) = corner2.Y
dPtList(4) = corner3.X
dPtList(5) = corner3.Y

then create your lwpolyline passing the dPtList as the point list

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
Valued Contributor
Posts: 53
Registered: ‎07-18-2005
Message 4 of 6 (141 Views)

# Re: Define a polyline.

08-23-2005 09:49 AM in reply to: sepich4567
I have searched the ObjectARX reference manual for "LWPolyline" and have not found anything. Can anyone tell me where this thing is defined and how to use it properly?
*Mike Tuersley
Message 5 of 6 (141 Views)

# Re: Define a polyline.

08-23-2005 01:12 PM in reply to: sepich4567
try Autodesk.AutoCAD.DatabaseServices.Polyline2d - LWPolylIne is an AutoCAD
and COM term

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
Distinguished Contributor
Posts: 352
Registered: ‎12-05-2003
Message 6 of 6 (141 Views)

# Re: Define a polyline.

09-29-2005 08:05 AM in reply to: sepich4567
Hi Mike:
I am working on a function to draw a box in LWPolyline in C#. Now everything looks OK but the rectangle does not show up in the drawing. Please see code below:

public static Entity DrawBox(Point2d pt, double Width, double Height, BlockTableRecord btr)
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();

Polyline plBox;
try
{
plBox = new Polyline(4);
plBox.AddVertexAt (0, pt, 0,0,0);
plBox.AddVertexAt (1, new Point2d(pt.X+Width, pt.Y),0,0,0);
plBox.AddVertexAt (2, new Point2d(pt.X+Width,pt.Y+Height),0,0,0);
plBox.AddVertexAt (3, new Point2d(pt.X,pt.Y+Height),0,0,0);
plBox.Closed = true;

btr.AppendEntity(plBox);
trans.AddNewlyCreatedDBObject(plBox,true);
trans.Commit();
}
finally
{
trans.Dispose();
}

return plBox;
}

//// Here is the code to test it
[CommandMethod("DrawBox_TEST")]
public static void DrawBox_Test()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Transaction trans = db.TransactionManager.StartTransaction();

BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
PromptPointOptions prPtOpts = new PromptPointOptions("Please pick a point:");

PromptPointResult prPtRes = ed.GetPoint(prPtOpts);

if (prPtRes.Status != PromptStatus.OK )
return;

Point3d pt1 = prPtRes.Value;
Point2d pt = new Point2d(pt1.X, pt1.Y);

Entity ent = AutoCADLib.DrawBox(pt,100,50,btr);
if (ent != null)
ed.WriteMessage("{0}",ent.GetType().Name);
else
ed.WriteMessage("No Box Drawed.");
}
do you what's wrong is there? Thank you.

Also, I found in AutoCAD .Net help,
"AcDbPolyline is often called a lightweight polyline because of its efficient use of memory. AcDbPolyline provides greater performance and reduced overhead compared to AcDb2dPolyline"

I kind of confused:
the LWPolyline in AutoCAD is AcDbPolyline
old style Polyline is AcDB2dPolyline. Which is correct?

Wes
Post to the Community

Have questions about Autodesk products? Ask the community.

Download & Installation
Subscription Management
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!