-
Notifications
You must be signed in to change notification settings - Fork 75
/
makeBinderCmd.py
94 lines (74 loc) · 3.22 KB
/
makeBinderCmd.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
#!/usr/bin/env python3
# coding: utf-8
#
# makeBinderCmd.py
# creates a SubShapeBinder at the root of the assembly
#
# LGPL
# Copyright HUBERT Zoltán
import os
from PySide import QtGui, QtCore
import FreeCADGui as Gui
import FreeCAD as App
from FreeCAD import Console as FCC
import Asm4_libs as Asm4
"""
+-----------------------------------------------+
| a circular link array class and command |
+-----------------------------------------------+
"""
class makeShapeBinder():
def __init__(self):
pass
def GetResources(self):
tooltip = "Create a reference to an external shape\n"
tooltip += "This creates a SubShapeBinder of the selected shapes\n"
tooltip += "(face, edge, point) in the root assembly\n"
tooltip += "Only shapes belonging to the same part can be imported in a single step"
iconFile = os.path.join( Asm4.iconPath, 'Asm4_shapeBinder.svg' )
return {"MenuText": "Create a shape binder", "ToolTip": tooltip, "Pixmap": iconFile}
def IsActive(self):
# only do this for assembly objects and all selected shapes must be in the same part
if Asm4.getAssembly() and len(Gui.Selection.getSelection())==1:
return True
else:
return False
def Activated(self):
rootAssembly = Asm4.getAssembly()
# get the selected objects
selEx = Gui.Selection.getSelectionEx("", 0)[0].SubElementNames
for sel in selEx:
(objName,dot,shape) = sel.partition('.')
# the first element should be the name of a child in the assembly
if objName+'.' in rootAssembly.getSubObjects():
# get the object where the selected shapes are
obj = App.ActiveDocument.getObject(objName)
# this is a double-check, should always be true at this point
if obj:
shape_name = '__'+objName+'__'+shape
'''
shape = (shape,)
# we must remove the first name in each selEx element
if len(selEx)>1:
# the first one (shape) has already been done
for sel in selEx[1:]:
(objName,dot,shp) = sel.partition('.')
shape += (shp,)
shape_name += '__'+objName
'''
# now create the SubShapeBinder
binder = rootAssembly.newObject('PartDesign::SubShapeBinder', shape_name)
binder.Label = shape_name
binder.Support = [(obj, (shape,))]
binder.MakeFace = False
binder.ViewObject.LineColor = (0.,1.,0.)
binder.recompute()
"""
+-----------------------------------------------+
| test functions |
+-----------------------------------------------+
binder = App.ActiveDocument.Model.newObject('PartDesign::SubShapeBinder', 'ShapeBinder')
support = [ (sel.Object, sel.SubElementNames) for sel in Gui.Selection.getSelectionEx('', 1) ]
"""
# add the command to the workbench
Gui.addCommand('Asm4_shapeBinder', makeShapeBinder())