『求助』利用vb对solidworks二次开发中的零件尺寸如何改
浏览:60618 回答:1
Private Sub Command1_Click()
Dim swapp As Object
Dim newpart As Object
Dim part As Object
Dim strfilename As String
Dim longstatus As Long
Dim d1 As Integer
Dim d2 As Integer
Dim h As Single
Set swapp = CreateObject("sldworks.application")
swapp.Visible = ture
Set newpart = swapp.NewDocument("E:\program files\solidworks\data\templates\零件.prtdot", 0, 0#, 0#)
Set newpart = swapp.ActivateDoc("part1")
Set swapp = CreateObject("Sldworks.application")
swapp.Visible = True
Set swapp = Nothing
If Dir(strfilename) = "" Then
MsgBox ("文件不存在,请检查路径:" & vbCrLf & strfilename)
Exit Sub
End If
strfilename = "F:\solidworkszuoye\垫圈.sldprt"
Set swapp = CreateObject("sldworks.application")
swapp.Visible = True
Set part = swapp.OpenDoc4(strfilename, 1, 0, "", longstatus)
Set part = swapp.ActivateDoc("垫圈")
Set part = Nothing
Set swapp = Nothing
If Dir(strfilename) = "" Then
MsgBox ("文件不存在,请检查路径:" & vbCrLf & strfilename)
Exit Sub
End If
strfilename = App.Path + "\" + "垫圈.sldprt"
Set swapp = CreateObject("sldworks.application")
swapp.Visible = True
Set part = swapp.OpenDoc4(strfilename, 1, 0, "", longstatus)
Set part = swapp.ActivateDoc("垫圈")
ProgressBar1.Value = 4
d1 = Text1.Text
d2 = Text2.Text
h = Text3.Text
Debug.Print d1, d2, h
strfilename = "@垫圈.sldprt"
part.Parameter("d1@草图1" & strfilename).SystemValue = d1 / 1000
part.Parameter("d2@草图1" & strfilename).SystemValue = d2 / 1000
part.Parameter("h@拉伸1" & strfilename).SystemValue = h / 1000
part.EditRebuild
ProgressBar1.Value = 9
Set part = Nothing
Set swapp = Nothing
ProgressBar1.Value = 100
End Sub
总是出现对象变量或者with块变量未设置
part.Parameter("d1@草图1" & strfilename).SystemValue = d1 / 1000
这个在VB里修改solidworks中的垫圈尺寸,有什么问题呢?
Dim swapp As Object
Dim newpart As Object
Dim part As Object
Dim strfilename As String
Dim longstatus As Long
Dim d1 As Integer
Dim d2 As Integer
Dim h As Single
Set swapp = CreateObject("sldworks.application")
swapp.Visible = ture
Set newpart = swapp.NewDocument("E:\program files\solidworks\data\templates\零件.prtdot", 0, 0#, 0#)
Set newpart = swapp.ActivateDoc("part1")
Set swapp = CreateObject("Sldworks.application")
swapp.Visible = True
Set swapp = Nothing
If Dir(strfilename) = "" Then
MsgBox ("文件不存在,请检查路径:" & vbCrLf & strfilename)
Exit Sub
End If
strfilename = "F:\solidworkszuoye\垫圈.sldprt"
Set swapp = CreateObject("sldworks.application")
swapp.Visible = True
Set part = swapp.OpenDoc4(strfilename, 1, 0, "", longstatus)
Set part = swapp.ActivateDoc("垫圈")
Set part = Nothing
Set swapp = Nothing
If Dir(strfilename) = "" Then
MsgBox ("文件不存在,请检查路径:" & vbCrLf & strfilename)
Exit Sub
End If
strfilename = App.Path + "\" + "垫圈.sldprt"
Set swapp = CreateObject("sldworks.application")
swapp.Visible = True
Set part = swapp.OpenDoc4(strfilename, 1, 0, "", longstatus)
Set part = swapp.ActivateDoc("垫圈")
ProgressBar1.Value = 4
d1 = Text1.Text
d2 = Text2.Text
h = Text3.Text
Debug.Print d1, d2, h
strfilename = "@垫圈.sldprt"
part.Parameter("d1@草图1" & strfilename).SystemValue = d1 / 1000
part.Parameter("d2@草图1" & strfilename).SystemValue = d2 / 1000
part.Parameter("h@拉伸1" & strfilename).SystemValue = h / 1000
part.EditRebuild
ProgressBar1.Value = 9
Set part = Nothing
Set swapp = Nothing
ProgressBar1.Value = 100
End Sub
总是出现对象变量或者with块变量未设置
part.Parameter("d1@草图1" & strfilename).SystemValue = d1 / 1000
这个在VB里修改solidworks中的垫圈尺寸,有什么问题呢?