SolidWorks机械工程师网——最大的SolidWorks学习平台

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1380|回复: 11
打印 上一主题 下一主题

求用VB语言编写齿轮程序,在SOLIDWORKS生成齿轮

[复制链接]

7

主题

232

帖子

17

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
263
QQ
跳转到指定楼层
楼主
发表于 2008-3-13 22:19:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

   经典图书
[s:12]我要做用VB语言编写齿轮程序,在SOLIDWORKS生成锥齿轮[s:12]的论文,我看了半个月的书,查了好多书籍,问了很多朋友都做不来,我发帖子N天了,请斑竹及各位高手帮帮忙啊,
天天登陆网页等你们帮忙啊
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享教程|习题|模型|技巧 点赞点赞17466 拍砖拍砖1914
SolidWorks机械工程师网
提示:建议使用谷歌浏览器浏览本网站!如单击这里下载!否则,可能无法下载附件文件!(支持大多数版本的谷歌浏览器,支持360和QQ浏览器的极速模式,即谷歌内核模式,使用IE和Edge浏览器,浏览个别网页以及下载文件时,会误报“***不安全”,此时需要单击“继续访问此不安全站点(不推荐)”才可以继续下载,另外,本网站不含任何不安全的文件,已联系微软公司解决,纯属IE和Edge浏览器误报)
回复

使用道具 举报

13

主题

210

帖子

30

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
259
QQ
沙发
发表于 2008-3-13 22:20:36 | 只看该作者
怎么每人会啊? 斑竹出来帮帮忙啊,急啊!!![size=4]
SolidWorks机械工程师网
提示:建议使用谷歌浏览器浏览本网站!如单击这里下载!否则,可能无法下载附件文件!(支持大多数版本的谷歌浏览器,支持360和QQ浏览器的极速模式,即谷歌内核模式,使用IE和Edge浏览器,浏览个别网页以及下载文件时,会误报“***不安全”,此时需要单击“继续访问此不安全站点(不推荐)”才可以继续下载,另外,本网站不含任何不安全的文件,已联系微软公司解决,纯属IE和Edge浏览器误报)
回复 支持 反对

使用道具 举报

12

主题

229

帖子

34

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
270
QQ
板凳
发表于 2008-3-13 22:21:25 | 只看该作者

   经典图书
江洪的一本书上有源程序,你可以看一下,具体的书名我忘了
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

14

主题

215

帖子

31

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
252
QQ
地板
发表于 2008-3-13 22:33:15 | 只看该作者
[size=5]""江洪的一本书上有源程序,你可以看一下,具体的书名我忘了""---------貌似我看过那本书,那讲的是用C++编的,不是VB编的!11

我天天上网等你们的好消息,那么多天了竟然没有一个人会编???
快帮忙啊!!!!
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

10

主题

231

帖子

26

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
280
QQ
5#
发表于 2008-3-13 22:33:39 | 只看该作者

   经典案例图书
高手们编起来也费时费劲啊~~~~忙不好这么帮。 既然有VC代码,那么转到VB还不是一样,改改代码就是。
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

95

主题

314

帖子

219

金币

堂主

Rank: 4

积分
548
6#
发表于 2008-3-13 22:36:20 | 只看该作者
改天帮你找找看,圆柱齿轮的可能有,锥齿轮恐怕没有,是用.swp做出来的,MISUMI的样本光盘中带有一些这样的东东
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

14

主题

222

帖子

43

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
290
QQ
7#
发表于 2008-3-13 22:40:40 | 只看该作者

   经典案例图书
不好意思,是个链轮
Dim swApp
Dim storePath
Dim sw2003api
Private Type BROWSEINFO
   hwndOwner       As Long
   pIDLRoot        As Long
   pszDisplayName  As Long
   lpszTitle       As String
   ulFlags         As Long
   lpfnCallback    As Long
   lParam          As Long
  iImage          As Long
End Type
Private Declare Function SHBrowseForFolder Lib "Shell32" (lpbi As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal hMem As Long)
Private Const MAX_PATH = 260
'Directories only
Private Const BIF_RETURNONLYFSDIRS = &H1&
'Windows 2000 (Shell32.dll 5.0) extended dialog
Private Const BIF_NEWDIALOGSTYLE = &H40
' show edit box
Private Const BIF_EDITBOX = &H10&
Function getFeatureByTypeOcc(model, typ, nr)
  Set feat = model.FirstFeature ' Get the 1st feature in part
  Set res = Nothing
  Count = 0
  Do While Not feat Is Nothing ' While we have a valid feature
    If feat.GetTypeName() = typ Then
      Count = Count + 1
      If Count = nr Then
        Set res = feat
        Exit Do
      End If
    End If
    Set feat = feat.GetNextFeature() ' Get the next feature
  Loop ' Continue until no more
  Set getFeatureByTypeOcc = res
