VBA将所有的直线转换成样条曲线
至于为什么我要这样转换,就不告诉你。仅仅是告诉你们你addSPLine的用法。
Sub LineToSPline() '直线转化为样条曲线
Dim E As AcadEntity
Dim L As AcadLine
Dim StartTan(0 To 2) As Double
Dim FitPoints(0 To 8) As Double
Dim CenterP As Variant
Dim A(0 To 2) As Double '拟合样条曲线的端点和终点的方向
Dim SP As AcadSpline
For Each E In ThisDrawing.ModelSpace
'ThisDrawing.Utility.Prompt L.ObjectName
If E.ObjectName = "AcDbLine" Then
Set L = E
CenterP = CenterPoint(L.StartPoint, L.EndPoint)
A(0) = L.StartPoint(0) - L.EndPoint(0)
A(1) = L.StartPoint(1) - L.EndPoint(1)
A(2) = L.StartPoint(1) - L.EndPoint(1)
FitPoints(0) = L.StartPoint(0): FitPoints(1) = L.StartPoint(1): FitPoints(2) = L.StartPoint(2)
FitPoints(3) = CenterP(0): FitPoints(4) = CenterP(1): FitPoints(5) = CenterP(2)
FitPoints(6) = L.EndPoint(0): FitPoints(7) = L.EndPoint(1): FitPoints(8) = L.EndPoint(2)
StartTan(0) = -A(0): StartTan(1) = -A(1): StartTan(2) = -A(2)
Set SP = ThisDrawing.ModelSpace.AddSpline(FitPoints, StartTan, StartTan)
SP.Layer = L.Layer
SP.color = L.color
L.Delete
End If
Next E
End Sub
Dim E As AcadEntity
Dim L As AcadLine
Dim StartTan(0 To 2) As Double
Dim FitPoints(0 To 8) As Double
Dim CenterP As Variant
Dim A(0 To 2) As Double '拟合样条曲线的端点和终点的方向
Dim SP As AcadSpline
For Each E In ThisDrawing.ModelSpace
'ThisDrawing.Utility.Prompt L.ObjectName
If E.ObjectName = "AcDbLine" Then
Set L = E
CenterP = CenterPoint(L.StartPoint, L.EndPoint)
A(0) = L.StartPoint(0) - L.EndPoint(0)
A(1) = L.StartPoint(1) - L.EndPoint(1)
A(2) = L.StartPoint(1) - L.EndPoint(1)
FitPoints(0) = L.StartPoint(0): FitPoints(1) = L.StartPoint(1): FitPoints(2) = L.StartPoint(2)
FitPoints(3) = CenterP(0): FitPoints(4) = CenterP(1): FitPoints(5) = CenterP(2)
FitPoints(6) = L.EndPoint(0): FitPoints(7) = L.EndPoint(1): FitPoints(8) = L.EndPoint(2)
StartTan(0) = -A(0): StartTan(1) = -A(1): StartTan(2) = -A(2)
Set SP = ThisDrawing.ModelSpace.AddSpline(FitPoints, StartTan, StartTan)
SP.Layer = L.Layer
SP.color = L.color
L.Delete
End If
Next E
End Sub
|
tiancao1001 于 2008-11-05 11:09 AM 发表评论:
因此要吧终点加上那么一点点,
'直线转化为样条曲线
Sub LineToSPline()
Dim E As AcadEntity
Dim L As AcadLine
Dim StartTan(0 To 2) As Double '指定样条曲线的起点切向。
Dim FitPoints(0 To 8) As Double '指定样条曲线的所有拟合点?
Dim CenterP As Variant '直线中点
Dim a(0 To 2) As Double '拟合样条曲线的端点和终点的方向
Dim n As Long
Dim i As Long
Dim Sp As AcadSpline
n = ThisDrawing.ModelSpace.Count
For Each E In ThisDrawing.ModelSpace
i = i + 1
ThisDrawing.Utility.Prompt Int(i / n * 100) & "%" & vbCrLf
DoEvents
'ThisDrawing.Utility.Prompt L.ObjectName
'If e.ObjectName = "AcDbLine" Then
If TypeOf E Is AcadLine Then
Set L = E
CenterP = centerPoint(L.StartPoint, L.EndPoint)
a(0) = L.StartPoint(0) - L.EndPoint(0)
a(1) = L.StartPoint(1) - L.EndPoint(1)
a(2) = L.StartPoint(1) - L.EndPoint(1)
FitPoints(0) = L.StartPoint(0): FitPoints(1) = L.StartPoint(1): FitPoints(2) = L.StartPoint(2)
FitPoints(3) = CenterP(0): FitPoints(4) = CenterP(1): FitPoints(5) = CenterP(2)
FitPoints(6) = L.EndPoint(0) + 0.001: FitPoints(7) = L.EndPoint(1) + 0.001: FitPoints(8) = L.EndPoint(2)
StartTan(0) = -a(0): StartTan(1) = -a(1): StartTan(2) = -a(2)
Set Sp = ThisDrawing.ModelSpace.AddSpline(FitPoints, StartTan, StartTan)
Sp.Layer = L.Layer
Sp.color = L.color
L.Delete
End If
Next E
End Sub
Sub LineToSPline()
Dim E As AcadEntity
Dim L As AcadLine
Dim StartTan(0 To 2) As Double '指定样条曲线的起点切向。
Dim FitPoints(0 To 8) As Double '指定样条曲线的所有拟合点?
Dim CenterP As Variant '直线中点
Dim a(0 To 2) As Double '拟合样条曲线的端点和终点的方向
Dim n As Long
Dim i As Long
Dim Sp As AcadSpline
n = ThisDrawing.ModelSpace.Count
For Each E In ThisDrawing.ModelSpace
i = i + 1
ThisDrawing.Utility.Prompt Int(i / n * 100) & "%" & vbCrLf
DoEvents
'ThisDrawing.Utility.Prompt L.ObjectName
'If e.ObjectName = "AcDbLine" Then
If TypeOf E Is AcadLine Then
Set L = E
CenterP = centerPoint(L.StartPoint, L.EndPoint)
a(0) = L.StartPoint(0) - L.EndPoint(0)
a(1) = L.StartPoint(1) - L.EndPoint(1)
a(2) = L.StartPoint(1) - L.EndPoint(1)
FitPoints(0) = L.StartPoint(0): FitPoints(1) = L.StartPoint(1): FitPoints(2) = L.StartPoint(2)
FitPoints(3) = CenterP(0): FitPoints(4) = CenterP(1): FitPoints(5) = CenterP(2)
FitPoints(6) = L.EndPoint(0) + 0.001: FitPoints(7) = L.EndPoint(1) + 0.001: FitPoints(8) = L.EndPoint(2)
StartTan(0) = -a(0): StartTan(1) = -a(1): StartTan(2) = -a(2)
Set Sp = ThisDrawing.ModelSpace.AddSpline(FitPoints, StartTan, StartTan)
Sp.Layer = L.Layer
Sp.color = L.color
L.Delete
End If
Next E
End Sub
tiancao1001 于 2008-07-15 05:31 PM 发表评论:
'样条曲线转化为直线(针对上面函数转化后的样条曲线)
Sub SPlineToLine()
Dim E As AcadEntity
Dim L As AcadLine
Dim SP As AcadSpline
Dim StartP As Variant
Dim EndP As Variant
For Each E In ThisDrawing.ModelSpace
'DoEvents
'ThisDrawing.Utility.Prompt E.ObjectName
If E.ObjectName = "AcDbSpline" Then
Set SP = E
StartP = SP.GetFitPoint(0)
EndP = SP.GetFitPoint(2)
Set L = ThisDrawing.ModelSpace.AddLine(StartP, EndP)
L.Layer = SP.Layer
L.color = SP.color
SP.Delete
End If
Next E
End Sub
Sub SPlineToLine()
Dim E As AcadEntity
Dim L As AcadLine
Dim SP As AcadSpline
Dim StartP As Variant
Dim EndP As Variant
For Each E In ThisDrawing.ModelSpace
'DoEvents
'ThisDrawing.Utility.Prompt E.ObjectName
If E.ObjectName = "AcDbSpline" Then
Set SP = E
StartP = SP.GetFitPoint(0)
EndP = SP.GetFitPoint(2)
Set L = ThisDrawing.ModelSpace.AddLine(StartP, EndP)
L.Layer = SP.Layer
L.color = SP.color
SP.Delete
End If
Next E
End Sub
发表评论 - 不要忘了输入验证码哦! |