Jump to content

Add Dimensions to Polyline in VBA


Andresig

Recommended Posts

I started a routine to add dimensions to polyline...

 

The problem is that is created over the line and I want to create it separated from the line, If some one can help me with this will be awesome...

 

thanks,

 

Sub add_dim_polyline()
   'to add Panel Dimensions
   Dim ThePolyline As AcadLWPolyline
   Dim polyCoords As Variant
   Dim getPoint As Variant
   Dim a As Integer
   Dim polyCoordBound As Integer
   Dim stPoint(2) As Double
   Dim ePoint(2) As Double
   Dim sectionAngle As Double
   Dim textCoords As Variant
   Dim polyDist As Double
   Dim x1, x2, y1, y2 As Double
   Dim objDimAligned As AcadDimAligned
   ThisDrawing.Utility.GetEntity ThePolyline, getPoint, "Select an object"
   polyCoords = ThePolyline.Coordinates
   polyCoordBound = UBound(polyCoords)



   For a = 0 To polyCoordBound - 1 Step 2
       If a = polyCoordBound - 1 Then
           stPoint(0) = polyCoords(a)
           stPoint(1) = polyCoords(a + 1)
           stPoint(2) = 0
           ePoint(0) = polyCoords(0)
           ePoint(1) = polyCoords(1)
           ePoint(2) = 0
       Else
           stPoint(0) = polyCoords(a)
           stPoint(1) = polyCoords(a + 1)
           stPoint(2) = 0
           ePoint(0) = polyCoords(a + 2)
           ePoint(1) = polyCoords(a + 3)
           ePoint(2) = 0

       End If
       x1 = stPoint(0): x2 = ePoint(0)
       y1 = stPoint(1): y2 = ePoint(1)
       polyDist = Sqr(((x1 - x2) ^ 2) + ((y1 - y2) ^ 2))
       sectionAngle = ThisDrawing.Utility.AngleFromXAxis(stPoint, ePoint)
       textCoords = ThisDrawing.Utility.PolarPoint(stPoint, sectionAngle, polyDist / 2)
       Set objDimAligned = ThisDrawing.ModelSpace.AddDimAligned(stPoint, ePoint, textCoords)

   Next a
End Sub

Link to comment
Share on other sites

Perhaps something like the addition shown here.

 

sectionAngle = ThisDrawing.Utility.AngleFromXAxis(stPoint, ePoint)
textCoords = ThisDrawing.Utility.PolarPoint(stPoint, sectionAngle, polyDist / 2)
textCoords = ThisDrawing.Utility.PolarPoint(textCoords, sectionAngle + 1.57, 1#) 'Rotate PI/2
Set objDimAligned = ThisDrawing.ModelSpace.AddDimAligned(stPoint, ePoint, textCoords)

Link to comment
Share on other sites

Sub add_dim_polyline()
   'to add Panel Dimensions
   Dim ThePolyline As AcadLWPolyline
   Dim polyCoords As Variant
   Dim getPoint As Variant
   Dim a As Integer
   Dim polyCoordBound As Integer
   Dim stPoint(2) As Double
   Dim ePoint(2) As Double
   Dim sectionAngle As Double
   Dim textCoords As Variant
   Dim polyDist As Double
   Dim x1, x2, y1, y2 As Double
   Dim objDimAligned As AcadDimAligned
   Dim textAngle As Double
   ThisDrawing.Utility.GetEntity ThePolyline, getPoint, "Select an object"
   polyCoords = ThePolyline.Coordinates
   polyCoordBound = UBound(polyCoords)



   For a = 0 To polyCoordBound - 2 Step 2
       stPoint(0) = polyCoords(a)
       stPoint(1) = polyCoords(a + 1)
       stPoint(2) = 0
       ePoint(0) = polyCoords(a + 2)
       ePoint(1) = polyCoords(a + 3)
       ePoint(2) = 0

       x1 = stPoint(0): x2 = ePoint(0)
       y1 = stPoint(1): y2 = ePoint(1)
       polyDist = Sqr(((x1 - x2) ^ 2) + ((y1 - y2) ^ 2))
       sectionAngle = ThisDrawing.Utility.AngleFromXAxis(stPoint, ePoint)
       textAngle = sectionAngle + 1.57
       textCoords = ThisDrawing.Utility.PolarPoint(stPoint, sectionAngle + 1.57, 1#)
       Set objDimAligned = ThisDrawing.ModelSpace.AddDimAligned(stPoint, ePoint, textCoords)

   Next a
End Sub

Link to comment
Share on other sites

Heyy, I just saw this post, can someone of you tell me what is this VBA about?? When drawing polyline it shows and writes distance up to line or..??

Link to comment
Share on other sites

Sounds good, I have something similiar lisp, you select polyline and it puts dimension on it (between two dots on pline, and so on along line), how you use VBA?? never done that so I'm curious...in few words if you have time to write how to start it..o:)

Link to comment
Share on other sites

Sounds good, I have something similiar lisp, you select polyline and it puts dimension on it (between two dots on pline, and so on along line), how you use VBA?? never done that so I'm curious...in few words if you have time to write how to start it..o:)

 

I'm still not permitted to stamp addresses but google "autocad vba" and will appear some hyperpics dot com page with an introduction of vba

Link to comment
Share on other sites

I'm still not permitted to stamp addresses but google "autocad vba" and will appear some hyperpics dot com page with an introduction of vba

 

Ok, understand...Thx man!!!:D

Link to comment
Share on other sites

  • 4 years later...
I started a routine to add dimensions to polyline...

 

The problem is that is created over the line and I want to create it separated from the line, If some one can help me with this will be awesome...

 

thanks,

 

Sub add_dim_polyline()
   'to add Panel Dimensions
   Dim ThePolyline As AcadLWPolyline
   Dim polyCoords As Variant
   Dim getPoint As Variant
   Dim a As Integer
   Dim polyCoordBound As Integer
   Dim stPoint(2) As Double
   Dim ePoint(2) As Double
   Dim sectionAngle As Double
   Dim textCoords As Variant
   Dim polyDist As Double
   Dim x1, x2, y1, y2 As Double
   Dim objDimAligned As AcadDimAligned
   ThisDrawing.Utility.GetEntity ThePolyline, getPoint, "Select an object"  <--???
   polyCoords = ThePolyline.Coordinates
   polyCoordBound = UBound(polyCoords)



   For a = 0 To polyCoordBound - 1 Step 2
       If a = polyCoordBound - 1 Then
           stPoint(0) = polyCoords(a)
           stPoint(1) = polyCoords(a + 1)
           stPoint(2) = 0
           ePoint(0) = polyCoords(0)
           ePoint(1) = polyCoords(1)
           ePoint(2) = 0
       Else
           stPoint(0) = polyCoords(a)
           stPoint(1) = polyCoords(a + 1)
           stPoint(2) = 0
           ePoint(0) = polyCoords(a + 2)
           ePoint(1) = polyCoords(a + 3)
           ePoint(2) = 0

       End If
       x1 = stPoint(0): x2 = ePoint(0)
       y1 = stPoint(1): y2 = ePoint(1)
       polyDist = Sqr(((x1 - x2) ^ 2) + ((y1 - y2) ^ 2))
       sectionAngle = ThisDrawing.Utility.AngleFromXAxis(stPoint, ePoint)
       textCoords = ThisDrawing.Utility.PolarPoint(stPoint, sectionAngle, polyDist / 2)
       Set objDimAligned = ThisDrawing.ModelSpace.AddDimAligned(stPoint, ePoint, textCoords)

   Next a
End Sub

this code can''t work,
Link to comment
Share on other sites

Welcome to the Forum, Iyant!

Can you be more specific, please? How you loaded/called the code? Did you got any error message? And last, but not least, in which version did you attempted to test it?

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...