“快速打开零部件工程图的宏”的问题
各位大侠:想录个宏、设置成快捷键,实现无论在模型窗口选中零件的面、或在左侧区域(commandmanager区域)选中零件或装配体,再按快捷键,即可打开相应的工程图。实现此功能需先做个宏。可是不太成功。问题是:
1、报错;
2、宏里指定了零部件的名称,导致只能打开创建宏时的零件工程图。
哪位高手能否指点下该如何修改这个宏?非常感谢!
改了一下,此附件不在报错,但是打开的是创建宏时的工程图,依然不行。
再改了一下,见下,启动宏没反应,也不报错,这个是SW2020的版本的宏
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim COSMOSWORKSObj As Object
Dim CWAddinCallBackObj As Object
Set CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks")
Set COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS
boolstatus = Part.Extension.SelectByID2("B111 PLT-1@B000AAA", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
' Open
Set Part = swApp.OpenDoc6("C:\Users\COMPASSION\Desktop\宏\B111 PLT.SLDDRW", 3, 0, "", longstatus, longwarnings)
Dim swDrawing As DrawingDoc
Set swDrawing = Part
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
swApp.ActivateDoc2 "B111 PLT - 图纸1", False, longstatus
Set Part = swApp.ActiveDoc
' Redraw
Part.GraphicsRedraw2
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Set CWAddinCallBackObj = Nothing
Set COSMOSWORKSObj = Nothing
End Sub
这个是SW2016的版本的宏,就差一步就成功了,就是如何从被选的零部件获得文件名。
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Filename As String
Dim No As Integer
Dim Title As String
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Part", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Set Part = Part.Extension.SelectByID2("Part", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Filename = Part.GetPathName()
No = Len(Filename)
Filename = Left(Filename, No - 7)
Set Part = swApp.OpenDoc6(Filename & ".SLDDRW", 3, 0, "", longstatus, longwarnings)
Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameLeft = 0
myModelView.FrameTop = 0
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
Set Part = swApp.ActiveDoc
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
End Sub 矫情,有个词叫“快捷键”,操作:你把”从零件/装配体到工程图“设置一个快捷键,比如Ctrl+1。
使用方法:你点中零件,按快捷键就好了
这个功能正如2楼说得那样,把打开工程图这个命令设置成快捷键就能实现的 好东西 学习一下 零件和工程图并不是一一对应的
为啥,有配置,有出图的特殊需要
A零件可以对应工程图B,C,D。。。
所以,我觉得这个需求就不成立。。。:dizzy: 感谢楼主分享,学习了 zhufeng_hgp 发表于 2022-1-26 23:08
这个功能正如2楼说得那样,把打开工程图这个命令设置成快捷键就能实现的
你好,请问你这个是从装配体选择零件,然后打开工程图的吗?如果是可以的也帮我发一下吧,谢谢!1142163586@qq.com
已学习,多谢!
页:
[1]