<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Assign nomenclature to each polyline. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880628#M45108</link>
    <description>How can i add label to each vertex. i want to label each line so i think to go with previous method. can i change possition of label if assign to vertex</description>
    <pubDate>Wed, 12 Mar 2014 10:35:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-03-12T10:35:47Z</dc:date>
    <item>
      <title>Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4874426#M45103</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to assign nomenclature to each polyline while drawing it. Nomenclature can vary. I know how to label line with dtext. but confused with polyine.&lt;/P&gt;&lt;P&gt;please Find Attach dwg for better understanding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code using to draw polyline is as below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'get current document&lt;BR /&gt;Dim doc As Document = Application.DocumentManager.MdiActiveDocument&lt;BR /&gt;Dim db As Database = doc.Database&lt;BR /&gt;'lock document as using modeless form&lt;BR /&gt;Using docLock As DocumentLock = doc.LockDocument&lt;BR /&gt;Using tx As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;'open blocktable&lt;BR /&gt;Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)&lt;BR /&gt;'open model space for write&lt;BR /&gt;Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)&lt;BR /&gt;'converte text value&lt;BR /&gt;Dim uWidth As Double = CDbl(TextBox1.Text)&lt;BR /&gt;Dim base As Double = CDbl(TextBox2.Text)&lt;BR /&gt;Dim tHeight As Double = CDbl(TextBox3.Text)&lt;BR /&gt;Dim Xx As Double = ((base - uWidth) / 2)&lt;BR /&gt;' Dim pt1 As Point2d = New Point2d(0, 0)&lt;BR /&gt;Dim pt1 As Point2d = New Point2d(0, 0)&lt;BR /&gt;Dim pt2 As Point2d = New Point2d(base / 2, tHeight)&lt;BR /&gt;Dim pt3 As Point2d = New Point2d(base, 0)&lt;BR /&gt;Dim pt4 As Point2d = New Point2d(base - Xx, tHeight)&lt;BR /&gt;Dim pt5 As Point2d = New Point2d(0 + Xx, tHeight)&lt;/P&gt;&lt;P&gt;'draw traiangle&lt;BR /&gt;Dim tra As Polyline = New Polyline()&lt;BR /&gt;tra.AddVertexAt(0, pt1, 0, 0, 0)&lt;/P&gt;&lt;P&gt;'wanna label here&lt;/P&gt;&lt;P&gt;?????&lt;BR /&gt;tra.AddVertexAt(1, pt2, 0, 0, 0)&lt;BR /&gt;tra.AddVertexAt(2, pt3, 0, 0, 0)&lt;BR /&gt;tra.AddVertexAt(3, pt4, 0, 0, 0)&lt;BR /&gt;tra.AddVertexAt(4, pt5, 0, 0, 0)&lt;BR /&gt;tra.AddVertexAt(5, pt1, 0, 0, 0)&lt;BR /&gt;tra.AddVertexAt(6, pt3, 0, 0, 0)&lt;BR /&gt;tra.Closed = True&lt;BR /&gt;'add triangle in model space&lt;BR /&gt;ms.AppendEntity(tra)&lt;BR /&gt;tx.AddNewlyCreatedDBObject(tra, True)&lt;/P&gt;&lt;P&gt;tx.Commit()&lt;BR /&gt;End Using&lt;BR /&gt;End Using&lt;/P&gt;</description>
      <pubDate>Mon, 10 Mar 2014 08:05:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4874426#M45103</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-10T08:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880520#M45104</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;with below code iam able to assign label to line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;public static Point3d PolarPoint(Point3d basepoint, double angle, double distance)&lt;BR /&gt;{&lt;BR /&gt;return new Point3d(&lt;BR /&gt;basepoint.X + (distance * Math.Cos(angle)),&lt;BR /&gt;basepoint.Y + (distance * Math.Sin(angle)),&lt;BR /&gt;basepoint.Z);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//labeling&lt;BR /&gt;Matrix3d mtx = ed.CurrentUserCoordinateSystem;&lt;BR /&gt;Point3d mp = acLine.GetPointAtParameter(acLine.EndParam / 2).TransformBy(mtx);&lt;BR /&gt;double ang = acLine.Angle;&lt;/P&gt;&lt;P&gt;if ((ang &amp;gt; Math.PI / 2) &amp;amp;&amp;amp; (ang &amp;lt; Math.PI * 1.5))&lt;BR /&gt;{&lt;BR /&gt;ang = ang + Math.PI;&lt;BR /&gt;}&lt;BR /&gt;Point3d tp = PolarPoint(mp, ang + Math.PI / 2, ((db.Textsize) + 100)).TransformBy(mtx);&lt;BR /&gt;DBText dtext = new DBText();&lt;BR /&gt;dtext.SetDatabaseDefaults();&lt;BR /&gt;dtext.TextString = string.Format("{0:f" + db.Dimdec.ToString() + "}", acLine.Length);&lt;BR /&gt;//&amp;lt;---change text string to your needs&lt;BR /&gt;dtext.Position = tp;&lt;BR /&gt;dtext.Height = 120;&lt;BR /&gt;dtext.HorizontalMode = TextHorizontalMode.TextMid;&lt;BR /&gt;dtext.VerticalMode = TextVerticalMode.TextBottom;&lt;BR /&gt;dtext.Rotation = ang;&lt;BR /&gt;dtext.AlignmentPoint = tp;&lt;BR /&gt;dtext.AdjustAlignment(db);&lt;BR /&gt;BlockTableRecord btr = (BlockTableRecord)tx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);&lt;BR /&gt;btr.AppendEntity(dtext);&lt;BR /&gt;tx.AddNewlyCreatedDBObject(dtext, true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now i want to label polyline issue it is single plyline.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 09:53:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880520#M45104</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T09:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880526#M45105</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; &amp;lt;CommandMethod("tst")&amp;gt; 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 &amp;amp; "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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 09:43:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880526#M45105</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T09:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880550#M45106</link>
      <description>is it possible to explode Polyline and treat each line as input for above code</description>
      <pubDate>Wed, 12 Mar 2014 09:54:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880550#M45106</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T09:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880574#M45107</link>
      <description>&lt;P&gt;if you want to explode a entity , you can have a look on below link:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2011/02/exploding-autocad-objects-using-net.html" target="_blank"&gt;http://through-the-interface.typepad.com/through_the_interface/2011/02/exploding-autocad-objects-using-net.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I would not recommend you to do so. But I do not understand, if you have a vertex why don't you add a label around there?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 10:02:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880574#M45107</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T10:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880628#M45108</link>
      <description>How can i add label to each vertex. i want to label each line so i think to go with previous method. can i change possition of label if assign to vertex</description>
      <pubDate>Wed, 12 Mar 2014 10:35:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880628#M45108</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T10:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880796#M45109</link>
      <description>&lt;P&gt;please try this code. I did a trick. I create a temporary line to get its angle. but did not add it to model space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; &amp;lt;CommandMethod("tst")&amp;gt; Public Sub TestPolyline()
        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("Select a polyline:")
        Dim per As PromptEntityResult = ed.GetEntity(peo)
        If per.Status &amp;lt;&amp;gt; PromptStatus.OK Then
            Return
        End If
        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
                    Dim pt1 As Point2d = pl.GetPoint2dAt(i)
                    Dim pt2 As Point2d = pl.GetPoint2dAt(i + 1)
                    Dim ln As Line = New Line(New Point3d(pt1.X, pt1.Y, 0), New Point3d(pt2.X, pt2.Y, 0))
                    Dim ang As Double = ln.Angle
                    Dim dtxt As DBText = New DBText()
                    dtxt.Position = New Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, 0)
                    dtxt.Height = 2.5
                    dtxt.TextString = "label" &amp;amp; i
                    dtxt.Rotation = ang

                    Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
                    Dim btr As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                    btr.AppendEntity(dtxt)
                    tx.AddNewlyCreatedDBObject(dtxt, True)
                Next
            End If
            tx.Commit()
        End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 11:57:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880796#M45109</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T11:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880950#M45110</link>
      <description>Thank you .its working for my requirement well. But now issue is i want to do this for all poly-lines without selection from user. Is it possible ?</description>
      <pubDate>Wed, 12 Mar 2014 12:58:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4880950#M45110</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T12:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4881114#M45111</link>
      <description>&lt;P&gt;HI , it is possible. Just see my code. In one place I had to cast the polyline from selection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim pl As Polyline = TryCast(ent, Polyline)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your case, when you create a polyline, just use that polyline to get all that vertices which I did later. Please see my below code, where I will create a polyline and later add laber for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; &amp;lt;CommandMethod("tst")&amp;gt; Public Sub TestPoly()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
       
        Using tx As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
            Dim btr As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
            'add polyline
            Dim pl As Polyline = New Polyline()
            pl.AddVertexAt(0, New Point2d(0, 0), 0, 0, 0)
            pl.AddVertexAt(1, New Point2d(5, 0), 0, 0, 0)
            pl.AddVertexAt(2, New Point2d(5, 5), 0, 0, 0)
            pl.AddVertexAt(3, New Point2d(0, 0), 0, 0, 0)
            btr.AppendEntity(pl)
            tx.AddNewlyCreatedDBObject(pl, True)
            'add label for that polyline
            Dim vn As Integer = pl.NumberOfVertices
            For i = 0 To vn - 2
                Dim pt1 As Point2d = pl.GetPoint2dAt(i)
                Dim pt2 As Point2d = pl.GetPoint2dAt(i + 1)
                Dim ln As Line = New Line(New Point3d(pt1.X, pt1.Y, 0), New Point3d(pt2.X, pt2.Y, 0))
                Dim ang As Double = ln.Angle
                Dim dtxt As DBText = New DBText()
                dtxt.Position = New Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, 0)
                dtxt.Height = 0.1
                dtxt.TextString = "label" &amp;amp; i
                dtxt.Rotation = ang
                btr.AppendEntity(dtxt)
                tx.AddNewlyCreatedDBObject(dtxt, True)
            Next
            tx.Commit()
        End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 13:55:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4881114#M45111</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T13:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Assign nomenclature to each polyline.</title>
      <link>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4882870#M45112</link>
      <description>&lt;P&gt;Thank you so much... its what exactly i want... Your code always help me... Thank you once again.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2014 04:48:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/assign-nomenclature-to-each-polyline/m-p/4882870#M45112</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-13T04:48:02Z</dc:date>
    </item>
  </channel>
</rss>

