-
Notifications
You must be signed in to change notification settings - Fork 75
/
gotoDocumentCmd.py
92 lines (70 loc) · 2.55 KB
/
gotoDocumentCmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# coding: utf-8
#
# gotoDocumentCmd.py
#
# LGPL
# Copyright HUBERT Zoltán
import os
from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
import Asm4_libs as Asm4
from Asm4_Translate import translate
"""
+-----------------------------------------------+
| main class |
+-----------------------------------------------+
"""
class gotoDocumentCmd:
def __init__(self):
super(gotoDocumentCmd,self).__init__()
self.selectedLink = []
def GetResources(self):
return {"MenuText": "Open Document",
"ToolTip": translate("Commands", "Activates the document of the selected linked part"),
"Pixmap": os.path.join(Asm4.iconPath, 'Asm4_openDocument.svg')
}
def IsActive(self):
# is there an active document ?
if App.ActiveDocument and self.checkSelection() is not None:
return True
else:
return False
def checkSelection(self):
selectedLink = None
# check that 1 object is selected
if len(Gui.Selection.getSelection())==1:
selObj = Gui.Selection.getSelection()[0]
# check that the selected object is a link ...
if selObj.TypeId=='App::Link':
# ... to something in a Document ...
if hasattr(selObj.LinkedObject,'Document'):
# ... that is not the current Document
if selObj.LinkedObject.Document != App.ActiveDocument:
selectedLink = selObj
# now we should be safe
return selectedLink
"""
+-----------------------------------------------+
| the real stuff |
+-----------------------------------------------+
"""
def Activated(self):
# check what we have selected
selectedLink = self.checkSelection()
if not selectedLink:
return
linkedObj = selectedLink.LinkedObject
# in case linking to a sub-object
if isinstance(linkedObj, tuple):
linkedObj = linkedObj[0].getSubObject(linkedObj[1], retType=1)
# the non-magical command
App.setActiveDocument(linkedObj.Document.Name)
Gui.activateView('Gui::View3DInventor', True)
"""
+-----------------------------------------------+
| add the command to the workbench |
+-----------------------------------------------+
"""
Gui.addCommand( 'Asm4_gotoDocument', gotoDocumentCmd() )