[求助]请问大家我这段程序哪里有问题?
[求助]请问大家我这段程序哪里有问题?PtPick = ThisDrawing.Utility.GetPoint(, "请输入要插入的点:")<BR> Textdwx.text = PtPick(0)<BR> Textdwy.text = PtPick(1)<BR> Textdwz.text = PtPick(2)
dwx = Val(Textdwx.text)<BR>dwy = Val(Textdwy.text)<BR>dwz = Val(Textdwz.text)
dim ptTo(0 To 2) As Double
ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz+k
我主要是想问问大家ptTo(2) = dwz+k这句话是不是有问题,当dwz为0时画出的图没的问题,但是只要dwz不为0时,就有问题了
在编程的时候我都考虑了起始点(dwx,dwy,dwz)的坐标的,应该思想没的做,主要是不是语法有错误 1 dwz为0出了什么问题
2 需要完整代码 下面就是绘制螺母的程序,dwz为不为0时,画出的图形只有个六棱柱,倒角倒不出来,但是dwz为0时,画出的图形就是对的
Public Function LMH(d, d1, Da, Dw, e, s, m, p, bl As Double, dwx, dwy, dwz As Double)
'变量说明:D为螺母公称直径,Da为螺母内部倒角直径,Dw为螺母与螺栓联结时靠螺栓端的螺母外部倒角直径<BR>'e为螺母的外径,s为螺母与螺栓联结时背靠螺栓端的螺母外部倒角直径<BR>'m为螺母的厚度<BR>'p为内螺纹的螺距<BR>'bl为绘图比例
Dim objBoltT As Acad3DSolid, objCone As Acad3DSolid, objCylinder As Acad3DSolid<BR> Dim xc As Integer<BR> Dim yu<BR> <BR> zh = Int(m / p)<BR> yu = m - zh * p<BR> xc = 2 * (2 * Int(m / p) + 1) - 3<BR> <BR> Da = bl * Da '设置尺寸符合绘图比例<BR> d = bl * d<BR> Dw = bl * Dw<BR> d1 = bl * d1<BR> m = bl * m<BR> e = bl * e<BR> s = bl * s<BR> p = bl * p<BR> yu = yu * bl<BR> <BR> '创建六边形<BR> Dim objPline As AcadLWPolyline<BR> Dim ptCen(0 To 2) As Double<BR> ptCen(0) = dwx: ptCen(1) = dwy: ptCen(2) = dwz<BR> Set objPline = AddPolygon(ptCen, 6, e / 2) ' (中心,边数,边长)<BR> <BR> '创建六棱柱<BR> Dim objRegion As AcadRegion<BR> Set objRegion = PlToRegion(objPline)<BR> Set objBoltT = ThisDrawing.ModelSpace.AddExtrudedSolid(objRegion, m, 0)<BR> objRegion.Delete<BR>' Dim ptTemp(0 To 2) As Double<BR>' ptTemp(0) = 20: ptTemp(1) = 0: ptTemp(2) = 0<BR>' objBoltT.Rotate3D ptCen, ptTemp, -PI / 2<BR>' ThisDrawing.ModelSpace.AddLine ptCen, ptTemp<BR> <BR> '创建圆锥体(原点是形体的中心,而不是底面的中心)<BR> Dim ptTo(0 To 2) As Double<BR> ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + (Tan(30 * 3.14 / 180) * Dw * 0.5 + m) * 0.5<BR> Set objCone = ThisDrawing.ModelSpace.AddCone(ptCen, Dw * 0.5 + m / Tan(30 * 3.14 / 180), Tan(30 * 3.14 / 180) * Dw * 0.5 + m) '(中心,半径,高度)<BR> objCone.Move ptCen, ptTo '确保三个实体的正确位置<BR> <BR> '创建圆柱体<BR> ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + m<BR> Set objCylinder = ThisDrawing.ModelSpace.AddCylinder(ptCen, e, 2 * m)<BR> objCylinder.Move ptCen, ptTo<BR> <BR> '布尔运算的第一步:圆柱体减去圆锥体<BR> objCylinder.Boolean acSubtraction, objCone<BR> ptTo(0) = dwx + 0: ptTo(1) = dwy - 10: ptTo(2) = dwz + 0<BR> objCylinder.Rotate3D ptTo, ptCen, PI<BR> ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + m<BR> objCylinder.Move ptCen, ptTo<BR> '布尔运算的第二步:六棱柱减去上一步得到的对象<BR> objBoltT.Boolean acSubtraction, objCylinder<BR> <BR> '创建圆锥体(原点是形体的中心,而不是底面的中心)<BR> <BR> ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + (Tan(30 * 3.14 / 180) * s * 0.5 + m) * 0.5<BR> Set objCone = ThisDrawing.ModelSpace.AddCone(ptCen, s * 0.5 + m / Tan(30 * 3.14 / 180), Tan(30 * 3.14 / 180) * s * 0.5 + m) '(中心,半径,高度)<BR> objCone.Move ptCen, ptTo '确保三个实体的正确位置<BR> <BR> '创建圆柱体<BR> ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + m<BR> Set objCylinder = ThisDrawing.ModelSpace.AddCylinder(ptCen, e, 2 * m)<BR> objCylinder.Move ptCen, ptTo<BR> <BR> '布尔运算的第一步:圆柱体减去圆锥体<BR> objCylinder.Boolean acSubtraction, objCone<BR> <BR> '布尔运算的第二步:六棱柱减去上一步得到的对象<BR> objBoltT.Boolean acSubtraction, objCylinder<BR> <BR>'创建圆锥体(原点是形体的中心,而不是底面的中心)*******倒角
ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + (d / 2) * 0.5<BR> Set objCone = ThisDrawing.ModelSpace.AddCone(ptCen, d / 2, d / 2) '(中心,半径,高度)<BR> objCone.Move ptCen, ptTo '确保三个实体的正确位置<BR> '布尔运算<BR>objBoltT.Boolean acSubtraction, objCone
'创建圆锥体(原点是形体的中心,而不是底面的中心)*******倒角
ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + (Da / 2) * 0.5<BR> Set objCone = ThisDrawing.ModelSpace.AddCone(ptCen, Da / 2, Da / 2) '(中心,半径,高度)<BR> objCone.Move ptCen, ptTo '确保三个实体的正确位置<BR> ptTo(0) = dwx: ptTo(1) = dwy - 10: ptTo(2) = dwz<BR> objCone.Rotate3D ptTo, ptCen, PI<BR> ptTo(0) = dwx: ptTo(1) = dwy: ptTo(2) = dwz + m<BR> objCone.Move ptCen, ptTo<BR> '布尔运算<BR>objBoltT.Boolean acSubtraction, objCone
End Function 晕,有很多函数你没放出来,根本没法调试,不过从参数上看你是不是在
Public function LMH(d, d1, Da, Dw, e, s, m, p, bl As Double, dwx, dwy, dwz As Double)中的d,d1等参数你都声明为了Variant然后所导致的错误。 首先感谢楼上的师兄,由于程序本身有点多,不方便全部打出来,看了看你给的解释。
d, d1, Da, Dw, e, s, m, p, bl 这些参数我都是声明为的double型呀
只有PtPick数组,也就是拾取点的时候哪个数祖,才定义为的variant型
很有可能就是这里出了问题,但是不晓得具体是哪里
ptTo(2) = dwz + (d / 2) * 0.5<BR>是不是dwz不能直接在后面加(d / 2) * 0.5哦
应该就是这里出了问题<BR> Public function LMH(d, d1, Da, Dw, e, s, m, p, bl As Double, dwx, dwy, dwz As Double)这样声明就是只有bl和dwz成了Double型,其他都默认为Variant,VB和Delphi是不一样地。
ptTo(2) = dwz + (d / 2) * 0.5<BR>没有除数为0的情况不会有问题。 哦
多谢了哈
我试试看哈
页:
[1]