AutoCAD VBA创建椭圆和样条曲线
AutoCAD VBA创建椭圆和样条曲线,代码如下。
Public Function AddEllipse(ByVal ptCen As Variant, ByVal ptmajAxis As Variant, ByVal radRatio As Double) As AcadEllipse
Set AddEllipse = ThisDrawing.ModelSpace.AddEllipse(ptCen, ptmajAxis, radRatio)
End Function
Public Function AddEllipseRec(ByVal pt1 As Variant, ByVal pt2 As Variant, ByVal angle As Double) As AcadEllipse
Dim majAxisLen, minAxisLen As Double
Dim ptCen As Variant
Dim radRatio As Double
Dim ptmajAxis(0 To 2) As Double
Dim objEllipse As AcadEllipse
majAxisLen = Abs(pt1(0) – pt2(0))
minAxisLen = Abs(pt1(1) – pt2(1))
radRatio = minAxisLen / majAxisLen
If radRatio < 1 Then
ptmajAxis(0) = majAxisLen / 2: ptmajAxis(1) = 0: ptmajAxis(2) = 0
ElseIf radRatio > 1 Then
ptmajAxis(0) = 0: ptmajAxis(1) = minAxisLen / 2: ptmajAxis(2) = 0
Else
MsgBox "参数错误,无法创建椭圆!"
Exit Function
End If
ptCen = GetMidPt(pt1, pt2)
Set objEllipse = AddEllipse(ptCen, ptmajAxis, radRatio)
objEllipse.Rotate ptCen, angle
objEllipse.Update
Set AddEllipseRec = objEllipse
End Function
Public Function GetMidPt(pt1 As Variant, pt2 As Variant) As Variant
Dim ptMid(0 To 2) As Double
ptMid(0) = (pt1(0) + pt2(0)) / 2
ptMid(1) = (pt1(1) + pt2(1)) / 2
ptMid(0) = 0
GetMidPt = ptMid
End Function
Public Function AddSpline(ByRef ptArr() As Double, ByVal vecSt As Variant, ByVal vecEn As Variant) As AcadSpline
If (UBound(ptArr) + 1) Mod 3 <> 0 Then
MsgBox "数组参数无法创建样条曲线!"
Exit Function
End If
Set AddSpline = ThisDrawing.ModelSpace.AddSpline(ptArr, vecSt, vecEn)
End FunctionSub TestElandSp()
Dim ptCen(0 To 2) As Double
Dim ptmajAxis(0 To 2) As Double
Dim radRatio As Double
ptCen(0) = 150: ptCen(1) = 150: ptCen(2) = 0
ptmajAxis(0) = 30: ptmajAxis(1) = 0: ptmajAxis(2) = 0
radRatio = 0.3
AddEllipse ptCen, ptmajAxis, radRatio
ptCen(0) = 50: ptCen(1) = 50: ptCen(2) = 0
ptmajAxis(0) = 100: ptmajAxis(1) = 120: ptmajAxis(2) = 0
AddEllipseRec ptCen, ptmajAxis, 0
Dim vec1(2) As Double
Dim vec2(2) As Double
Dim ptArr(14) As Double
vec1(0) = -1: vec1(1) = -1: vec1(2) = 0
vec2(0) = 1: vec1(1) = -1: vec2(2) = 0
ptArr(0) = 0: ptArr(1) = 50: ptArr(2) = 0: ptArr(3) = 20: ptArr(4) = 90: ptArr(5) = 0
ptArr(6) = 40: ptArr(7) = 50: ptArr(8) = 0: ptArr(9) = 60: ptArr(10) = 90: ptArr(11) = 0
ptArr(12) = 80: ptArr(13) = 50: ptArr(14) = 0
AddSpline ptArr, vec1, vec2
ZoomAll
End Sub
代码完。
基本建模失败。
相关文章
- 2021-08-01Visual Basic与AutoCAD二次开发PDF下载
- 2021-08-01Mastering AutoCAD Civil 3D 2010PDF下载
- 2016-02-22VisualBasic与AutoCAD二次开发教程下载
- 2012-02-25某污水厂全套施工图(CASS工艺)
- 2011-08-03用AutoCAD画相贯线的作图法研究
- 2011-08-03AutoCAD 2007三维实体建模手册
- 2011-08-03AutoCAD 2009典型案例设计(电子教案)PPT
- 2011-08-03绘制零件图装配图--AutoCAD软件应用实例
- 2011-07-28AutoCAD 2007中文版 建筑与土木工程制图习题集锦
- 2011-07-25AutoCAD 2006 标准教程ppt免费下载