End Function
Function getLastFeatureByType(model, typ)
  Set feat = model.FirstFeature ' Get the 1st feature in part
  Set res = Nothing
  Count = 0
  Do While Not feat Is Nothing ' While we have a valid feature
    If feat.GetTypeName() = typ Then
      Set res = feat
    End If
    Set feat = feat.GetNextFeature() ' Get the next feature
  Loop ' Continue until no more
  Set getLastFeatureByType = res
End Function
' this code with copy a matrix to a other
Function copyMat4x4(source)
Dim res(0 To 15) As Double
For i = 0 To 15
res(i) = source(i)
Next
copyMat4x4 = res
End Function
' This code creates a mat from a sw mat
Function createMatFromSWMat(source)
Dim res(0 To 15) As Double
res(0) = source(0)
res(1) = source(1)
res(2) = source(2)
res(3) = 0
res(4) = source(3)
res(5) = source(4)
res(6) = source(5)
res(7) = 0
res(8) = source(6)
res(9) = source(7)
res(10) = source(8)
res(11) = 0
res(12) = source(9)
res(13) = source(10)
res(14) = source(11)
res(15) = source(12)
createMatFromSWMat = res
End Function
Function createSWMatFromMat(source)
Dim res(0 To 15) As Double
res(0) = source(0)
res(1) = source(1)
res(2) = source(2)
res(3) = source(4)
res(4) = source(5)
res(5) = source(6)
res(6) = source(8)
res(7) = source(9)
res(8) = source(10)
res(9) = source(12)
res(10) = source(13)
res(11) = source(14)
res(12) = source(15)
res(13) = 0
res(14) = 0
res(15) = 0
createSWMatFromMat = res
End Function
Function createMat4x4FromValues(x1, x2, x3, y1, y2, y3, z1, z2, z3, t1, t2, t3)
Dim res(0 To 15) As Double
res(0) = x1
res(1) = x2
res(2) = x3
res(3) = 0
res(4) = y1
res(5) = y2
res(6) = y3
res(7) = 0
res(8) = z1
res(9) = z2
res(10) = z3
res(11) = 0
res(12) = t1
res(13) = t2
res(14) = t3
res(15) = 1
createMat4x4FromValues = res
End Function
' this code will mult a common mat with any other stuff
Function multMatMat(ld, xld, yld, rd, xrd, yrd)
  mulRes = yld * xrd
  'Dim od(0 To 0) As Variant
  ReDim od(mulRes - 1) As Double
  For i = 0 To mulRes - 1
   od(i) = 0#
  Next
  y = 0
  While y < yld
    x = 0
    While x < xrd
      i = 0
      While i < xld
       od(x * yld + y) = od(x * yld + y) + ld(i * yld + y) * rd(x * yrd + i)
       i = i + 1
      Wend
      x = x + 1
    Wend
    y = y + 1
  Wend
  multMatMat = od
End Function
' this code will mult a vector with a matrix
Function mulMat4x4Values3d(mat, x, y, z)
  tmp = createVec4d(x, y, z, 1)
  res = multMatMat(mat, 4, 4, tmp, 1, 3)
  mulMat4x4Values3d = createVec3d(res(0), res(1), res(2))
End Function
Function mulMat4x4Vec3d(mat, vec)
  tmp = createVec4d(vec(0), vec(1), vec(2), 1)
  res = multMatMat(mat, 4, 4, tmp, 1, 3)
  mulMat4x4Vec3d = createVec3d(res(0), res(1), res(2))
End Function
Function mulMat4x4Mat4x4(mat1, mat2)
  mulMat4x4Mat4x4 = multMatMat(mat1, 4, 4, mat2, 4, 4)
