iCAx开思网

标题: 在使用VB调用SW时遇到一个问题 [打印本页]

作者: howard2002    时间: 2006-5-23 07:44
标题: 在使用VB调用SW时遇到一个问题
Private Sub Command1_Click()
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Set swApp = CreateObject("sldworks.application")
swApp.UserControl = True
Set Part = swApp.NewDocument("D:\Program Files\SolidWorks\data\templates\零件.prtdot", 0, 0#, 0#)
'Set Part = swApp.NewDocument("D:\Program Files\SolidWorks\lang\chinese-simplified\Tutorial\part.prtdot", 0, 0#, 0#)
'有一个问题,选用这个模板后,boolstatus = Part.Extension.SelectByID2 不能选择其他的基准平面,系统自动选择从“前视基准面”开始画草图,即"boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0#, 0#, 0#, False, 0, Nothing, 0)"无效,执行后boolstatus的值为false

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("上视基准面", "PLANE", 0#, 0#, 0#, False, 0, Nothing, 0)
Part.InsertSketch2 True
Part.CreateCircleByRadius2 0, 0, 0, 0.01
End Sub


开始我以为是solidworks系统选项->默认模板->零件(P)设置问题
但不论我把零件(P)设成“D:\Program Files\SolidWorks\data\templates\零件.prtdot”或“D:\Program Files\SolidWorks\lang\chinese-simplified\Tutorial\part.prtdot”都出现前面提到的问题

选用Set Part = swApp.NewDocument("D:\Program Files\SolidWorks\data\templates\零件.prtdot", 0, 0#, 0#)语句
运行后,圆的草绘平面是“上视基准面”
而选用“D:\Program Files\SolidWorks\lang\chinese-simplified\Tutorial\part.prtdot”运行后,圆的草绘平面是“前视基准面”

作者: pyczt    时间: 2006-5-23 10:02
试试这种语句,可能是基准面的名称不对
Private Sub Command1_Click()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set Part = swApp.NewDocument("D:\Program Files\SolidWorks\lang\chinese-simplified\Tutorial\part.prtdot", 0, 0#, 0#)
boolstatus = Part.Extension.SelectByID2("上视", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.CreateCircleByRadius2 0, 0, 0, 0.01
Part.InsertSketch2 True
End Sub

[ 本帖最后由 pyczt 于 2006-5-23 10:29 编辑 ]
作者: iamhappyflyer    时间: 2006-5-23 13:01
很幸运与上你们,我用vb开发solidworks,怎么写程序在solidworks里打开一个已经做好的零件啊??
很着急,希望你们能帮帮我,先跪谢了!!
作者: pyczt    时间: 2006-5-23 13:39
原帖由 iamhappyflyer 于 2006-5-23 13:01 发表
很幸运与上你们,我用vb开发solidworks,怎么写程序在solidworks里打开一个已经做好的零件啊??
很着急,希望你们能帮帮我,先跪谢了!!



80后的年轻人啊,不要动不动就跪谢跪求!

录一下宏,就得到语句,不难啊

Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Feature As Object
Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.OpenDoc6("E:\SW\counter\WENZHOU\WINDBOX.SLDPRT", 1, 0, "", longstatus, longwarnings)
'Set Part = swApp.ActivateDoc2("WINDBOX.SLDPRT", False, longstatus)
'swApp.ActiveDoc.ActiveView.FrameLeft = 0
'swApp.ActiveDoc.ActiveView.FrameTop = 0
'swApp.ActiveDoc.ActiveView.FrameState = 1
'swApp.ActiveDoc.ActiveView.FrameState = 1
'swApp.ActiveDoc.ActiveView.FrameState = 1
End Sub
作者: zlljll2005    时间: 2006-5-23 16:50
唉,想当年我的毕业论文就是这个课题
作者: iamhappyflyer    时间: 2006-5-23 22:46
好羞啊~~
真的很感谢,我问了很多人,都帮不上忙,千言万语不能表达我此刻的心情~~
就一句谢谢!!
有问题还会请教你的~~
作者: gangbeng198    时间: 2006-5-29 21:08
Sample TextSample Text

[size=-1]我的毕业设计就是利用solidworks建零件库 用vb作为开发语言,一点头绪没有,能不能指点一下,马上要交设计了,很着急,谢谢!




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3