几何尺寸与公差论坛

 找回密码
 注册
查看: 2427|回复: 1

【转帖】solidworks二次开发之零件篇-VB(原创)

[复制链接]
发表于 2011-3-15 18:28:51 | 显示全部楼层 |阅读模式
只需要用VB做一个按钮就可以实现

Option Explicit
Private Sub Command1_Click()
Dim swApp As SldWorks.SldWorks


Dim Part As Object

Set swApp = CreateObject("SldWorks.application")
swApp.Visible = True  '让后台运行的SW显示出来
swApp.UserControl = True


End Sub

VB程序,前提是SW已经打开。。。结合前面的启动篇就不需要打开。。。VB窗口形式的图形在后面。。。

  

Option Explicit

Private Sub Command1_Click()
Dim swApp As SldWorks.SldWorks
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object



Set swApp = CreateObject("sldworks.application")

Set Part = swApp.NewDocument("D:\Program Files\SolidWorks\lang\chinese-simplified\Tutorial\part.prtdot", 0, 0#, 0#)
Set Part = swApp.ActivateDoc2("零件1", False, longstatus)
swApp.ActiveDoc.ActiveView.FrameWidth = 1205
swApp.ActiveDoc.ActiveView.FrameHeight = 820
swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1
swApp.ActiveDoc.ActiveView.FrameState = 1
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("前视", "LANE", 0, 0, 0, False, 0, Nothing, 0) '进入前视基准面


Part.CreateCircle 0, 0, 0, Val(Text1.Text) * 0.001, 0, 0 '绘制圆,前三个坐标为圆心坐标,分别为X、Y、Z轴坐标,后三个为圆上一点坐标
Part.FeatureManager.FeatureExtrusion2 True, False, False, 0, 0,  Val(Text2.Text) * 0.001, 0, False, False, False, False, 0, 0, False,  False, False, False, 1, 1, 1, 0, 0, False
'拉伸命令,其中第六个参数为拉伸长度
boolstatus = Part.Extension.SelectByID2("", "FACE", 0, 0, Val(Text2.Text) * 0.001, False, 0, Nothing, 0)
'进入一个绘制基准面,其中基准面的Z周坐标为Val(Text2.Text) * 0.001
Part.SketchManager.InsertSketch True '插入一个草图


Part.CreateCircle 0, 0, 0, Val(Text3.Text) * 0.001, 0, 0
'绘制圆
Part.FeatureManager.FeatureCut True, False, False, 0, 0, Val(Text4.Text)  * 0.001, 0, False, False, False, False, 0, 0, False, False, False,  False, 0, 1, 1
'切除
boolstatus = Part.Extension.SelectByID2("", "FACE", 0, 0, Val(Text2.Text) * 0.001, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True


Part.CreateCircle  Val(Text1.Text) * 0.001 - (Val(Text1.Text) * 0.001 - Val(Text3.Text) *  0.001) / 2, 0, Val(Text2.Text) * 0.001, Val(Text1.Text) * 0.001 -  (Val(Text1.Text) * 0.001 - Val(Text3.Text) * 0.001) / 2 + 0.006, 0,  Val(Text2.Text) * 0.001
Part.CreateCircularSketchStepAndRepeat Val(Text1.Text) * 0.001 -  (Val(Text1.Text) * 0.001 - Val(Text3.Text) * 0.001) / 2, 3.14159265359,  4, 1.570796326795, 1, ""
Part.FeatureManager.FeatureExtrusion True, False, False, 0, 0,  Val(Text2.Text) * 0.002, 0, False, False, False, False, 0, 0, False,  False, False, False, 1, 1, 1


End Sub

  

下面的程序为驱动另外一个窗口,可以不需要

Private Sub Command2_Click()
End
End Sub


Private Sub Command3_Click()
Load Form2
Form2.Show
End Sub
 楼主| 发表于 2011-3-15 18:29:02 | 显示全部楼层

回复: 【转帖】solidworks二次开发之零件篇-VB(原创)

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

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 01:59 , Processed in 0.037710 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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