End Function
' create a 4x4 matrix
Function createMat4x4()
Dim res(0 To 15) As Double
For i = 0 To 15
res(i) = 0
Next
createMat4x4 = res
End Function
Function createMat4x4Ident()
Dim res(0 To 15) As Double
res(0) = 1
res(5) = 1
res(10) = 1
res(15) = 1
res(1) = 0
res(2) = 0
res(3) = 0
res(4) = 0
res(6) = 0
res(7) = 0
res(8) = 0
res(9) = 0
res(11) = 0
res(12) = 0
res(13) = 0
res(14) = 0
createMat4x4Ident = res
End Function
' this function create a new vector
Function createVec3d(x, y, z)
Dim res(0 To 2) As Double
res(0) = x
res(1) = y
res(2) = z
createVec3d = res
End Function
' this function create a new vector
Function createVec4d(x, y, z, w)
Dim res(0 To 3) As Double
res(0) = x
res(1) = y
res(2) = z
res(3) = w
createVec4d = res
End Function
Function getMatTVec(mat)
getMatTVec = createVec3d(mat(12), mat(13), mat(14))
End Function
Sub setMatTVec(mat, v)
mat(12) = v(0)
mat(13) = v(1)
mat(14) = v(2)
End Sub
Sub setMatXVec(mat, v)
mat(0) = v(0)
mat(1) = v(1)
mat(2) = v(2)
End Sub
Sub setMatYVec(mat, v)
mat(4) = v(0)
mat(5) = v(1)
mat(6) = v(2)
End Sub
Sub setMatZVec(mat, v)
mat(8) = v(0)
mat(9) = v(1)
mat(10) = v(2)
End Sub
Sub setMatScale(mat, s)
mat(15) = s
End Sub
Function getMatXVec(mat)
getMatXVec = createVec3d(mat(0), mat(1), mat(2))
End Function
Function getMatYVec(mat)
getMatYVec = createVec3d(mat(4), mat(5), mat(6))
End Function
Function getMatZVec(mat)
getMatZVec = createVec3d(mat(8), mat(9), mat(10))
End Function
Function negVec3d(v)
negVec3d = createVec3d(-v(0), -v(1), -v(2))
End Function
Function scaleVec3d(v, s)
scaleVec3d = createVec3d(v(0) * s, v(1) * s, v(2) * s)
End Function
' invert a 4x4 matrix
Function invMat4x4(source)
target = copyMat4x4(source)
setMatTVec target, createVec3d(0, 0, 0)
target(1) = source(4)
target(4) = source(1)
target(2) = source(8)
target(8) = source(2)
target(6) = source(9)
target(9) = source(6)
setMatScale target, 1
t = getMatTVec(source)
v = mulMat4x4Vec3d(target, t)
setMatTVec target, negVec3d(v)
invMat4x4 = target
End Function
Function getFaceFromModel(part, pos, normal)
Dim partBodies As Variant
partBodies = part.GetBodies(swSolidBody)
For k = LBound(partBodies) To UBound(partBodies)
   found = 0
   Dim body As Object
   Set body = partBodies(k)
   Set face = body.GetFirstFace()
   getFaceFromModel = noting
   Do While Not face Is Nothing ' While we have a valid feature
     Set sur = face.GetSurface()
     If sur.IsPlane() Then
       planePara = sur.PlaneParams
       faceNormal = face.normal
       nTest = faceNormal(0) * normal(0) + faceNormal(1) * normal(1) + faceNormal(2) * normal(2)
       If nTest > 1 - 0.000001 Then
         ' check projection
         closeRes = face.GetClosestPointOn(pos(0), pos(1), pos(2))
         dTest = (pos(0) - closeRes(0)) * (pos(0) - closeRes(0)) + (pos(1) - closeRes(1)) * (pos(1) - closeRes(1)) + (pos(2) - closeRes(2)) * (pos(2) - closeRes(2))
         If dTest < 0.000001 Then
           Set getFaceFromModel = face
           found = 1
           Exit Do
         End If
       End If
     Else
       If sur.IsCylinder() Then
         closeRes = face.GetClosestPointOn(pos(0), pos(1), pos(2))
         dTest = (pos(0) - closeRes(0)) * (pos(0) - closeRes(0)) + (pos(1) - closeRes(1)) * (pos(1) - closeRes(1)) + (pos(2) - closeRes(2)) * (pos(2) - closeRes(2))
         If dTest < 0.00000001 Then
           res = sur.EvaluateAtPoint(closeRes(0), closeRes(1), closeRes(2))
           nTest = res(0) * normal(0) + res(1) * normal(1) + res(2) * normal(2)
           If nTest > 1 - 0.00000001 Then
             Set getFaceFromModel = face
             found = 1
             Exit Do
           End If
         End If
       End If
     End If
     Set face = face.GetNextFace ' Get the next Face
   Loop
   If (found = 1) Then
     Exit For
   End If
Next k
End Function
Function getEdgeFromModel(part, pos, ByRef edgeRet)
Dim partBodies As Variant
partBodies = part.GetBodies(swSolidBody)
For k = LBound(partBodies) To UBound(partBodies)
   Dim body As Object
   Set body = partBodies(k)
   edges = body.GetEdges()
   start = LBound(edges)
   ende = UBound(edges)
   For i = start To ende
     Set edge = edges(i)
     closeRes = edge.GetClosestPointOn(pos(0), pos(1), pos(2))
     dTest = (pos(0) - closeRes(0)) * (pos(0) - closeRes(0)) + (pos(1) - closeRes(1)) * (pos(1) - closeRes(1)) + (pos(2) - closeRes(2)) * (pos(2) - closeRes(2))
     If dTest < 0.00000001 Then
       Set edgeRet = edge
       getEdgeFromModel = True
       Exit Function
     End If
   Next i
