首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SOLIDWORKS VBA打开激活零件图

SOLIDWORKS VBA打开激活零件图
EN

Stack Overflow用户
提问于 2021-03-16 17:01:04
回答 1查看 376关注 0票数 0

我只需要使用激活零件的VBA打开图形即可。工程图始终与零件具有完全相同的文件名和位置。我得到的是

代码语言:javascript
复制
Option Explicit


Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swDocSpecification As SldWorks.DocumentSpecification

Dim sName As String

Dim longstatus As Long, longwarnings As Long



Sub main()

Set swApp = Application.SldWorks    
Set swDocSpecification = swApp.GetOpenDocSpec("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 
2017\tutorial\AutoCAD\7550-021.slddrw")

sName = swDocSpecification.FileName

swDocSpecification.DocumentType = swDocDRAWING

swDocSpecification.ReadOnly = True

swDocSpecification.Silent = False

Set swModel = swApp.OpenDoc7(swDocSpecification)

longstatus = swDocSpecification.Error

longwarnings = swDocSpecification.Warning

End Sub

但它不能工作,可能是因为文件位置,这可能总是不同的,这取决于活动部分如何命名和活动部分所在的位置。

有没有人可以分享一个函数,简单地打开零件的相关图纸?

EN

回答 1

Stack Overflow用户

发布于 2021-04-04 00:40:37

试试这个:

代码语言:javascript
复制
Option Explicit
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swDraw As SldWorks.ModelDoc2
    Dim swDocSpecification As SldWorks.DocumentSpecification
    Dim FilePath As String
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then MsgBox "Open an assembly or part": Exit Sub
    If swModel.GetType <> swDocumentTypes_e.swDocASSEMBLY And swModel.GetType <> swDocumentTypes_e.swDocPART Then MsgBox "Open an assembly or part": Exit Sub
    Set swDocSpecification = swApp.GetOpenDocSpec(swModel.GetPathName)
    FilePath = LCase(swModel.GetPathName)
    FilePath = Replace(FilePath, ".sldprt", ".slddrw")
    FilePath = Replace(FilePath, ".sldasm", ".slddrw")
    swDocSpecification.FileName = FilePath
    swDocSpecification.DocumentType = swDocumentTypes_e.swDocDRAWING
    swDocSpecification.ReadOnly = True
    swDocSpecification.Silent = True
    Set swDraw = swApp.OpenDoc7(swDocSpecification)
    swApp.ActivateDoc3 FilePath, False, swRebuildOnActivation_e.swRebuildActiveDoc, Empty
End Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66651968

复制
相关文章

相似问题

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