brianxian 发表于 2010-7-23 23:04:00

vba旋转生成实体

求VBA旋转生成实体语句,如一个平面的圆绕一个轴旋转后生成圆环,就是这个图标的语句。谢了!

wuyunpeng888 发表于 2010-7-28 22:54:00

<pre class="Code">Sub Example_AddRevolvedSolid()
    ' 该示例通过面域沿一个轴旋转以创建实体。
    ' 面域是由一个弧和一根直线创建的。
    Dim curves(0 To 1) As AcadEntity

    ' 定义圆弧
    Dim centerPoint(0 To 2) As Double
    Dim radius As Double
    Dim startAngle As Double
    Dim endAngle As Double
    centerPoint(0) = 5#: centerPoint(1) = 3#: centerPoint(2) = 0#
    radius = 2#
    startAngle = 0
    endAngle = 3.141592
    Set curves(0) = ThisDrawing.ModelSpace.AddArc(centerPoint, radius, startAngle, endAngle)
   
    ' 定义直线
    Set curves(1) = ThisDrawing.ModelSpace.AddLine(curves(0).startPoint, curves(0).endPoint)
      
    ' 创建面域
    Dim regionObj As Variant
    regionObj = ThisDrawing.ModelSpace.AddRegion(curves)
    ZoomAll
    MsgBox "旋转该面域以创建实体。", , "AddRevolvedSolid 示例"
   
    ' 定义旋转轴
    Dim axisPt(0 To 2) As Double
    Dim axisDir(0 To 2) As Double
    Dim angle As Double
    axisPt(0) = 7: axisPt(1) = 2.5: axisPt(2) = 0
    axisDir(0) = 11: axisDir(1) = 1: axisDir(2) = 3
    angle = 6.28
      
    ' 创建实体
    Dim solidObj As Acad3DSolid
    Set solidObj = ThisDrawing.ModelSpace.AddRevolvedSolid(regionObj(0), axisPt, axisDir, angle)
    ZoomAll
   
   ' 更改视口的查看方向以更好地看清实体
    Dim NewDirection(0 To 2) As Double
    NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
    ThisDrawing.ActiveViewport.direction = NewDirection
    ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
    ZoomAll
    MsgBox "实体已创建完成", , "AddRevolvedSolid 示例"

End Sub</pre>

brianxian 发表于 2010-7-30 12:59:00

<p>谢了,就是这个东西,我的开发要完成了</p>

brianxian 发表于 2010-7-30 13:26:00

<p>Sub Example_AddRevolvedSolid()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cc As AcadCircle<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ptc(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim rc As Double<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ptc(0) = 0: ptc(1) = 0: ptc(2) = 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; re = 5<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set cc = ThisDrawing.ModelSpace.AddCircle(ptc, re)<br/>&nbsp;&nbsp;&nbsp; ' 创建面域<br/>&nbsp;&nbsp;&nbsp; Dim regionObj As Variant<br/>&nbsp;&nbsp;&nbsp; regionObj = ThisDrawing.ModelSpace.AddRegion(cc)<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 定义旋转轴<br/>&nbsp;&nbsp;&nbsp; Dim axisPt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim axisDir(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim angle As Double<br/>&nbsp;&nbsp;&nbsp; axisPt(0) = 10: axisPt(1) = -5: axisPt(2) = 0<br/>&nbsp;&nbsp;&nbsp; axisDir(0) = 10: axisDir(1) = 5: axisDir(2) = 0<br/>&nbsp;&nbsp;&nbsp; angle = 6.28<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 创建实体<br/>&nbsp;&nbsp;&nbsp; Dim solidObj As Acad3DSolid<br/>&nbsp;&nbsp;&nbsp; Set solidObj = ThisDrawing.ModelSpace.AddRevolvedSolid(regionObj(0), axisPt, axisDir, angle)<br/>&nbsp;&nbsp;&nbsp; ZoomAll<br/>End Sub<br/>这又是这么回事?</p>
<p>按照你给的代码修改的</p>

brianxian 发表于 2010-8-1 22:58:00

<p>求解答~~~~~~~~~~~~~~~~~~!!~!~!~!~!~!~!~!</p>

brianxian 发表于 2010-8-6 20:03:00

00000000000000000000000000

brianxian 发表于 2010-8-12 14:50:00

<p>版主,管理员。。。。。。。。帮忙解决下啊~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!</p>
<p>谢谢~~~~~~~~~~~~~~~~~~!</p>
页: [1]
查看完整版本: vba旋转生成实体