.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add Polyline and other entities

5 REPLIES 5
Reply
Message 1 of 6
dungtdc
1315 Views, 5 Replies

Add Polyline and other entities

Because, to add an entity to ModelSpace by .Net we have to use some line of code so I've created a sub to add entity to Modelspace. Text, Circle, Point... is OK, but I don't know the ways to add a Polyline, 3D polyline to. I was create by add polyline with specify number of vertices like this: Dim Pl as polyline = New Polyline(Nums) and use methods AddVertexAt to add vertex step by step. I think it is very slowly. It is not same in VBA, you only use: Thisdrawing.modelspace.addPolyline(ArrofVertex) or Thisdrawing.modelspace.add3DPolyline(ArrofVertex) or Thisdrawing.modelspace.addLWPolyline(ArrofVertex). Could you help me the way to do this task. Please attack some code. Many thanks.
Oh, why the example codes that was posted in the forum are not format. Is there an error of forum
5 REPLIES 5
Message 2 of 6
chiefbraincloud
in reply to: dungtdc

If you use the Polyline2D or Polyline3D type instead of Polyline, you can pass Point3D collections to the New constructor.

The attached file has two Subs, with a few comments, one for a 2d polyline with filleted corners, the other a 3d polyline.

The bulges for filleting 2d polylines can be a little tricky if you haven't used them before. The following is quoted from the ObjectARX Developer help.

"The bulge is the tangent of 1/4 of the included angle for the arc between the selected vertex and the next vertex in the polyline's vertex list. A negative bulge value indicates that the arc goes clockwise from the selected vertex to the next vertex. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle." Also, to pass the bulges, it has to be Poly2dType.SimplePoly
Dave O.                                                                  Sig-Logos32.png
Message 3 of 6
dungtdc
in reply to: dungtdc

How about polyline. I wrote some code like this:

Public Sub AddPoly()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor()
Dim pl As Polyline
Dim DB As Database = HostApplicationServices.WorkingDatabase()
Dim Trans As Transaction = DB.TransactionManager.StartTransaction()
pl = New Polyline(3)
pl.AddVertexAt(0, New Point2d(0, 0), 0, -1, -1)
pl.AddVertexAt(1, New Point2d(10, 10), 0, -1, -1)
pl.AddVertexAt(2, New Point2d(50, 20), 0, -1, -1)
Try
Dim Bt As BlockTable = Trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
Dim Btr As BlockTableRecord = Trans.GetObject(Bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Btr.AppendEntity(pl)
Trans.AddNewlyCreatedDBObject(pl, True)
Trans.Commit()
Catch
MsgBox("Error Adding Entities")
Finally
Trans.Dispose()
End Try
End If
End Sub

any Comment or other better way to do this.
I have a polyline with hundred of vertex like the contour in a map. Do I use a for...next to add its step by step?.
for example in this case: I have an array like this: arrvertex with value:(0,0,10,10,50,20...). Oh! I think it is slower than VBA. In VBA we do:

Thisdrawing.Modelspace.addlwpolyline(arrvertex)

and all is done.
Do you think so? Edited by: dungtdc on Oct 23, 2008 8:32 PM
Message 4 of 6
Anonymous
in reply to: dungtdc


You're speculating without realizing that what the
AddLWPolyline()

ActiveX method is doing behind the scenes,
is exactly the same

thing your code does.

 

ActiveX uses ObjectARX to do the work, so when you call
the

AddLWPolyline() method, it essentially must do the same
thing

you show in your code.

 

ObjectARX is much faster than ActiveX, so there really isn't
any

faster way to do this (other than via P/Invoking
acedEntMake(),

which might have an advantage in this case, but I can't
tell you

for sure since I've never tested it).


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
How
about polyline. I wrote some code like this:

Public Sub
AddPoly()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor()
Dim pl As
Polyline
Dim DB As Database =
HostApplicationServices.WorkingDatabase()
Dim Trans As Transaction =
DB.TransactionManager.StartTransaction()
pl = New
Polyline(3)
pl.AddVertexAt(0, New Point2d(0, 0), 0, -1,
-1)
pl.AddVertexAt(1, New Point2d(10, 10), 0, -1, -1)
pl.AddVertexAt(2,
New Point2d(50, 20), 0, -1, -1)
Try
Dim Bt As BlockTable =
Trans.GetObject(DB.BlockTableId, OpenMode.ForRead)
Dim Btr As
BlockTableRecord = Trans.GetObject(Bt(BlockTableRecord.ModelSpace),
OpenMode.ForWrite)
Btr.AppendEntity(pl)
Trans.AddNewlyCreatedDBObject(pl,
True)
Trans.Commit()
Catch
MsgBox("Error Adding
Entities")
Finally
Trans.Dispose()
End Try
End If
End
Sub

any Comment or other better way to do this.
I have a polyline
with hundred of vertex like the contour in a map. Do I use a for...next to add
its step by step?.
for example in this case: I have an array like this:
arrvertex with value:(0,0,10,10,50,20...). Oh! I think it is slower than VBA.
In VBA we
do:

Thisdrawing.Modelspace.addlwpolyline(arrvertex)

and all is
done.
Do you think so? Edited by: dungtdc on Oct 23, 2008 8:32
PM
Message 5 of 6
dungtdc
in reply to: dungtdc

Many thanks for your answers
Message 6 of 6
asmaa_
in reply to: dungtdc

je veux ajouter des points 3D au début ou a la fin d'un polyline qui existe déjà :

PromptEntityOptions poly=new PromptEntityOptions(" Select a polyline ");
PromptEntityResult per = ed.GetEntity(poly);
DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForWrite);
Polyline lwp = obj as Polyline;

..................

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost