当曲线类为';不需要
通过一点误差控制,这应该可以让你达到目的
- Option Explicit
- Const pi As Double = 3.14159265358979
- Sub DividePoly()
-
- Dim Ent As AcadEntity
- Dim oPline As AcadLWPolyline
- Dim cnt As Integer, CCnt As Integer
- Dim Dist As Double, Tan As Double
- Dim dLength As Double
- Dim div As Integer
- Dim unitL As Double
- Dim i As Integer, j As Integer, K As Integer
- Dim C1, C2, p
- Dim C(5) As Variant
- Dim dBulge As Double, Ang As Double
- Dim Total As Double
- Dim CoordCol As New Collection
- Dim Elev As Double
- Dim bBlock As Boolean
- Dim oBref As AcadBlockReference
- Dim sBlock As String
- Dim Util As AcadUtility
-
- Set Util = ThisDrawing.Utility
- 'Set Ent = EntSel("Select a pline to divide:")
- Util.GetEntity Ent, p, "Select a pline to divide:"
- If TypeOf Ent Is AcadLWPolyline Then
- Set oPline = Ent
- Else
- MsgBox ("Must be a pline.")
- Exit Sub
- End If
-
- On Error Resume Next
- Dim keywordList As String
- keywordList = "Block"
- Util.InitializeUserInput 128, keywordList
- Dim Answer As String
- div = Util.GetInteger(vbCr & "Enter the number of segments or [Block]: ")
- If Err Then
- If StrComp(Err.Description, "User input is a keyword", 1) = 0 Then
- Err.Clear
- Answer = ThisDrawing.Utility.GetInput
- If Answer = "Block" Then
- bBlock = True
- sBlock = Util.GetString(False, "Enter name of block to insert:")
- If sBlock = "" Then Exit Sub
- Dim oBlock As AcadBlock
- Set oBlock = ThisDrawing.Blocks(sBlock)
- If Err.Description = "Key not found" Then
- Exit Sub
- Else
- div = Util.GetInteger(vbCr & "Enter the number of segments : ")
-
- End If
- Else: Exit Sub
- End If
- End If
- End If
- On Error GoTo 0
-
-
-
- If Not div > 1 Then Exit Sub
- unitL = oPline.Length / div
- Elev = oPline.Elevation
- cnt = (UBound(oPline.Coordinates) - 1) / 2
- If oPline.Closed = True Then
- CCnt = cnt + 1
- Else
- CCnt = cnt
- End If
-
- For i = 0 To CCnt - 1
- C1 = oPline.Coordinate(i)
- If i = cnt Then
- C2 = oPline.Coordinate(0)
- Else
- C2 = oPline.Coordinate(i + 1)
- End If
- C(0) = C1: C(1) = C2
- dLength = segLength(C1, C2)
- C(5) = dLength
- dBulge = oPline.GetBulge(i)
- C(3) = dBulge
- If dBulge 0 Then
- 'converting bulge to angle in radians ang=Atn(dBulge) * 4
- Ang = Atn(dBulge) * 2
- dLength = Ang * dLength / Sin(Ang)
- C(4) = dLength
- End If
- Total = Total + dLength
- C(2) = Total
- CoordCol.Add C
- Next i
-
- dLength = 0
- K = 1
- For i = 1 To div - 1
- dLength = dLength + unitL
- For j = K To CCnt
- If CoordCol(j)(2) >= dLength Then
- Exit For
- End If
- Next j
- If j > 1 Then
- K = j - 1
- Dist = dLength - CoordCol(K)(2)
- Else
- K = j
- Dist = dLength
- End If
- dBulge = CoordCol(j)(3)
- If dBulge = 0 Then
- p = PtonLine(CoordCol(j)(0), CoordCol(j)(1), Dist, Tan)
- Else
- p = PtonArc(CoordCol(j), Dist, Tan)
|