马上注册,结交更多同行朋友,交流,分享,学习。
您需要 登录 才可以下载或查看,没有帐号?注册
x
最近在用vb对sw进行二次开发时~
总是出现对象变量或with块变量未设置
求助~~
我是要在装配体中修改零件参数
用录制宏的方法 得到了一段代码 修改后如下
Private Sub Command1_Click()
Dim f As Double
Dim b As Double
Dim l1 As Double
Dim l2 As Double
Dim h As Double
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
filename = "e:\SOLIDWORKS\MCLNR\装配体1.SLDASM"
Set swApp = CreateObject("sldworks.application")
swApp.UserControl = True
swApp.Visible = True
Set Part = swApp.OpenDoc4(filename, 1, 0, "", longstatus)
Set Part = swApp.ActivateDoc("装配体")
f = Text1.Text
b = Text2.Text
l1 = Text3.Text
h = Text4.Text
l2 = Text5.Text
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
boolstatus = Part.Extension.SelectByID2("l1@草图1@刀体-1@装配体
1", "DIMENSION", 0.009700210989324, 0.02674959445128, 0.04923612695845, False, 0, Nothing, 0)
(就是这两句,总是出现对象变量或with块变量未设置~我有把这两句删除 就变成下面出现这种情况~到底怎么回事啊~~~)
Part.Parameter("l1@草图1@刀体.Part").SystemValue = f / 1000
Part.Parameter("b@草图1@刀体.Part").SystemValue = b / 1000
Part.Parameter("l1@草图1@刀体.Part").SystemValue = l1 / 1000
Part.Parameter("d1@拉伸1@刀体.Part").SystemValue = h / 1000
Part.Parameter("h1@草图3@刀体.Part").SystemValue = h / 1000
Part.Parameter("l2@草图3@刀体.Part").SystemValue = (l2 - l1) / 1000
Part.Parameter("d1@拉伸3@刀体.Part").SystemValue = b / 1000
Part.EditRebuild
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True |