Next k
getEdgeFromModel = False
End Function
Sub cLn(part, wMat, x1, y1, x2, y2)
pk1 = mulMat4x4Values3d(wMat, x1, y1, 0)
pk2 = mulMat4x4Values3d(wMat, x2, y2, 0)
part.CreateLine2 pk1(0), pk1(1), 0, pk2(0), pk2(1), 0
End Sub
Sub cCLn(part, wMat, x1, y1, x2, y2)
pk1 = mulMat4x4Values3d(wMat, x1, y1, 0)
pk2 = mulMat4x4Values3d(wMat, x2, y2, 0)
part.CreateCenterLineVB pk1(0), pk1(1), 0, pk2(0), pk2(1), 0
End Sub
Sub cArc(part, wMat, x1, y1, x2, y2, x3, y3)
pk1 = mulMat4x4Values3d(wMat, x1, y1, 0)
pk2 = mulMat4x4Values3d(wMat, x2, y2, 0)
pk3 = mulMat4x4Values3d(wMat, x3, y3, 0)
part.Create3PointArc pk1(0), pk1(1), 0, pk3(0), pk3(1), 0, pk2(0), pk2(1), 0
End Sub
Sub cCir(part, wMat, x1, y1, rad)
pk1 = mulMat4x4Values3d(wMat, x1, y1, 0)
part.CreateCircleByRadius2 pk1(0), pk1(1), 0, rad
End Sub
Public Function BrowseForFolder() As String
  Dim tBI         As BROWSEINFO
  Dim lngPIDL     As Long
  Dim strPath     As String
  With tBI
    .lpszTitle = ""
    .ulFlags = BIF_RETURNONLYFSDIRS Or BIF_NEWDIALOGSTYLE Or BIF_EDITBOX
  End With
  lngPIDL = SHBrowseForFolder(tBI)
  If (lngPIDL <> 0) Then
    ' get path from ID list
    strPath = Space$(MAX_PATH)
    SHGetPathFromIDList lngPIDL, strPath
    strPath = Left$(strPath, InStr(strPath, Chr$(0)) - 1)
    ' release list
    CoTaskMemFree lngPIDL
  End If
  BrowseForFolder = strPath
End Function
Sub CreatePart0()
Dim error As Long
Set res = swApp.OpenDoc2(storePath & "SP50B19_N_15.sldprt", 1, True, False, True, error)
If Not res Is Nothing Then
Exit Sub
End If
Set part = swApp.NewPart
part.SetAddToDB (True)
part.SetDisplayWhenAdded (False)
swSumInfoTitleVar = 0
swSumInfoAuthorVar = 2
Set swModel = swApp.ActiveDoc
swModel.SummaryInfo(swSumInfoAuthorVar) = "CATALOGS*MISUMI"
swModel.SummaryInfo(swSumInfoTitleVar) = "SP50B19-N-15"
valRGB = part.MaterialPropertyValues
valRGB(0) = 0.68999999761581
valRGB(1) = 0.68999999761581
valRGB(2) = 0.68999999761581
part.MaterialPropertyValues = valRGB
Dim featMgr As Object
If (sw2003api = 1) Then
  Set featMgr = part.FeatureManager
End If
part.CreatePlaneFixed createVec3d(0, 0, 0), createVec3d(0, 0, -1), createVec3d(0, 1, 0), 1
part.BlankRefGeom
Set feat4 = getLastFeatureByType(part, "RefPlane")
part.selectById feat4.Name, "PLANE", 0, 0, 0
codeBag0 part
Set feat4 = getLastFeatureByType(part, "ProfileFeature")
part.selectById feat4.Name, "SKETCH", 0, 0, 0
If (sw2003api = 0) Then
  part.FeatureRevolve2 6.2831853071796, 1, 6.2831853071796, 0, 0
Else
  featMgr.FeatureRevolve 6.2831853071796, 1, 6.2831853071796, 0, 0, 1, 1, 1
End If
part.CreatePlaneFixed createVec3d(0, 0, 0), createVec3d(1, 0, 0), createVec3d(0, 1, 0), 1
part.BlankRefGeom
Set feat6 = getLastFeatureByType(part, "RefPlane")
part.selectById feat6.Name, "PLANE", 0, 0, 0
codeBag1 part
Set feat6 = getLastFeatureByType(part, "ProfileFeature")
part.selectById feat6.Name, "SKETCH", 0, 0, 0
If (sw2003api = 0) Then
  part.FeatureCut 1, 0, 1, 0, 0, 0.0087, 0.0087, 1, 1, 0, 0, 0, 0, 0, 0
Else
  featMgr.FeatureCut 1, 0, 1, 0, 0, 0.0087, 0.0087, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
End If
part.CreatePlaneFixed createVec3d(0, 0, 0.02), createVec3d(1, 0, 0.02), createVec3d(0, 1, 0.02), 1
part.BlankRefGeom
Set feat9 = getLastFeatureByType(part, "RefPlane")
part.selectById feat9.Name, "PLANE", 0, 0, 0
codeBag2 part
Set feat9 = getLastFeatureByType(part, "ProfileFeature")
part.selectById feat9.Name, "SKETCH", 0, 0, 0
If (sw2003api = 0) Then
  part.FeatureRevolveCut2 6.2831853071796, 1, 6.2831853071796, 0, 0
Else
  featMgr.FeatureRevolveCut 6.2831853071796, 1, 6.2831853071796, 0, 0, 1, 1
