add partdesign toolbar
This commit is contained in:
parent
33d5f5edf8
commit
57f3d26d68
|
@ -32,7 +32,8 @@ __Status__ = 'alpha'
|
||||||
__Requires__ = 'freecad 0.16.5155'
|
__Requires__ = 'freecad 0.16.5155'
|
||||||
__Communication__ = 'vv.titov@gmail.com; DeepSOIC on FreeCAD forum'
|
__Communication__ = 'vv.titov@gmail.com; DeepSOIC on FreeCAD forum'
|
||||||
|
|
||||||
|
import lattice2InjectedToolbars as TB
|
||||||
|
TB.registerPDToolbar()
|
||||||
|
|
||||||
class Lattice2Workbench (Workbench):
|
class Lattice2Workbench (Workbench):
|
||||||
MenuText = 'Lattice2'
|
MenuText = 'Lattice2'
|
||||||
|
@ -85,7 +86,7 @@ class Lattice2Workbench (Workbench):
|
||||||
self.appendMenu('Lattice2', cmdsCompoundTools)
|
self.appendMenu('Lattice2', cmdsCompoundTools)
|
||||||
|
|
||||||
cmdsPDTools = ([]
|
cmdsPDTools = ([]
|
||||||
+ Lattice2.PartDesignFeatures.PDPattern.exportedCommands
|
+ Lattice2.PartDesignFeatures.PDPatternCommand.exportedCommands
|
||||||
)
|
)
|
||||||
self.appendToolbar('Lattice2PartDesignFeatres', cmdsPDTools)
|
self.appendToolbar('Lattice2PartDesignFeatres', cmdsPDTools)
|
||||||
self.appendMenu('Lattice2', cmdsPDTools)
|
self.appendMenu('Lattice2', cmdsPDTools)
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
import lattice2PDPattern as PDPattern
|
import lattice2PDPattern as PDPattern
|
||||||
|
import lattice2PDPatternCommand as PDPatternCommand
|
||||||
|
|
35
lattice2InjectedToolbars.py
Normal file
35
lattice2InjectedToolbars.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import FreeCAD as App
|
||||||
|
|
||||||
|
def findToolbar(name, label, workbench, create = False):
|
||||||
|
"""findToolbar(name, label, workbench, create= False): returns tuple "User parameter:BaseApp/Workbench/Global/Toolbar", "toolbar_group_name"."""
|
||||||
|
tb_root = "User parameter:BaseApp/Workbench/{workbench}/Toolbar".format(workbench= workbench)
|
||||||
|
pp = App.ParamGet(tb_root)
|
||||||
|
if pp.HasGroup(name):
|
||||||
|
return [tb_root, name]
|
||||||
|
|
||||||
|
for i in range(10):
|
||||||
|
g = 'Custom_'+str(i)
|
||||||
|
if pp.HasGroup(g) and pp.GetGroup(g).GetString('Name') == label:
|
||||||
|
return [tb_root, g]
|
||||||
|
if create:
|
||||||
|
return [tb_root, name]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def findGlobalToolbar(name, label, create = False):
|
||||||
|
return findToolbar(name, label, 'Global', create)
|
||||||
|
|
||||||
|
def findPDToolbar(name, label, create = False):
|
||||||
|
return findToolbar(name, label, 'PartDesignWorkbench', create)
|
||||||
|
|
||||||
|
def registerPDToolbar():
|
||||||
|
creating_anew = not isPDRegistered()
|
||||||
|
p = App.ParamGet('/'.join(findPDToolbar('Lattice2',"Lattice2 PartDesign", create= True)))
|
||||||
|
p.SetString("Name", "Lattice2 PartDesign")
|
||||||
|
import lattice2PDPatternCommand as PDPattern
|
||||||
|
for cmd in PDPattern.exportedCommands:
|
||||||
|
p.SetString(cmd, "FreeCAD")
|
||||||
|
if creating_anew:
|
||||||
|
p.SetBool("Active", 1)
|
||||||
|
|
||||||
|
def isPDRegistered():
|
||||||
|
return findPDToolbar('Lattice2',"Lattice2 PartDesign")
|
|
@ -357,38 +357,4 @@ def cmdPDPattern():
|
||||||
" a template body and two placements/arrays, one from selected body and one from active body."
|
" a template body and two placements/arrays, one from selected body and one from active body."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# command defined in lattice2PDPatternCommand.py
|
||||||
class CommandLatticePDPattern:
|
|
||||||
"Command to create Lattice PartDesign Pattern feature"
|
|
||||||
def GetResources(self):
|
|
||||||
return {'Pixmap' : getIconPath("Lattice2_PDPattern.svg"),
|
|
||||||
'MenuText': "Lattice PartDesign Pattern",
|
|
||||||
'Accel': "",
|
|
||||||
'ToolTip': "Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array."}
|
|
||||||
|
|
||||||
def Activated(self):
|
|
||||||
try:
|
|
||||||
if len(FreeCADGui.Selection.getSelection())==0:
|
|
||||||
infoMessage("Lattice PartDesign Pattern",
|
|
||||||
"Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array.\n\n"
|
|
||||||
"Please select features to repeat, reference placement (optional), and target placement/array. \n\n"
|
|
||||||
"You can use features from another body. Then, reference placement is required. You can also select a body (a \"template body\"), then all features from that body will be replicated.\n\n"
|
|
||||||
"Please observe scope restrictions. Reference placement must be in same body the original features are in; target placement/array must be in active body. You can create Lattice Arrays "
|
|
||||||
"right in PartDesign bodies, but you can't drag them in after the fact. You can import arrays of placements from elsewhere using a Shapebinder, or Part-o-Magic Ghost.")
|
|
||||||
return
|
|
||||||
if activeBody() is None:
|
|
||||||
infoMessage("Lattice PartDesign Pattern", "No active body. Please, activate a body, first.")
|
|
||||||
cmdPDPattern()
|
|
||||||
except Exception as err:
|
|
||||||
msgError(err)
|
|
||||||
|
|
||||||
def IsActive(self):
|
|
||||||
if FreeCAD.ActiveDocument:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if FreeCAD.GuiUp:
|
|
||||||
FreeCADGui.addCommand('Lattice2_PDPattern', CommandLatticePDPattern())
|
|
||||||
|
|
||||||
exportedCommands = ['Lattice2_PDPattern']
|
|
42
lattice2PDPatternCommand.py
Normal file
42
lattice2PDPatternCommand.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# all imports are in command's activated(), for to speed up FC startup
|
||||||
|
import FreeCAD
|
||||||
|
if FreeCAD.GuiUp:
|
||||||
|
import FreeCADGui
|
||||||
|
|
||||||
|
class CommandLatticePDPattern:
|
||||||
|
"Command to create Lattice PartDesign Pattern feature"
|
||||||
|
def GetResources(self):
|
||||||
|
import lattice2_rc
|
||||||
|
return {'Pixmap' : ":/icons/Lattice2_PDPattern.svg",
|
||||||
|
'MenuText': "Lattice PartDesign Pattern",
|
||||||
|
'Accel': "",
|
||||||
|
'ToolTip': "Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array."}
|
||||||
|
|
||||||
|
def Activated(self):
|
||||||
|
from lattice2Common import infoMessage, msgError, activeBody
|
||||||
|
from lattice2PDPattern import cmdPDPattern
|
||||||
|
try:
|
||||||
|
if len(FreeCADGui.Selection.getSelection())==0:
|
||||||
|
infoMessage("Lattice PartDesign Pattern",
|
||||||
|
"Lattice PartDesign Pattern command. Replicates partdesign features at every placement in array.\n\n"
|
||||||
|
"Please select features to repeat, reference placement (optional), and target placement/array. \n\n"
|
||||||
|
"You can use features from another body. Then, reference placement is required. You can also select a body (a \"template body\"), then all features from that body will be replicated.\n\n"
|
||||||
|
"Please observe scope restrictions. Reference placement must be in same body the original features are in; target placement/array must be in active body. You can create Lattice Arrays "
|
||||||
|
"right in PartDesign bodies, but you can't drag them in after the fact. You can import arrays of placements from elsewhere using a Shapebinder, or Part-o-Magic Ghost.")
|
||||||
|
return
|
||||||
|
if activeBody() is None:
|
||||||
|
infoMessage("Lattice PartDesign Pattern", "No active body. Please, activate a body, first.")
|
||||||
|
cmdPDPattern()
|
||||||
|
except Exception as err:
|
||||||
|
msgError(err)
|
||||||
|
|
||||||
|
def IsActive(self):
|
||||||
|
if FreeCAD.ActiveDocument:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if FreeCAD.GuiUp:
|
||||||
|
FreeCADGui.addCommand('Lattice2_PDPattern', CommandLatticePDPattern())
|
||||||
|
|
||||||
|
exportedCommands = ['Lattice2_PDPattern']
|
Loading…
Reference in New Issue
Block a user