bihumanbu 发表于 2006-5-22 11:31:00

将面域旋转成球体时出错,大虾帮忙改以下

Const pi = 3.1415926
Dim r As Double

'绘制球体
&nbspublic Sub drwPicture()
Dim curves(0) As .AcadEntity
Dim centerpoint(2) As Double
r = 500
centerpoint(0) = 0: centerpoint(1) = 0: centerpoint(2) = 0
Set curves(0) = ModelSpace.AddCircle(centerpoint, r)


Dim object As Variant
object = ModelSpace.AddRegion(curves)

Dim solidObj As AutoCAD.Acad3DSolid

Dim axisPt(2) As Double
Dim axisDir(2) As Double
axisPt(0) = 0: axisPt(1) = 0: axisPt(2) = 0
axisDir(0) = 1: axisDir(0) = 0: axisDir(0) = 0
engle = 45 * pi / 180
solidObj = ModelSpace.AddRevolvedSolid(object(0), axisPt, axisDir, engle)
Dim newdirection(2) As Double
newdirection(0) = 1: newdirection(1) = 0.5: newdirection(2) = 0.5
ActiveViewport.Direction = newdirection
ActiveViewport = ActiveViewport
Layers.Item(0).color = AutoCAD.AcColor.acBlue
SendCommand ("_shademode" + vbCr + "_g" + vbCr)
ZoomAll
curves(0).Delete

End Sub

bihumanbu 发表于 2006-5-22 12:00:00

黑体的地方出错了,高手指点一下吧,

xinghesnak 发表于 2006-5-22 14:12:00

Dim curves(0) As AutoCAD.AcadEntity
Dim centerpoint(2) As Double
r = 500
centerpoint(0) = 0: centerpoint(1) = 0: centerpoint(2) = 0
Set curves(0) = ModelSpace.AddCircle(centerpoint, r)
Dim object As Variant
object = ModelSpace.AddRegion(curves)
这段程序创建了一个用于旋转的圆的截面吧,我查了一下VBA的例子,它用一个半圆做截面旋转就没有问题,原因我不清楚。所以我改成了下面这段程序
Dim curves(1) As AutoCAD.AcadEntity
Dim centerpoint(2) As Double
r = 500
centerpoint(0) = 0: centerpoint(1) = 0: centerpoint(2) = 0
Set ModelSpace = ThisDrawing.ModelSpace
Dim startAngle As Double
Dim endAngle As Double
radius = 500
startAngle = 0
endAngle = pi
Set curves(0) = ThisDrawing.ModelSpace.AddArc(centerpoint, radius, startAngle, endAngle)
Set curves(1) = ModelSpace.AddLine(curves(0).StartPoint, curves(0).EndPoint)
下面就不会报错了。。。。
还有就是你的声明给的不全吧,什么Modelspace,SendCommand都没有声明。。。。。。下面删除曲线的程序你自己改吧。。。。。真是不知道为什么整圆不能使用。。。。。。

bihumanbu 发表于 2006-5-22 19:55:00

谢谢了按照你的方法已经成功解决了;
在cad里面好象是不能用整圆旋转,可能是旋转出的两部分相交于轴了;
但是只要轴线在圆以外就行了。
再次感谢你热心的帮助!

guosheyang 发表于 2018-4-27 15:48:00


你好! 你的圆转球体的代码可以共享下吗,我想将许多大小不一的圆一次性转球体, 谢谢!
页: [1]
查看完整版本: 将面域旋转成球体时出错,大虾帮忙改以下