Hello mr mzakiralam,
Can you please help me. I want to assign Dtext or label to each polyline while drawing it or after drawing it. how can i do that. I know how to assign dtext to line.. but confused with polyline. Please help me. Please find the dwg attach herewith for reference.
code using to draw polyline is as below:
'get current document
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
'lock document as using modeless form
Using docLock As DocumentLock = doc.LockDocument
Using tx As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
'open model space for write
Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
'converte text value
Dim uWidth As Double = CDbl(TextBox1.Text)
Dim base As Double = CDbl(TextBox2.Text)
Dim tHeight As Double = CDbl(TextBox3.Text)
Dim Xx As Double = ((base - uWidth) / 2)
' Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt2 As Point2d = New Point2d(base, 0)
Dim pt3 As Point2d = New Point2d(base - Xx, tHeight)
Dim pt4 As Point2d = New Point2d(0, 0)
Dim pt5 As Point2d = New Point2d(0 + Xx, tHeight)
Dim pt6 As Point2d = New Point2d(base, 0)
Dim tra As Polyline = New Polyline()
tra.AddVertexAt(0, pt1, 0, 0, 0)
tra.AddVertexAt(1, pt2, 0, 0, 0)
tra.AddVertexAt(2, pt3, 0, 0, 0)
tra.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 0, 0, 0)
tra.AddVertexAt(5, pt6, 0, 0, 0)
tra.Closed = True
'add triangle in model space
Dim line1 As Line = New Line(New Point3d(pt5.X, pt5.Y, 0), New Point3d(pt3.X, pt3.Y, 0))
thank you... I had already open a new tread but didnot get any solution from last 2 days so replied here.
link to new thread is as below:
yes they are connecting polylines. with reference to your code i am able to draw complete tower.
no i want to label each line. within it.
Okay, I got your point now. As you know how to draw text for a line so it will be easier for you now. What you need to do just cast the polyline then you will be able to get all vertices of that polyline. If you get all vertex then I think your problem will be solved. Please see below code snippet which will help you to get the polyline and its vertices.
<CommandMethod("tst")> Public Sub TestPoly() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database Dim ed As Editor = doc.Editor Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Select a polyline to label it:") Dim per As PromptEntityResult = ed.GetEntity(peo) Using tx As Transaction = db.TransactionManager.StartTransaction() Dim ent As Entity = tx.GetObject(per.ObjectId, OpenMode.ForRead) If TypeOf ent Is Polyline Then Dim pl As Polyline = TryCast(ent, Polyline) Dim vn As Integer = pl.NumberOfVertices For i = 0 To vn - 2 'get adjacent vertices of a polyline Dim pt1 As Point2d = pl.GetPoint2dAt(i) Dim pt2 As Point2d = pl.GetPoint2dAt(i + 1) 'do what you need Next End If tx.Commit() End Using End Sub
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.