首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的宏不能与solidworks连接?

为什么我的宏不能与solidworks连接?
EN

Stack Overflow用户
提问于 2020-01-28 23:15:00
回答 1查看 752关注 0票数 1

昨晚我在使用excel,我的宏停止工作了。它被链接到一个solidworks文件。这个宏已经使用了3-4年,直到昨晚才有问题。

在这一行"Part.SketchManager.InsertSketch True“中,我得到了错误91,除了上次运行宏时按了error键尝试停止宏之外,没有对文件进行任何更改。这可能是也可能不是一个巧合,为什么它停止工作。我没有编写这段代码,也无法联系到该代码的人。请帮我修一下。

守则是:

代码语言:javascript
复制
Dim swApp As Object
Dim Part As Object
Dim boolStatus As Boolean
Dim longStatus As Long, longwarnings As Long
Dim conv As Double
Dim angle As Double
Dim counter As Double
Dim SelMgr As Object
Dim value As Double
Dim Feature As Object
Dim vPoint As Variant
Dim droop_Steps As Integer
Dim step_Size As Double
Dim comp_Steps As Integer
Dim front_row As Integer


Sub plotmotion()
angle = 57.2957795
conv = 0.0254

Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Dim myDimension As Object
Part.SketchManager.InsertSketch True
front_row = 1
boolStatus = Part.Extension.SelectByID2("plot", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
Part.EditSketch

For counter = 0.887 To 0 Step -0.005
    front_row = front_row + 1

    Set myDimension = Part.Parameter("Sheave Travel@plot")
    myDimension.SystemValue = counter * conv

    Excel.Range("E" & CStr(front_row)) = Part.Parameter("Sheave Travel@plot@RAMP 20-1.Part").SystemValue
    Excel.Range("I" & CStr(front_row)) = Part.Parameter("R@plot@RAMP 20-1.Part").SystemValue
    Excel.Range("F" & CStr(front_row)) = Part.Parameter("H@plot@RAMP 20-1.Part").SystemValue
    Excel.Range("G" & CStr(front_row)) = Part.Parameter("L@plot@RAMP 20-1.Part").SystemValue
    Excel.Range("H" & CStr(front_row)) = Part.Parameter("theta@plot@RAMP 20-1.Part").SystemValue * angle


Next counter
Part.SketchManager.InsertSketch True

End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-29 08:16:46

使用CreateObject(),将启动一个新的SOLIDWORKS进程,默认情况下是隐藏的。然后尝试立即使用ActiveDoc属性,但是在这个新进程中没有打开任何文档,然后下面的行将触发一个错误。有时,它是这样工作的,以连接一个已经打开的SOLIDWORKS进程--但并不总是如此!

如果您想连接到开放的SOLIDWORKS进程,则应该使用Set swApp = GetObject(, "SldWorks.Application")

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59958492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档