forked from Zolko-123/FreeCAD_Assembly4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeLinkArray.py
154 lines (115 loc) · 4.46 KB
/
makeLinkArray.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
# coding: utf-8
#
# makeLinkArray.py
import math, re, os
from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
import Part, Draft
import libAsm4 as asm4
# see whether the Fasteners Workbench is installed
if asm4.checkWorkbench('FastenersWorkbench'):
from FastenerBase import FSBaseObject
class newLinkArray():
"""Creating a link array from Draft Workbench"""
def GetResources(self):
return {"MenuText": "New Link Array",
"ToolTip": "Create a new orthogonal or polar array from links",
"Pixmap": os.path.join(asm4.iconPath, 'Asm4_LinkArray.svg')
}
def IsActive(self):
if App.ActiveDocument:
# Only active when a App::Link is selected
selectObj = self.checkPart()
if selectObj:
return (True)
else:
return (False)
def Activated(self):
# get the selected object
selectObject = self.checkPart()
model = App.ActiveDocument.getObject('Model')
# if something valid has been returned:
if selectObject:
# Now is time to create the array
arrayName = 'array_'+selectObject.Name
#text, ok = QtGui.QInputDialog.getText(None, 'Create new Link Array', 'Enter new Link Array name: ',
# text=arrayName)
#if ok and text:
# Draft.makeArray(App.ActiveDocument.getObject(selectObject.Name), App.Vector(1, 0, 0),
# App.Vector(0, 1, 0), 2, 2, useLink=True, name=text)
createdArray = Draft.makeArray(App.ActiveDocument.getObject(selectObject.Name), App.Vector(10, 0, 0),
App.Vector(0, 1, 0), 2, 1, useLink=True, name=arrayName)
model.addObject(createdArray)
createdArray.recompute()
model.recompute()
App.ActiveDocument.recompute()
def checkPart(self):
selectedObj = None
# check that it's an Assembly4 'Model'
if App.ActiveDocument.getObject('Model') and App.ActiveDocument.getObject('Model').TypeId=='App::Part':
if Gui.Selection.getSelection():
selection = Gui.Selection.getSelection()[0]
# Only create arrays of links ...
if selection.TypeId == 'App::Link':
selectedObj = selection
else:
# ... and Ffasteners from the FastenersWorkbench
for selObj in Gui.Selection.getSelectionEx():
obj = selObj.Object
if (hasattr(obj,'Proxy') and isinstance(obj.Proxy, FSBaseObject)):
selectedObj = obj
# return what we have found
return selectedObj
#---------------------------------------------------------------------------
# Python Features definitions
# from Draft/Draft.py
#---------------------------------------------------------------------------
class _DraftObject:
"""The base class for Draft objects"""
def __init__(self,obj,tp="Unknown"):
if obj:
obj.Proxy = self
self.Type = tp
def __getstate__(self):
return self.Type
def __setstate__(self,state):
if state:
self.Type = state
def execute(self,obj):
pass
def onChanged(self, obj, prop):
pass
class _ViewProviderDraftLink:
"a view provider for link type object"
def __init__(self,vobj):
self.Object = vobj.Object
vobj.Proxy = self
def attach(self,vobj):
self.Object = vobj.Object
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def getIcon(self):
tp = self.Object.Proxy.Type
if tp == 'Array':
return ":/icons/Draft_LinkArray.svg"
elif tp == 'PathArray':
return ":/icons/Draft_PathLinkArray.svg"
def claimChildren(self):
obj = self.Object
if hasattr(obj,'ExpandArray'):
expand = obj.ExpandArray
else:
expand = obj.ShowElement
if not expand:
return [obj.Base]
else:
return obj.ElementList
#---------------------------------------------------------------------------
# end
#---------------------------------------------------------------------------
# add the command to the workbench
Gui.addCommand('Asm4_makeLinkArray', makeLinkArray())