目标:把建筑立面图转到各个平面上,然后组成简单的3维图。
过程:
1。先分析立面图所用的画图命令,然后针对各命令作旋转处理。
2。最简单的是画线命令,取得线的起终点,旋转坐标后,更新线的坐标就可以了。
3。对其他画图命令,因为AutoCAD只在xy平面上画图,取得参数坐标后,先要用ucs命令转到对应平面,再画图。还要删除原来的图。
下面是一个转弧的例子。
生成弧的例程:
Sub Example_AddArc() ' This example creates an arc in model space. Dim arcObj As AcadArc Dim centerPoint(0 To 2) As Double Dim radius As Double Dim startAngleInDegree As Double Dim endAngleInDegree As Double ' Define the circle centerPoint(0) = 0#: centerPoint(1) = 0#: centerPoint(2) = 0# radius = 5# startAngleInDegree = 0# endAngleInDegree = 180# ' Convert the angles in degrees to angles in radians Dim startAngleInRadian As Double Dim endAngleInRadian As Double startAngleInRadian = startAngleInDegree * 3.141592 / 180# endAngleInRadian = endAngleInDegree * 3.141592 / 180# ' Create the arc object in model space Set arcObj = ThisDrawing.ModelSpace.AddArc(centerPoint, radius, startAngleInRadian, endAngleInRadian) ZoomAll End Sub
转弧的例程:
Sub myrotatearc() Dim newObjs As AcadArc Dim centerPoint(0 To 2) As Double Dim radius As Double Dim startAngleInDegree As Double Dim endAngleInDegree As Double Dim startAngleInRadian As Double Dim endAngleInRadian As Double Dim i, n As Long n = ThisDrawing.ModelSpace.Count For i = 0 To n - 1 'AcDbArc If ThisDrawing.ModelSpace.Item(i).ObjectName = "AcDbArc" Then Set newObjs = ThisDrawing.ModelSpace.Item(i) centerPoint(0) = newObjs.Center(0) centerPoint(1) = newObjs.Center(1) centerPoint(2) = newObjs.Center(2) radius = newObjs.radius startAngleInRadian = newObjs.StartAngle endAngleInRadian = newObjs.EndAngle ThisDrawing.SendCommand "_Ucs" & vbCr & "y" & vbCr & "90" & vbCr '绕y轴转90度 Set arcObj = ThisDrawing.ModelSpace.AddArc(centerPoint, radius, startAngleInRadian - 3.1415926 / 2#, endAngleInRadian - 3.1415926 / 2#) '注意这里减了90度,可能是因为上面ucs命令转了90度 ThisDrawing.SendCommand "_Ucs" & vbCr & "y" & vbCr & "-90" & vbCr '把画图平面转回来 newObjs.Delete '删除原来的弧 End If Next i ZoomAll ThisDrawing.Regen acAllViewports MsgBox "Good on ya!" End Sub |