[VBA]有偿求做螺栓参数化设计~~~
有偿求做螺栓参数化设计~~~ 楼上的兄弟是做毕业设计呢吧,我也是。。。。我弄了好多资料,还有请人帮忙弄了三个螺栓的程序,可是问题是现在程序的语言没什么错误了,可是就是出不来图象。。。。。。现在我先给你发个程序,希望我们能够共同探讨。。。程序如下:main (thisdrawing)
Public Sub m(d, k, e, s, r, f, b, c, dw)<BR>Dim sysOSMODE As Integer<BR>sysOSMODE = thisdrawing.GetVariable("OSMODE")<BR>thisdrawing.SetVariable "OSMODE", 0<BR>thisdrawing.Utility.InitializeUserInput 32<BR>On Error Resume Next<BR>mp = thisdrawing.Utility.GetPoint<BR>np = thisdrawing.Utility.GetPoint<BR>l = thisdrawing.Utility.GetDistance<BR>rotsita = thisdrawing.Utility.GetAngle<BR>If s >= l Then<BR> s = l - 2# * f<BR>End If
thisdrawing.sentcommand ("_polygon" & vbCr & "6" & vbCr & mpstr & vbCr & "c" & vbCr & crad & vbCr)<BR>dx = np(0)<BR>dx1 = dx0 - k<BR>dx2 = ((e / 2# - s / 2#) / 1.732 + dxo) - k<BR>dx3 = (1.5 - 1.141) * d + dx0 - k<BR>dx5 = dx0 + r + c<BR>dx6 = dx0 - b + l - d / 5# + c<BR>dx7 = dx0 + l - b + c<BR>dx8 = dx0 + l - f + c<BR>dx9 = dx0 + l + c<BR>dx10 = (dx1 + dx2) / 2#<BR>dx11 = dx8 + d / 10#<BR>dy0 = np(l)<BR>dy2 = dy0 + d / 2#<BR>dy3 = dy0 + e * 3 / 8<BR>dy4 = dy0 + s / 2#<BR>dy5 = dy0 + e / 2#<BR>dy6 = dy0 + r + d / 2#<BR>dy7 = dy0 + d / 2# - f<BR>dy8 = (dy4 + dy5) / 2#<BR>dy9 = dy2 - d / 10#
utilobj.CreateTypedArray p10, vbDouble, dx1, dy0, 0<BR>utilobj.CreateTypedArray p32, vbDouble, dx3, dx2, 1
Set la = blockobj.AddLine(p10, p14)
<BR>Set arca = blockobj.AddArc(cetpt, ccrad, angs, ange)
For Each acadent In blockobj<BR>acadent.Mirror p10, np<BR>Next acadent
utiobj.CreateTypedArray insertpt, vbDouble, np(0), np(1), np(2)
Set blockrefobj = thisdrawing.ModelSpace.InsertBlock(insertpt, mx, 1#, 1#, 1#, 0)<BR>thisdrawing.Regen acavtiveviewport
End Sub
x = sp(0) - ep(0)<BR>y = sp(1) - ep(0)<BR>distance = spr((x * 2) + (y * 2))
Set l3 = thisdrawing.ModelSpace.AddLine(lcenptl, thisdrawing.unility.PolarPoint(lcenpt1, angel1 + 3.1414926536 / 2, 100))<BR>Set l4 = thisdrawing.ModelSpace.AddLine(lcenpt2, thisdrawing.Utility.PolarPoint(lcenpt2, angel2 + 3.1415926536 / 2, 100))<BR>centerpt = l4.IntersectWith(l3, acExtendBoth)
Public Sub m3()<BR>Call m(3#, 2#, 6.4, 5.3, 0.2, 0.6, 12#, 0.4, 4.6)
End Sub
程序二:
Option Explicit<BR>Const pi As Double = 3.1414926
Sub createbolt()<BR> Dim objbolt As Acad3DSolid, objcone As Acad3DSolid, objcylinder As Acad3DSolid
Dim objpline As AcadLWPolyline<BR> Dim ptcen(0 To 2) As Double<BR> ptcen(0) = 0: ptcen(1) = 0: ptcen(2) = 0<BR> Set objpline = ADDPolygon(ptcen, 6, 7.5)
Dim objregion As AcadRegion<BR> Set objregion = pltoregion(objpline)<BR> Set objboltt = ThisDrawing.ModelSpace.AddExtrudedSolid(objregion, 8, 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
Dim ptto(0 To 2) As Double<BR> ptto(0) = 0: ptto(1) = 0: ptto(2) = 7.5<BR> Set objcone = ThisDrawing.ModelSpace.AddCone(ptcen, 12, 15)<BR> objcone.Move ptcen, ptto
ptto(0) = 0: ptto(1) = 0: ptto(2) = 10<BR> Set objcylinder = ThisDrawing.ModelSpace.AddCylinder(ptcen, 15, 20)<BR> objcylinder.Move ptcen, ptto
<BR> objcylinder.Boolean acSubtraction, objcone
objbolt.Boolean acSubtraction, objcylinder
<BR> Dim ptarrl(0 To 61) As Double<BR> Dim i As Integer<BR> For i = 0 To 61<BR> If i Mod 4 = 0 Then<BR> ptrrl(i) = 2 * i / 4 + 10<BR> ElseIf i Mod 4 = 1 Then<BR> ptrrl(i) = 5<BR> ElseIf i Mod 4 = 2 Then<BR> ptrrl(i) = 2 * (i - 2) / 4 + 10 + 1<BR> ElseIf i Mod 4 = 3 Then<BR> ptrrl(i) = 2<BR> End If<BR> Next i<BR> Dim objpl(0 To 1) As AcadLWPolyline<BR> Set objpl(0) = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptarr1)
Dim ptarr2(0 To 9) As Double<BR> ptarr2(0) = 10: ptarr2(1) = 5: ptarr2(2) = 0: ptarr2(3) = 5<BR> ptarr2(4) = 0: ptarr2(5) = 0: ptarr2(6) = 40: ptarr2(7) = 0<BR> ptarr2(8) = 40: ptarr2(9) = 5<BR> Set objpl(1) = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptarr2)<BR> <BR> <BR> Dim objregionl As Variant<BR> objregionl = ThisDrawing.ModelSpace.AddRegion(objpl)<BR> objpl(0).Delete<BR> objpl(1).Delete
<BR> ptto(0) = 0: ptto(1) = -10: ptto(2) = 0<BR> objregionl1(0).Rotate3D ptto, ptcen, pi, pi / 2<BR> ptto(0) = 0: ptto(1) = 0: ptto(2) = 10<BR> Dim objboltb As Acad3DSolid<BR> <BR> <BR> Set objboltb = ThisDrawing.ModelSpace.AddRevolvedSolid(objregionl(0), ptcen, ptto, 2 * Atn(1) * 4)<BR> objregionl(0).Delete
objboltt.Boolean acUnion, objboltb
End Sub
<BR>Public Function pltoregion(ByVal objpline As AcadLWPolyline) As AcadRegion<BR> If objpline.Close = False Then<BR> MsgBox "多段线不闭合,无法创建面域!", vbCritical<BR> Exit Function<BR> End If
<BR> Dim objlist(0) As AcadEntity<BR> Set objlist(0) = objpline
<BR> Dim objregion As Variant<BR> objregion = ThisDrawing.ModelSpace.AddRegion(objlist)
objpline.Delete<BR> Set pltoregion = objregion(0)<BR>End Function 程序三:这个是从网上“粜”来的@_@
Public Sub m(d1, h, c, d, r, k, s, c2, dw As Double)
'设置环境参数,不设置任何捕捉<BR>Dim sysOSMODE As Integer<BR>sysOSMODE = ThisDrawing.GetVariable("osmode")<BR>ThisDrawing.SetVariable "osmode", 0
'设置初始化用户输入状态<BR>ThisDrawing.Utility.InitializeUserInput 32
On Error Resume Next '错误状态处理<BR>Dim fp, sp As Variant
'捕捉用户输入点<BR>fp = ThisDrawing.Utility.GetPoint(, "请输入螺栓前视图的中心点:")<BR>sp = ThisDrawing.Utility.GetPoint(fp, "请输入螺栓侧视图的基准点:")<BR>l = ThisDrawing.Utility.GetDistance(, "请输入螺栓长度 L:")<BR>rotsita = ThisDrawing.Utility.GetAngle(, "请输入螺栓的旋转角度<0>:")
'错误状态处理<BR>If Err Then<BR> rotsita = 0#<BR> Err.Clear<BR>End If
'设SP点为侧图绘图基准点,xzom为X方向坐标,yzom为Y方向坐标<BR>xzom = sp(0) + 0<BR>yzom = sp(1) + 0
'定义AP为系列定义参数,<BR>Dim ap As Variant<BR>Dim utilObj As Object<BR>Set utilObj = ThisDrawing.Utility
utilObj.CreateTypedArray ap, vbDouble, xzom, yzom, 0<BR>If s >= l Then<BR> s = l - 2# * k<BR>End If
hrad = d / 2#
Dim mx As String<BR> mx = "M" & CStr(Fix(d1)) & CStr(Fix(h)) & CStr(Fix(l))<BR> mmx = mx
'绘制螺栓前视图的圆<BR> Dim circ As AcadCircle<BR> Set circ = ThisDrawing.ModelSpace.AddCircle(fp, hrad)
'绘制螺栓前视图的六边形<BR> Dim fpstr As String<BR> fpstr = fp(0) & "," & fp(1) & "," & fp(2)<BR> ThisDrawing.SendCommand ("_polygon" & vbCr & "6" & _<BR> vbCr & fpstr & vbCr & "c" & vbCr & hrad & vbCr)
'****************************************************<BR>'定义当前图层设置。<BR>Dim flagno As Integer<BR>flagno = 0
Dim iblock As Integer<BR>iblock = ThisDrawing.Blocks.Count<BR>While (iblock > 0)<BR> If ThisDrawing.Blocks.Item(iblock - 1).Name = mx Then<BR> flagno = 1<BR> End If<BR> iblock = iblock - 1<BR>Wend
<BR>If flagno = 0 Then<BR> Dim layerold As Integer<BR> layerold = ThisDrawing.GetVariable("clayer")<BR>'设置各点参数值<BR> rr = r<BR> c40 = c / 4#<BR> ax0 = ap(0)<BR> ax1 = ax0 - h<BR> ax2 = ((c / 2# - d / 2#) / 1.732 + ax0) - h<BR> ax3 = (1.5 - 1.414) * d1 + ax0 - h<BR> ax5 = ax0 + rr + c2<BR> ax6 = ax0 - s + l - d1 / 5# + c2<BR> ax7 = ax0 + l - s + c2<BR> ax8 = ax0 + l - k + c2<BR> ax9 = ax0 + l + c2<BR> ax10 = (ax1 + ax2) / 2#<BR> ax11 = ax8 + d1 / 10#<BR> ay0 = ap(1)<BR> ay2 = ay0 + d1 / 2#<BR> ay3 = ay0 + c * 3 / 8<BR> ay4 = ay0 + d / 2#<BR> ay5 = ay0 + c / 2#<BR> ay6 = ay0 + r + d1 / 2#<BR> ay7 = ay0 + d1 / 2# - k<BR> ay8 = (ay4 + ay5) / 2#<BR> ay9 = ay2 - d1 / 10#<BR> ccrad = 1.5 * d1<BR> '设置各参数点<BR> Dim p10, p32, p13, p14, p25, p05, p06, p52, p72, p77, _<BR> p70, p82, p80, p90, p97, p62, p02, p108, p79, p119, p1, p2 As Variant<BR> utilObj.CreateTypedArray p10, vbDouble, ax1, ay0, 0<BR> utilObj.CreateTypedArray p32, vbDouble, ax3, ay2, 0<BR> utilObj.CreateTypedArray p13, vbDouble, ax1, ay3, 0<BR> utilObj.CreateTypedArray p14, vbDouble, ax1, ay4, 0<BR> utilObj.CreateTypedArray p25, vbDouble, ax2, ay5, 0<BR> utilObj.CreateTypedArray p05, vbDouble, ax0, ay5, 0<BR> utilObj.CreateTypedArray p06, vbDouble, ax0 + c2, ay6, 0<BR> utilObj.CreateTypedArray p52, vbDouble, ax5, ay2, 0<BR> utilObj.CreateTypedArray p72, vbDouble, ax7, ay2, 0<BR> utilObj.CreateTypedArray p77, vbDouble, ax7, ay7, 0<BR> utilObj.CreateTypedArray p70, vbDouble, ax7, ay0, 0<BR> utilObj.CreateTypedArray p82, vbDouble, ax8, ay2, 0<BR> utilObj.CreateTypedArray p80, vbDouble, ax8, ay0, 0<BR> utilObj.CreateTypedArray p90, vbDouble, ax9, ay0, 0<BR> utilObj.CreateTypedArray p97, vbDouble, ax9, ay7, 0<BR> utilObj.CreateTypedArray p62, vbDouble, ax6, ay2, 0<BR> utilObj.CreateTypedArray p02, vbDouble, ax0, ay2, 0<BR> utilObj.CreateTypedArray p108, vbDouble, ax10, ay8, 0<BR> utilObj.CreateTypedArray p79, vbDouble, ax7, ay9, 0<BR> utilObj.CreateTypedArray p119, vbDouble, ax11, ay9, 0<BR> utilObj.CreateTypedArray p1, vbDouble, ax0 + c2, ay0, 0<BR> utilObj.CreateTypedArray p2, vbDouble, ax0 + c2, ay0 + dw / 2, 0<BR> <BR>
' 生成块
Set blockObj = ThisDrawing.Blocks.Add(ap, mx)<BR> <BR>Dim linea, lineb, linec, lined, linee, linef, lineg, lineh, linei, linej, _<BR>linek, linep, lineq As AcadLine
'绘制螺栓侧视图的一侧各条线段<BR> Set linea = blockObj.AddLine(p10, p14)<BR> Set lineb = blockObj.AddLine(p14, p25)<BR> Set linec = blockObj.AddLine(p25, p05)<BR> Set lined = blockObj.AddLine(p05, ap)<BR> Set linee = blockObj.AddLine(p06, ap)<BR> Set linef = blockObj.AddLine(p32, p02)<BR> Set lineg = blockObj.AddLine(p52, p82)<BR> Set lineh = blockObj.AddLine(p82, p80)<BR> Set linei = blockObj.AddLine(p82, p97)<BR> Set linej = blockObj.AddLine(p97, p90)<BR> Set linek = blockObj.AddLine(p72, p70)<BR> Set linep = blockObj.AddLine(p1, p2)<BR> Set lineq = blockObj.AddLine(p2, p05)<BR> <BR> dist = distance(p32, p10)<BR> pi = 3.1415926536<BR> ang1 = Atn(Sqr(ccrad ^ 2 - (dist / 2#) ^ 2) * 2 / dist)<BR> ang2 = ThisDrawing.Utility.AngleFromXAxis(p32, p10)<BR> ang3 = ang1 + ang2 - 2 * pi<BR> <BR> Dim cenPt As Variant<BR> cenPt = ThisDrawing.Utility.PolarPoint(p32, ang3, ccrad)<BR> angs = ThisDrawing.Utility.AngleFromXAxis(cenPt, p32)<BR> ange = ThisDrawing.Utility.AngleFromXAxis(cenPt, p10)<BR> <BR> Dim arca As AcadArc<BR> Set arca = blockObj.AddArc(cenPt, ccrad, angs, ange)<BR> Dim arcb As AcadArc<BR> <BR> Dim cenPt2 As Variant<BR> '利用 p108, p13, p32 绘制圆弧<BR> cenPt2 = centerPt(p108, p13, p32)<BR> arcb_ra = distance(cenPt2, p108)<BR> arcb_angs = ThisDrawing.Utility.AngleFromXAxis(cenPt2, p108)<BR> arcb_ange = ThisDrawing.Utility.AngleFromXAxis(cenPt2, p32)<BR> <BR> Set arcb = blockObj.AddArc(cenPt2, arcb_ra, arcb_angs, arcb_ange)<BR> <BR> 'arcc<BR> distc = distance(p06, p52)<BR> ang1c = Atn(Sqr(rr ^ 2 - (distc / 2#) ^ 2) * 2 / distc)<BR> ang2c = ThisDrawing.Utility.AngleFromXAxis(p06, p52)<BR> ang3c = ang1c + ang2c - 2 * pi<BR> <BR> Dim cenPt3 As Variant<BR> cenPt3 = ThisDrawing.Utility.PolarPoint(p06, ang3c, rr)<BR> arcc_angs = ThisDrawing.Utility.AngleFromXAxis(cenPt3, p06)<BR> arcc_ange = ThisDrawing.Utility.AngleFromXAxis(cenPt3, p52)<BR> '绘制螺栓侧视图的圆弧<BR> Dim arcc As AcadArc<BR> Set arcc = blockObj.AddArc(cenPt3, rr, arcc_angs, arcc_ange)<BR> <BR> 'color 3<BR> Dim linel, linem As AcadLine<BR> Set linel = blockObj.AddLine(p62, p79)<BR> Set linem = blockObj.AddLine(p79, p119)<BR> linel.Color = 3<BR> linem.Color = 3<BR> '对绘制的螺栓进行镜像<BR> Dim acadent As AcadEntity<BR> For Each acadent In blockObj<BR> acadent.Mirror p10, ap<BR> Next acadent<BR> <BR> <BR>End If
Dim insertPt As Variant<BR> utilObj.CreateTypedArray insertPt, vbDouble, sp(0), sp(1), sp(2)<BR> <BR> <BR> Dim blockRefObj As AcadBlockReference<BR> Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertPt, mx, 1#, 1#, 1#, 0)<BR> <BR> ThisDrawing.Regen acActiveViewport<BR>
ThisDrawing.SetVariable "osmode", sysOSMODE<BR>End Sub
程序发给你了,希望能够多交流交流。。。。我TMD也快死了!!!
[VBA]有偿求做螺栓参数化设计~~~
谢谢!! <p>你的程序不全,运行的时候没有发现有几个函数未定义吗??在书上这几个函数没有给出来,但是光盘里有的.你看看吧。</p> 他妈有病,要发就发全嘛,想做好事就不要讨挨骂 <p>可与QQ:278410209联系.</p> 楼主弄的咋样了,我的是一样的课题,有能够运行的程序,但没有窗体,相互交流下,ok?
页:
[1]