2
Set swDocument = Application.SldWorks.ActiveDoc
Set Sheet = swDocument.GetCurrentSheet
MySheet = Sheet.GetName
MyPath = swDocument.GetPathName
Const swSelNOTES = 15

我正在使用 Solidworks 2010 宏并尝试将其更新到 Solidworks 2013,似乎他们已经删除/折旧了该GetCurrentSheet属性,Application.SldWorks.ActiveDoc有人知道当前的获取方法吗?

4

1 回答 1

3

据我记忆和所知,ModelDoc2对象上从来没有GetCurrentSheet方法,它实际上是DrawingDoc类型的方法。

因此,阅读您的代码,我认为ActiveDoc不是DrawingDoc。可以肯定的是,只需使用:

Dim swApp       as SldWorks
Dim swDrawing   as DrawingDoc
Dim swDocument  as ModelDoc2

Set swApp      = Application.SldWorks
Set swDocument = swApp.ActiveDoc 
Set swDrawing  = swDocument

If swDrawing is Nothing Then
   MsgBox "No valid drawing doc!"
   Exit Sub
End If

或者

Dim swApp       as SldWorks
Dim swDrawing   as DrawingDoc
Dim swDocument  as ModelDoc2

Set swApp      = Application.SldWorks
Set swDocument = swApp.ActiveDoc 

If swDocument.GetType() <> swDocumentTypes_e.swDocDRAWING Then
   MsgBox "No valid drawing doc!"
   Exit Sub
Else 
    Set swDrawing  = swDocument
End If

你知道是否是这种情况。我还建议您查看 API 文档中的以下附加信息:

http://help.solidworks.com/2013/English/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.idrawingdoc~getcurrentsheet.html

http://help.solidworks.com/2013/English/api/sldworksapi/Get_and_Set_Sheet_Properties_Example_VB.htm

于 2014-01-19T14:26:02.403 回答