End If
If ver_2001plus = 1 Then
  If getEdgeFromModel(part, createVec3d(0.0024585, 0.0359585, 0.02), cylEdge) Then
    cylEdge.Select (False)
    part.InsertCosmeticThread 0, 0.006, 0.0267, ""
  ElseIf getEdgeFromModel(part, createVec3d(0.0024585, 0.0103415, 0.02), cylEdge) Then
    cylEdge.Select (False)
    part.InsertCosmeticThread 0, 0.006, 0.0267, ""
  End If
End If
part.CreatePlaneFixed createVec3d(0, 0, 0.02), createVec3d(1, 0, 0.02), createVec3d(0, 1, 0.02), 1
part.BlankRefGeom
Set feat11 = getLastFeatureByType(part, "RefPlane")
part.selectById feat11.Name, "PLANE", 0, 0, 0
codeBag3 part
Set feat11 = getLastFeatureByType(part, "ProfileFeature")
part.selectById feat11.Name, "SKETCH", 0, 0, 0
If (sw2003api = 0) Then
  part.FeatureRevolveCut2 6.2831853071796, 1, 6.2831853071796, 0, 0
Else
  featMgr.FeatureRevolveCut 6.2831853071796, 1, 6.2831853071796, 0, 0, 1, 1
End If
If ver_2001plus = 1 Then
  If getEdgeFromModel(part, createVec3d(0.029911724481983, -0.020108373455204, 0.02), cylEdge) Then
    cylEdge.Select (False)
    part.InsertCosmeticThread 0, 0.006, 0.029, ""
  ElseIf getEdgeFromModel(part, createVec3d(5.7348932845326E-03, -0.006149873455204, 0.02), cylEdge) Then
    cylEdge.Select (False)
    part.InsertCosmeticThread 0, 0.006, 0.029, ""
  End If
End If
part.CreatePlaneFixed createVec3d(0, 0, 0), createVec3d(1, 0, 0), createVec3d(0, 1, 0), 1
part.BlankRefGeom
Set feat13 = getLastFeatureByType(part, "RefPlane")
part.selectById feat13.Name, "PLANE", 0, 0, 0
codeBag4 part
Set feat13 = getLastFeatureByType(part, "ProfileFeature")
part.selectById feat13.Name, "SKETCH", 0, 0, 0
If (sw2003api = 0) Then
  part.FeatureCut 1, 0, 1, 0, 0, 0.028, 0.028, 1, 1, 0, 0, 0, 0, 0, 0
Else
  featMgr.FeatureCut 1, 0, 1, 0, 0, 0.028, 0.028, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
End If
part.SetDisplayWhenAdded (True)
part.SetAddToDB (False)
part.SaveAs2 storePath & "SP50B19_N_15.sldprt", 0, 0, False
End Sub
Sub codeBag0(part)
part.InsertSketch
Set swActiveMat = part.GetActiveSketch()
swSketchMat = createMatFromSWMat(swActiveMat.ModelToSketchXForm)
mSkMat = createMat4x4FromValues(0, 0, -1, 0, 1, 0, 1, 0, 0, 0, 0, 0)
wMat = mulMat4x4Mat4x4(swSketchMat, mSkMat)
cLn part, wMat, -0.028, 0.0077, -0.0278, 0.0075
cLn part, wMat, -0.0278, 0.0075, -0.0002, 0.0075
cLn part, wMat, -0.0002, 0.0075, 0, 0.0077
cLn part, wMat, 0, 0.0077, 0, 0.048225
cLn part, wMat, 0, 0.048225, -0.001105763029981, 0.05235176380902
cArc part, wMat, -0.001105763029981, 0.05235176380902, -1.1771959094371E-03, 0.052458670668058, -1.2989481952388E-03, 0.0525
cLn part, wMat, -1.2989481952388E-03, 0.0525, -7.4010518047612E-03, 0.0525
cArc part, wMat, -7.4010518047612E-03, 0.0525, -7.5228040905629E-03, 0.052458670668058, -0.007594236970019, 0.052351763809021
cLn part, wMat, -0.007594236970019, 0.052351763809021, -0.0087, 0.048225
cLn part, wMat, -0.0087, 0.048225, -0.0087, 0.0367
cArc part, wMat, -0.0087, 0.0367, -8.7585786437627E-03, 0.036558578643763, -0.0089, 0.0365
cLn part, wMat, -0.0089, 0.0365, -0.0278, 0.0365
cLn part, wMat, -0.0278, 0.0365, -0.028, 0.0363
cLn part, wMat, -0.028, 0.0363, -0.028, 0.0077
cCLn part, wMat, 0, 0, -0.028, 0
part.InsertSketch
End Sub
Sub codeBag1(part)
part.InsertSketch
Set swActiveMat = part.GetActiveSketch()
swSketchMat = createMatFromSWMat(swActiveMat.ModelToSketchXForm)
mSkMat = createMat4x4FromValues(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
wMat = mulMat4x4Mat4x4(swSketchMat, mSkMat)
cLn part, wMat, -0.15031007674759, -0.11937067538941, 0.15169542307706, -0.11937067538941
cLn part, wMat, 0.15169542307706, -0.11937067538941, 0.15169542307706, 0.12675918914659
cLn part, wMat, 0.15169542307706, 0.12675918914659, -0.15031007674759, 0.12675918914659
cLn part, wMat, -0.15031007674759, 0.12675918914659, -0.15031007674759, -0.11937067538941
cLn part, wMat, -0.05232068588285, -4.3354156372974E-03, -0.039766520815668, -9.2305673960956E-03
cArc part, wMat, -0.039766520815668, -9.2305673960956E-03, -0.039160403174065, -9.9167608959754E-03, -0.039366875722611, -0.010808730178763
cLn part, wMat, -0.039366875722611, -0.010808730178763, -0.048078099649391, -0.021089009794281
cLn part, wMat, -0.048078099649391, -0.021089009794281, -0.034614700695936, -0.021642597994871
cArc part, wMat, -0.034614700695936, -0.021642597994871, -0.033818617514826, -0.022094805561696, -0.033724280858511, -0.023005487015343
cLn part, wMat, -0.033724280858511, -0.023005487015343, -0.038625505310339, -0.035557282510351
cLn part, wMat, -0.038625505310339, -0.035557282510351, -0.025711840653378, -0.031709317281394
cArc part, wMat, -0.025711840653378, -0.031709317281394, -0.024812059897938, -0.031878535208576, -0.024427136877257, -0.0327092423669
cLn part, wMat, -0.024427136877257, -0.0327092423669, -0.024987238134446, -0.046172371938341
cLn part, wMat, -0.024987238134446, -0.046172371938341, -0.014022703715713, -0.038339840019726
cArc part, wMat, -0.014022703715713, -0.038339840019726, -0.013116730592331, -0.038207730919167, -0.012482933589272, -0.038868443771814
cLn part, wMat, -0.012482933589272, -0.038868443771814, -8.6412159897385E-03, -0.051783968428643
cLn part, wMat, -8.6412159897385E-03, -0.051783968428643, -8.1398924578305E-04, -0.040815646188007
cArc part, wMat, -8.1398924578305E-04, -0.040815646188007, -7.4882862497599E-18, -0.040396526130637, 8.1398924578303E-04, -0.040815646188007
cLn part, wMat, 8.1398924578303E-04, -0.040815646188007, 8.6412159897385E-03, -0.051783968428643
cLn part, wMat, 8.6412159897385E-03, -0.051783968428643, 0.012482933589272, -0.038868443771814
cArc part, wMat, 0.012482933589272, -0.038868443771814, 0.013116730592331, -0.038207730919167, 0.014022703715713, -0.038339840019726
cLn part, wMat, 0.014022703715713, -0.038339840019726, 0.024987238134446, -0.046172371938341
cLn part, wMat, 0.024987238134446, -0.046172371938341, 0.024427136877257, -0.0327092423669
cArc part, wMat, 0.024427136877257, -0.0327092423669, 0.024812059897938, -0.031878535208576, 0.025711840653378, -0.031709317281394
cLn part, wMat, 0.025711840653378, -0.031709317281394, 0.038625505310339, -0.035557282510351
cLn part, wMat, 0.038625505310339, -0.035557282510351, 0.033724280858511, -0.023005487015343
cArc part, wMat, 0.033724280858511, -0.023005487015343, 0.033818617514825, -0.022094805561696, 0.034614700695936, -0.021642597994871
cLn part, wMat, 0.034614700695936, -0.021642597994871, 0.04807809964939, -0.021089009794281
cLn part, wMat, 0.04807809964939, -0.021089009794281, 0.039366875722611, -0.010808730178763
cArc part, wMat, 0.039366875722611, -0.010808730178763, 0.039160403174065, -9.9167608959754E-03, 0.039766520815668, -9.2305673960956E-03
cLn part, wMat, 0.039766520815668, -9.2305673960956E-03, 0.05232068588285, -4.3354156372975E-03
cLn part, wMat, 0.05232068588285, -4.3354156372975E-03, 0.040743458762153, 2.5593202874143E-03
cArc part, wMat, 0.040743458762153, 2.5593202874143E-03, 0.040258551513131, 0.003335918687224, 0.040609021363876, 4.1817384070575E-03
cLn part, wMat, 0.040609021363876, 4.1817384070575E-03, 0.050893513961815, 0.012887988074892
cLn part, wMat, 0.050893513961815, 0.012887988074892, 0.037704855844915, 0.015650028688505
cArc part, wMat, 0.037704855844915, 0.015650028688505, 0.036994061119961, 0.016227099718551, 0.037050904333419, 0.017140887967449
cLn part, wMat, 0.037050904333419, 0.017140887967449, 0.043951240108783, 0.028714778301427
cLn part, wMat, 0.043951240108783, 0.028714778301427, 0.030580346745762, 0.02704481364598
cArc part, wMat, 0.030580346745762, 0.02704481364598, 0.029720690182442, 0.027359822705978, 0.029477746914421, 0.028242556348287
cLn part, wMat, 0.029477746914421, 0.028242556348287, 0.032246167416208, 0.041429876743311
cLn part, wMat, 0.032246167416208, 0.041429876743311, 0.020141982573736, 0.035508873401393
cArc part, wMat, 0.020141982573736, 0.035508873401393, 0.019226621299631, 0.035527684371822, 0.018710218222875, 0.036283705520374
cLn part, wMat, 0.018710218222875, 0.036283705520374, 0.017046722133246, 0.049655405189283
cLn part, wMat, 0.017046722133246, 0.049655405189283, 7.5209220547848E-03, 0.040124995746824
cArc part, wMat, 7.5209220547848E-03, 0.040124995746824, 6.6490496672371E-03, 0.039845570167157, 5.9151470679321E-03, 0.04039295219963
cLn part, wMat, 5.9151470679321E-03, 0.04039295219963, -7.9936057773011E-18, 0.0525
cLn part, wMat, -7.9936057773011E-18, 0.0525, -5.9151470679321E-03, 0.04039295219963
cArc part, wMat, -5.9151470679321E-03, 0.04039295219963, -6.6490496672371E-03, 0.039845570167157, -7.5209220547848E-03, 0.040124995746825
cLn part, wMat, -7.5209220547848E-03, 0.040124995746825, -0.017046722133246, 0.049655405189283
cLn part, wMat, -0.017046722133246, 0.049655405189283, -0.018710218222875, 0.036283705520374
cArc part, wMat, -0.018710218222875, 0.036283705520374, -0.019226621299631, 0.035527684371822, -0.020141982573736, 0.035508873401393
cLn part, wMat, -0.020141982573736, 0.035508873401393, -0.032246167416208, 0.041429876743311
cLn part, wMat, -0.032246167416208, 0.041429876743311, -0.029477746914421, 0.028242556348287
cArc part, wMat, -0.029477746914421, 0.028242556348287, -0.029720690182442, 0.027359822705978, -0.030580346745762, 0.02704481364598
cLn part, wMat, -0.030580346745762, 0.02704481364598, -0.043951240108783, 0.028714778301427
cLn part, wMat, -0.043951240108783, 0.028714778301427, -0.037050904333419, 0.017140887967449
cArc part, wMat, -0.037050904333419, 0.017140887967449, -0.036994061119961, 0.016227099718551, -0.037704855844915, 0.015650028688505
cLn part, wMat, -0.037704855844915, 0.015650028688505, -0.050893513961815, 0.012887988074892
cLn part, wMat, -0.050893513961815, 0.012887988074892, -0.040609021363876, 4.1817384070575E-03
cArc part, wMat, -0.040609021363876, 4.1817384070575E-03, -0.040258551513131, 0.003335918687224, -0.040743458762153, 2.5593202874144E-03
cLn part, wMat, -0.040743458762153, 2.5593202874144E-03, -0.05232068588285, -4.3354156372974E-03
part.InsertSketch
End Sub
Sub codeBag2(part)
part.InsertSketch
Set swActiveMat = part.GetActiveSketch()
swSketchMat = createMatFromSWMat(swActiveMat.ModelToSketchXForm)
mSkMat = createMat4x4FromValues(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.02)
wMat = mulMat4x4Mat4x4(swSketchMat, mSkMat)
cLn part, wMat, 6.0005711337296E-19, 0.0023, -0.003, 0.0023
cLn part, wMat, -0.003, 0.0023, -0.003, 0.0098
cLn part, wMat, -0.003, 0.0098, -0.0024585, 0.0103415
cLn part, wMat, -0.0024585, 0.0103415, -0.0024585, 0.0359585
cLn part, wMat, -0.0024585, 0.0359585, -0.003, 0.0365
cLn part, wMat, -0.003, 0.0365, -0.003, 0.044
cLn part, wMat, -0.003, 0.044, 2.2349065957258E-18, 0.044
cLn part, wMat, 2.2349065957258E-18, 0.044, 6.0005711337296E-19, 0.0023
cCLn part, wMat, 2.2349065957258E-18, 0.0365, 6.0005711337296E-19, 0.0098
part.InsertSketch
End Sub
Sub codeBag3(part)
part.InsertSketch
Set swActiveMat = part.GetActiveSketch()
swSketchMat = createMatFromSWMat(swActiveMat.ModelToSketchXForm)
mSkMat = createMat4x4FromValues(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.02)
wMat = mulMat4x4Mat4x4(swSketchMat, mSkMat)
cLn part, wMat, 4.5922738268339E-19, 0, 0.0015, 2.5980762113533E-03
cLn part, wMat, 0.0015, 2.5980762113533E-03, 7.9951905283833E-03, -1.1519237886467E-03
cLn part, wMat, 7.9951905283833E-03, -1.1519237886467E-03, 8.1933932845326E-03, -0.001891626544796
cLn part, wMat, 8.1933932845326E-03, -0.001891626544796, 0.032370224481983, -0.015850126544796
cLn part, wMat, 0.032370224481983, -0.015850126544796, 0.033109927238132, -0.015651923788647
cLn part, wMat, 0.033109927238132, -0.015651923788647, 0.039605117766515, -0.019401923788647
cLn part, wMat, 0.039605117766515, -0.019401923788647, 0.038105117766515, -0.022
cLn part, wMat, 0.038105117766515, -0.022, 4.5922738268339E-19, 0
cCLn part, wMat, 0.031609927238132, -0.01825, 6.4951905283833E-03, -0.00375
part.InsertSketch
End Sub
Sub codeBag4(part)
part.InsertSketch
Set swActiveMat = part.GetActiveSketch()
swSketchMat = createMatFromSWMat(swActiveMat.ModelToSketchXForm)
mSkMat = createMat4x4FromValues(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
wMat = mulMat4x4Mat4x4(swSketchMat, mSkMat)
cLn part, wMat, -0.0025, 0, 0.0025, 0
cLn part, wMat, 0.0025, 0, 0.0025, 0.0098
cLn part, wMat, 0.0025, 0.0098, -0.0025, 0.0098
cLn part, wMat, -0.0025, 0.0098, -0.0025, 0
part.InsertSketch
End Sub
Sub main()
Set swApp = CreateObject("SldWorks.Application")
code = swApp.RevisionNumber
found = InStr(code, ".")
If (found > 0) Then
  code = Left(code, found - 1)
  If (CInt(code) >= 11) Then
    sw2003api = 1
  End If
End If
swApp.SetUserPreferenceToggle 11, False
swApp.SetUserPreferenceToggle 97, False
storePath = BrowseForFolder
If (storePath <> "") Then
   If ((Right(storePath, 1) <> "") And (Right(storePath, 1) <> "/")) Then
       storePath = storePath + ""
   End If
   CreatePart0
End If
End Sub
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

94

主题

303

帖子

183

金币

堂主

Rank: 4

积分
512
QQ
8#
发表于 2008-3-13 22:42:22 | 只看该作者
上面的兄弟,非常感谢你的帮助啊,我都不知道怎么感谢回报你了,有什么需要的你尽管说,我一定尽我所能!
       我求了好久了,可是他们就知道叫我用插件,要是用插件我还用那么辛苦的那么多天的天天求程序吗,是吧?我们毕业设计要求只能要用VB编程,不能用插件.
        还有,不好意思,我刚学VB技术比较差, 你上面的程序具体操作过程讲解有吗?VB界面是什么样子的?急盼!!!
  还有齿轮的吗?
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

73

主题

285

帖子

147

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
444
9#
发表于 2008-3-13 22:45:48 | 只看该作者
1你了解锥齿轮的齿面参数方程吗?
2你了解使用SW的特征生成锥齿轮的方法吗?
这里引申出一个问题,用拉伸等特征作出的锥齿轮其实不是精确的锥齿轮。比如直齿锥齿轮,严格地说齿面上是球面渐开线,而简单的用拉伸等特征做的话其实是很多二维平面上的渐开线并在一起构成的齿面,只是近似的。曲齿锥齿轮就更复杂了。你要做什么样的?
3只有你完成了上边第2步之后,你确定了建模思路之后,才到你说的使用SW的API编程这一步。VB很简单,SW的help里VB的例子也非常多,你只需要知道你要用到哪些特征然后去找相应的API函数就行了。说真的,我觉得你有些本末倒置了。你说插件没有用,那是说插件不能帮你交差,你多用几款插件看看人家的齿轮建模思路,你就知道有没有用。如果你真是只想交差那就当我没说。
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

11

主题

192

帖子

27

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
239
QQ
10#
发表于 2008-3-13 22:47:20 | 只看该作者

   经典图书
齿轮的齿面参数方程编程好了,下一步该干什么,请高手指点
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

15

主题

231

帖子

34

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
286
QQ
11#
发表于 2008-3-13 22:47:40 | 只看该作者
请问在SW中如何打开其自带的VB??
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

10

主题

211

帖子

29

金币

侠客

Rank: 3Rank: 3Rank: 3

积分
241
12#
发表于 2008-3-13 22:48:31 | 只看该作者
qing请问我在用SW录制VB的齿轮程序时录不完整怎么办?,是不是画图太快了.
SolidWorks机械工程师网
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭 卷起
关闭 卷起

SOLIDWORKS 2023 机械设计从入门到精通

手机版|小黑屋| GMT+8, 2024-9-28 03:22 , Processed in 0.253934 second(s), 27 queries , Memcache On.

SolidWorks机械工程师网 ( 鲁ICP备14025122号-2 ) 鲁公网安备 37028502190335号

声明:本网言论纯属发表者个人意见,与本网立场无关。
如涉版权,可发邮件: admin@swbbsc.com

快速回复 返回顶部 返回列表