def getCommands(self, group): cmdlist = [] cmdsubs = {} for cmd in self.commands[group]: command, subgroup = cmd if subgroup != None and GroupButtonMode > 0: if not (subgroup in cmdsubs): cmdsubs[subgroup] = [] if GroupButtonMode == 2: cmdlist.append(subgroup.replace(" ", "")) cmdlist.append("Separator") cmdsubs[subgroup].append(command) else: cmdlist.append(command) for subcommand in cmdsubs: if GroupButtonMode == 2: Gui.addCommand( subcommand.replace(" ", ""), FSGroupCommand(cmdsubs[subcommand], subcommand, subcommand)) else: cmdlist.append( (subcommand.replace(" ", ""), cmdsubs[subcommand], subcommand)) return cmdlist
def getCommands(self, group): cmdlist = [] cmdsubs = {} for cmd in self.commands[group]: command, subgroup = cmd if subgroup != None and GroupButtonMode > 0: if not(subgroup in cmdsubs): cmdsubs[subgroup] = [] if GroupButtonMode == 2: cmdlist.append(subgroup.replace(" ", "")) cmdlist.append("Separator") cmdsubs[subgroup].append(command) else: cmdlist.append(command) for subcommand in cmdsubs: if GroupButtonMode == 2: Gui.addCommand(subcommand.replace(" ", ""), FSGroupCommand(cmdsubs[subcommand], subcommand, subcommand)) else: cmdlist.append((subcommand.replace(" ", ""), cmdsubs[subcommand])) return cmdlist
import os, Silk_dummy path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join(path_Silk, 'Resources', 'Icons') class CubicCurve_4(): def Activated(self): poly = Gui.Selection.getSelection()[0] a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "CubicCurve_4") AN.CubicCurve_4(a, poly) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (1.00, 0.67, 0.00) a.ViewObject.PointSize = 2.00 a.ViewObject.PointColor = (1.00, 1.00, 0.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/CubicCurve_4.svg', 'MenuText': 'CubicCurve_4', 'ToolTip': 'CubicCurve_4: \n creates a NURBS from a ControlPoly4 object (Cubic Bezier Curve)' } Gui.addCommand('CubicCurve_4', CubicCurve_4())
doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len( Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selFace) != Part.Face: return False return True Gui.addCommand('SMMakeWall', AddWallCommandClass()) ########################################################################################### # Extrude ########################################################################################### def smExtrude(extLength=10.0, selFaceNames='', selObjectName=''): # selFace = Gui.Selection.getSelectionEx()[0].SubObjects[0] # selObjectName = Gui.Selection.getSelection()[0].Name AAD = FreeCAD.ActiveDocument MainObject = AAD.getObject(selObjectName) finalShape = MainObject.Shape for selFaceName in selFaceNames: selFace = AAD.getObject(selObjectName).Shape.getElement(selFaceName)
if hasattr(view, 'getActiveObject'): activeBody = view.getActiveObject('pdbody') if not smIsOperationLegal(activeBody, selobj): return doc.openTransaction("Bend") if activeBody is None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython", "Fold") SMFoldWall(a) SMFoldViewProvider(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython", "Fold") SMFoldWall(a) SMFoldPDViewProvider(a.ViewObject) activeBody.addObject(a) doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 2: return False # selobj = Gui.Selection.getSelection()[1] # if str(type(selobj)) != "<type 'Sketcher.SketchObject'>" : # return False return True Gui.addCommand('SMFoldWall', AddFoldWallCommandClass())
computed_parts = self.compute_parts() self.create_new_parts(self.document, computed_parts) if first_preview: FreeCADGui.getDocument(self.document.Name).ActiveView.fitAll() def init_widget(): return class MakeRoundedBoxCommand: def __init__(self): return def GetResources(self): return {'Pixmap': os.path.join(iconPath, 'roundbox.xpm'), # the name of a svg file available in the resources 'MenuText': "Rounded box", 'ToolTip': "Make rounded box without tab"} def IsActive(self): return FreeCAD.ActiveDocument is not None def Activated(self): panel = MakeRoundedBox() FreeCADGui.Control.showDialog(panel) return Gui.addCommand('make_rounded_box_command', MakeRoundedBoxCommand())
from FreeCAD import Base from FreeCAD import Gui import ArachNURBS as AN # Locate Workbench Directory import os, Silk_dummy path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join( path_Silk, 'Resources', 'Icons') class ControlGrid3Star66_3Sub(): def Activated(self): sel=Gui.Selection.getSelection() Sub_0=Gui.Selection.getSelection()[0] Sub_1=Gui.Selection.getSelection()[1] Sub_2=Gui.Selection.getSelection()[2] SubList = [Sub_0, Sub_1, Sub_2] a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ControlGrid3Star66_3Sub") AN.ControlGrid3Star66_3Sub(a,SubList) a.ViewObject.Proxy=0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (1.00,0.67,0.00) a.ViewObject.PointSize = 2.00 a.ViewObject.PointColor = (1.00,1.00,0.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return {'Pixmap' : path_Silk_icons + '/ControlGrid3Star66_3Sub.svg', 'MenuText': 'ControlGrid3Star66_3Sub', 'ToolTip': 'ControlGrid3Star66_3Sub'} Gui.addCommand('ControlGrid3Star66_3Sub', ControlGrid3Star66_3Sub())
return doc.openTransaction("Add Relief") if activeBody is None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython", "Relief") SMRelief(a) SMReliefViewProviderTree(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython", "Relief") SMRelief(a) SMReliefViewProviderFlat(a.ViewObject) activeBody.addObject(a) FreeCADGui.Selection.clearSelection() doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len( Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False # selobj = Gui.Selection.getSelection()[0] for selVertex in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selVertex) != Part.Vertex: return False return True Gui.addCommand('SMMakeRelief', AddReliefCommandClass())
def IsActive(self): selObjs = self.GetSelection() return len(selObjs) > 0 def GetSelection(self): screwObj = [] for selobj in Gui.Selection.getSelectionEx(): obj = selobj.Object #FreeCAD.Console.PrintLog("sel obj: " + str(obj) + "\n") if (hasattr(obj, 'Proxy') and isinstance(obj.Proxy, FSBaseObject)): if obj.baseObject != None: screwObj.append(obj) return screwObj Gui.addCommand('FSFlip',FSFlipCommand()) FSCommands.append('FSFlip', "command") class FSMoveCommand: """Move Screw command""" def GetResources(self): icon = os.path.join( iconPath , 'IconMove.svg') return {'Pixmap' : icon , # the name of a svg file available in the resources 'MenuText': "Move fastner" , 'ToolTip' : "Move fastner to a new location"} def Activated(self): selObj = self.GetSelection() if selObj[0] == None: return
"""Add Preass-nut command""" def GetResources(self): icon = os.path.join( iconPath , 'PEMPressNut.svg') return {'Pixmap' : icon , # the name of a svg file available in the resources 'MenuText': "Add Press-Nut" , 'ToolTip' : "Add PEM Self Clinching Metric Nut"} def Activated(self): FastenerBase.FSGenerateObjects(FSPressNutObject, "PressNut") return def IsActive(self): return Gui.ActiveDocument != None Gui.addCommand("FSPressNut", FSPressnutCommand()) FastenerBase.FSCommands.append("FSPressNut", "screws", "PEM Inserts") ################################################################################### # PEM Self Clinching standoffs types: SO/SOS/SOA/SO4 SOLengths = {'3':0, '4':0, '6':0, '8':0, '10':4, '12':4, '14':4, '16':8, '18':8, '20':8, '22':11, '25':11} #BSLengths = {'6':3.2, '8':4, '10':4, '12':5, '14':6.5, '16':6.5, '18':9.5, '20':9.5, '22':9.5, '25':9.5} SODiameters = ['Auto', 'M3', '3.5M3', 'M3.5', 'M4', 'M5' ] SOPEMTable = { # B, C, H, d, Lmin, Lmax 'M3': (3.2, 4.2, 4.8, 2.5, 3, 18), '3.5M3':(3.2, 5.39, 6.4, 2.5, 3, 25), 'M3.5': (3.9, 5.39, 6.4, 2.9, 3, 25), 'M4': (4.8, 7.12, 7.9, 3.3, 3, 25), 'M5': (5.36, 7.12, 7.9, 4.2, 3, 25)
FSScrewCalcDlg.ui.setupUi(FSScrewCalcDlg) FSScrewCalcDlg.ui.fillScrewTypes() Gui.getMainWindow().addDockWidget(QtCore.Qt.RightDockWidgetArea, FSScrewCalcDlg) FSScrewCalcDlg.setFloating(True) FSScrewCalcDlg.hide() class FSScrewCalcCommand: """Display a calculator for needed screw holes""" def GetResources(self): FreeCAD.Console.PrintLog("Getting resources\n") icon = os.path.join( iconPath , 'IconScrewCalc.svg') return {'Pixmap' : icon , # the name of a svg file available in the resources 'MenuText': "Screw calculator" , 'ToolTip' : "Show a screw hole calculator"} def Activated(self): if FSScrewCalcDlg.isHidden(): FSScrewCalcDlg.show() else: FSScrewCalcDlg.hide() return def IsActive(self): return True Gui.addCommand("FSScrewCalc", FSScrewCalcCommand()) FastenerBase.FSCommands.append("FSScrewCalc", "command")
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Bend") SMBendWall(a) SMViewProviderTree(a.ViewObject) FreeCAD.ActiveDocument.recompute() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selFace) != Part.Face: return False return True Gui.addCommand('SMMakeWall',AddWallCommandClass()) ########################################################################################### # Extrude ########################################################################################### def smExtrude(extLength = 10.0, selFaceNames = '', selObjectName = ''): # selFace = Gui.Selection.getSelectionEx()[0].SubObjects[0] # selObjectName = Gui.Selection.getSelection()[0].Name AAD = FreeCAD.ActiveDocument MainObject = AAD.getObject( selObjectName ) finalShape = MainObject.Shape for selFaceName in selFaceNames: selFace = AAD.getObject(selObjectName).Shape.getElement(selFaceName)
'MenuText': "Change fastener parameters" , 'ToolTip' : "Change parameters of selected fasteners"} def Activated(self): dlg = FSTaskChangeParamDialog(None) fstype = FastenerBase.FSFasenerTypeDB[self.type] dlg.FillFields(fstype) Gui.Control.showDialog(dlg) return def IsActive(self): sel = Gui.Selection.getSelection() if len(sel) == 0: return False self.type = None tmaxlen = 0 for typename in FastenerBase.FSFasenerTypeDB: #FreeCAD.Console.PrintLog(typename + "\n") if filter(lambda c: not c.isdigit(), sel[0].Name) == typename: self.type = typename if self.type == None: return False for obj in sel: if filter(lambda c: not c.isdigit(), obj.Name) != self.type: return False return True Gui.addCommand("FSChangeParams", FSChangeParamCommand()) FastenerBase.FSCommands.append("FSChangeParams", "command")
activeBody = None selobj = Gui.Selection.getSelectionEx()[0].Object if hasattr(view,'getActiveObject'): activeBody = view.getActiveObject('pdbody') if not smIsOperationLegal(activeBody, selobj): return doc.openTransaction("Bend") if activeBody == None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython","Fold") SMFoldWall(a) SMFoldViewProvider(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython","Fold") SMFoldWall(a) SMFoldPDViewProvider(a.ViewObject) activeBody.addObject(a) doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 2 : return False # selobj = Gui.Selection.getSelection()[1] # if str(type(selobj)) != "<type 'Sketcher.SketchObject'>" : # return False return True Gui.addCommand('SMFoldWall',AddFoldWallCommandClass())
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from __future__ import division # allows floating point division from integers import FreeCAD, Part, math from FreeCAD import Base from FreeCAD import Gui import ArachNURBS as AN # Locate Workbench Directory import os, Silk_dummy path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join( path_Silk, 'Resources', 'Icons') class CubicSurface_66(): def Activated(self): poly=Gui.Selection.getSelection()[0] a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","CubicSurface_66") AN.CubicSurface_66(a,poly) a.ViewObject.Proxy=0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.DisplayMode = u"Shaded" a.ViewObject.ShapeColor = (0.33,0.67,1.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return {'Pixmap' : path_Silk_icons + '/CubicSurface_66.svg', 'MenuText': 'CubicSurface_66', 'ToolTip': 'CubicSurface_66'} Gui.addCommand('CubicSurface_66', CubicSurface_66())
"""Add Screw Rod command""" def GetResources(self): icon = os.path.join( iconPath , 'ScrewTap.svg') return {'Pixmap' : icon , # the name of a svg file available in the resources 'MenuText': "Add Threaded Rod" , 'ToolTip' : "Add arbitrary length threaded rod"} def Activated(self): for selObj in FastenerBase.FSGetAttachableSelections(): a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","ScrewTap") FSScrewRodObject(a, selObj) a.Label = a.Proxy.itemText FSViewProviderTree(a.ViewObject) FreeCAD.ActiveDocument.recompute() return def IsActive(self): return Gui.ActiveDocument != None Gui.addCommand("FSScrewTap",FSScrewRodCommand()) FastenerBase.FSCommands.append("FSScrewTap", "screws", "misc") ## add fastener types FastenerBase.FSAddFastenerType("Screw") FastenerBase.FSAddFastenerType("Washer", False) FastenerBase.FSAddFastenerType("Nut", False) FastenerBase.FSAddFastenerType("ScrewTap", True, False) for item in ScrewMaker.screwTables: FastenerBase.FSAddItemsToType(ScrewMaker.screwTables[item][0], item)
def FSAddScrewCommand(type, help, dropGroup=None): cmd = 'FS' + type Gui.addCommand(cmd, FSScrewCommand(type, help)) FastenerBase.FSCommands.append(cmd, "screws", dropGroup)
def FSAddScrewCommand(type, help, dropGroup = None): cmd = 'FS' + type Gui.addCommand(cmd,FSScrewCommand(type, help)) FastenerBase.FSCommands.append(cmd, "screws", dropGroup)
path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join(path_Silk, 'Resources', 'Icons') class Point_onCurve(): def Activated(self): selx = Gui.Selection.getSelectionEx()[0] NL_Curve = selx.Object # this is a resilient link to the underlying object Pick = selx.PickedPoints[ 0] # this is the point where the curve was picked u = NL_Curve.Shape.Curve.parameter( Pick) # picked point is used for an initial value a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Point_onCurve") AN.Point_onCurve(a, NL_Curve, u) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.PointSize = 5.00 a.ViewObject.PointColor = (1.00, 0.00, 0.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/Point_onCurve.svg', 'MenuText': 'Point_onCurve', 'ToolTip': 'Point_onCurve: \n Create a point on a curve.' } Gui.addCommand('Point_onCurve', Point_onCurve())
if not smIsOperationLegal(activeBody, selobj): return doc.openTransaction("Corner Relief") if activeBody is None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython", "CornerRelief") SMCornerRelief(a) SMCornerReliefVP(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython", "CornerRelief") SMCornerRelief(a) SMCornerReliefPDVP(a.ViewObject) activeBody.addObject(a) doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len( Gui.Selection.getSelectionEx()[0].SubElementNames) < 2: return False # selobj = Gui.Selection.getSelection()[0] for selVertex in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selVertex) != Part.Edge: return False return True Gui.addCommand('SMCornerRelief', AddCornerReliefCommandClass())
new_parts_list = [] per_line = int(math.sqrt(len(parts_list))) for i in range(len(parts_list)): part = parts_list[i] new_part = freecad_document.addObject("Part::Feature", "test") transform_shape(part, new_part, freecad_document) bound_box = new_part.Shape.BoundBox shift_vector = FreeCAD.Vector(-bound_box.XMin + x_pos, -bound_box.YMin + y_pos, z_fix - bound_box.ZMin) x_pos += bound_box.XLength + margin new_part.Placement.Base = new_part.Placement.Base.add(shift_vector) bound_box = new_part.Shape.BoundBox freecad_document.recompute() if (bound_box.YLength + y_pos) > max_line_y: max_line_y = bound_box.YLength + y_pos if (i+1) % per_line == 0: y_pos = max_line_y + margin x_pos = 0 new_parts_list.append(new_part) Draft.makeShape2DView(new_part) freecad_document.recompute() return new_parts_list Gui.addCommand('export_command', ExportCommand())
shape = origshape for diam in fp.diameters: FreeCAD.Console.PrintLog("Generating hole tool for: " + diam + "\n") edge, m, f, o, type = cshSplitEdgeDiam(diam) cshole = cshMakeCSHole(m, type) FastenerBase.FSMoveToObject(cshole, origshape.getElement(edge), f == '1', float(o)) shape = shape.cut(cshole) fp.Shape = shape class FSFilletCommand: """Make holes for countersunk screws""" def GetResources(self): icon = os.path.join( iconPath , 'IconCSHole.svg') return {'Pixmap' : icon , # the name of a svg file available in the resources 'MenuText': "Make countersunk" , 'ToolTip' : "Chamfer holes for countersunk screws"} def Activated(self): Gui.Control.showDialog(FSTaskFilletDialog(None)) return def IsActive(self): return len(Gui.Selection.getSelectionEx()) == 1 Gui.addCommand("FSFillet", FSFilletCommand()) FastenerBase.FSCommands.append("FSFillet", "command") # to monitor selections: add SelObserver http://www.freecadweb.org/wiki/index.php?title=Code_snippets#Function_resident_with_the_mouse_click_action # to filter selections: use Gui.Selection.SelectionGate
activeBody = None selobj = Gui.Selection.getSelectionEx()[0].Object if hasattr(view,'getActiveObject'): activeBody = view.getActiveObject('pdbody') if not smIsOperationLegal(activeBody, selobj): return doc.openTransaction("SketchOnSheet") if activeBody is None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython","SketchOnSheet") SMSketchOnSheet(a) SMSketchOnSheetVP(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython","SketchOnSheet") SMSketchOnSheet(a) SMSketchOnSheetPDVP(a.ViewObject) activeBody.addObject(a) doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 2 : return False # selobj = Gui.Selection.getSelection()[1] # if str(type(selobj)) != "<type 'Sketcher.SketchObject'>" : # return False return True Gui.addCommand('SMSketchOnSheet',AddSketchOnSheetCommandClass())
from FreeCAD import Base from FreeCAD import Gui import ArachNURBS as AN # Locate Workbench Directory import os, Silk_dummy path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join(path_Silk, 'Resources', 'Icons') class CubicSurface_44(): def Activated(self): poly = Gui.Selection.getSelection()[0] a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "CubicSurface_44") AN.CubicSurface_44(a, poly) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.DisplayMode = u"Shaded" a.ViewObject.ShapeColor = (0.33, 0.67, 1.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/CubicSurface_44.svg', 'MenuText': 'CubicSurface_44', 'ToolTip': 'CubicSurface_44' } Gui.addCommand('CubicSurface_44', CubicSurface_44())
self.create_new_parts(self.preview_doc, computed_parts) if not preview_doc_exist: FreeCADGui.getDocument(self.preview_doc.Name).ActiveView.fitAll() return class MultipleCommand: def __init__(self): return def GetResources(self): return { 'Pixmap': os.path.join( iconPath, 'one_tab.xpm' ), # the name of a svg file available in the resources 'MenuText': "Slots", 'ToolTip': "Slots" } def IsActive(self): return True def Activated(self): panel = MultipleJoins() FreeCADGui.Control.showDialog(panel) return Gui.addCommand('multiple_tabs_command', MultipleCommand())
if not smIsOperationLegal(activeBody, selobj): return doc.openTransaction("Add Junction") if activeBody is None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython", "Junction") SMJunction(a) SMJViewProviderTree(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython", "Junction") SMJunction(a) SMJViewProviderFlat(a.ViewObject) activeBody.addObject(a) FreeCADGui.Selection.clearSelection() doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len( Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] for selEdge in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selEdge) != Part.Edge: return False return True Gui.addCommand('SMMakeJunction', AddJunctionCommandClass())
'/DrawStyleWireFrame.svg', # the name of a svg file available in the resources 'Accel': "Shift+S", # a default shortcut (optional) 'MenuText': "Add a frame", 'ToolTip': "Adds a D3D printer frame" } def Activated(self): "Do something here when button is clicked" FreeCAD.Console.PrintMessage("Workbench is working!") if Gui.ActiveDocument == None: FreeCAD.newDocument() # view = Gui.activeDocument().activeView() doc = FreeCAD.activeDocument() n = list() c = Part.Circle() c.Radius = 2.0 f = doc.addObject("Part::Feature", "Circle") # create a document with a circle feature f.Shape = c.toShape() # Assign the circle shape to the shape property doc.recompute() return def IsActive(self): """Here you can define if the command must be active or not (greyed) if certain conditions are met or not. This function is optional.""" return True Gui.addCommand('OSE_CommandButton', OSE_CommandButtonClass())
# Locate Workbench Directory import os, Silk_dummy path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join(path_Silk, 'Resources', 'Icons') class ControlGrid44_2EdgeSegments(): def Activated(self): surface = Gui.Selection.getSelection()[0] curve_a = Gui.Selection.getSelection()[1] curve_b = Gui.Selection.getSelection()[2] a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ControlGrid44_2EdgeSegments") AN.ControlGrid44_2EdgeSegments(a, surface, curve_a, curve_b) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (0.67, 1.00, 1.00) a.ViewObject.PointSize = 4.00 a.ViewObject.PointColor = (0.00, 0.33, 1.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/ControlGrid44_2EdgeSegments.svg', 'MenuText': 'ControlGrid44_2EdgeSegments', 'ToolTip': 'ControlGrid44_2EdgeSegments' } Gui.addCommand('ControlGrid44_2EdgeSegments', ControlGrid44_2EdgeSegments())
elif ((NL_Grid.Poles[15] - Pick).Length / test_scale) < 0.0001: Corner = 2 print('corner 2 at Grid index 15') elif ((NL_Grid.Poles[12] - Pick).Length / test_scale) < 0.0001: Corner = 3 print('corner 3 at Grid index 12') else: print( 'unable to identify which corner the grid was pick on. please select the grid by one of its corners in the 3D view' ) a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ControlGrid64_3_Grid44") AN.ControlGrid64_3_1Grid44(a, NL_Grid, Corner) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (0.67, 1.00, 1.00) a.ViewObject.PointSize = 4.00 a.ViewObject.PointColor = (0.00, 0.33, 1.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/ControlGrid64_3_1Grid44.svg', 'MenuText': 'ControlGrid64_3_1Grid44', 'ToolTip': 'ControlGrid64_3_1Grid44' } Gui.addCommand('ControlGrid64_3_1Grid44', ControlGrid64_3_1Grid44())
import ArachNURBS as AN # Locate Workbench Directory import os, Silk_dummy path_Silk = os.path.dirname(Silk_dummy.__file__) path_Silk_icons = os.path.join(path_Silk, 'Resources', 'Icons') class CubicCurve_6(): def Activated(self): poly = Gui.Selection.getSelection()[0] a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "CubicCurve_6") AN.CubicCurve_6(a, poly) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (1.00, 0.67, 0.00) a.ViewObject.PointSize = 2.00 a.ViewObject.PointColor = (1.00, 1.00, 0.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/CubicCurve_6.svg', 'MenuText': 'CubicCurve_6', 'ToolTip': 'CubicCurve_6' } Gui.addCommand('CubicCurve_6', CubicCurve_6())
s = nutMakeSolid(d) self.diameter = fp.diameter fp.Shape = s fp.Label = fp.diameter + '-Nut' else: FreeCAD.Console.PrintLog("Using cached object\n") if shape != None: #fp.Placement = FreeCAD.Placement() # reset placement FastenerBase.FSMoveToObject(fp, shape, fp.invert, fp.offset.Value) FastenerBase.FSClassIcons[FSHexNutObject] = 'HexNut.svg' class FSHexNutCommand: """Add Preass-nut command""" def GetResources(self): icon = os.path.join( iconPath , 'HexNut.svg') return {'Pixmap' : icon , # the name of a svg file available in the resources 'MenuText': "Add Hex Nut" , 'ToolTip' : "Add Metric Hexagon Nut - ISO 4032, Style 3"} def Activated(self): FastenerBase.FSGenerateObjects(FSHexNutObject, "Nut") return def IsActive(self): return Gui.ActiveDocument != None Gui.addCommand("FSHexNut", FSHexNutCommand()) #FastenerBase.FSCommands.append("FSHexNut", "screws", "Nut")
def Activated(self): for selObj in FastenerBase.FSGetAttachableSelections(): a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ScrewTap") FSScrewRodObject(a, selObj) a.Label = a.Proxy.itemText FSViewProviderTree(a.ViewObject) FreeCAD.ActiveDocument.recompute() return def IsActive(self): return Gui.ActiveDocument != None Gui.addCommand("FSScrewTap", FSScrewRodCommand()) FastenerBase.FSCommands.append("FSScrewTap", "screws", "misc") class FSScrewDieObject(FSBaseObject): def __init__(self, obj, attachTo): '''"Add screw die" ''' FSBaseObject.__init__(self, obj, attachTo) self.itemText = "ScrewDie" self.type = 'ScrewDie' diameters = screwMaker.GetAllDiams(self.type) diameters.insert(0, 'Auto') #self.Proxy = obj.Name obj.addProperty("App::PropertyEnumeration", "diameter", "Parameters", "Screw diameter standard").diameter = diameters
activeBody = view.getActiveObject('pdbody') if not smIsOperationLegal(activeBody, selobj): return doc.openTransaction("Add Bend") if activeBody is None or not smIsPartDesign(selobj): a = doc.addObject("Part::FeaturePython","SolidBend") SMSolidBend(a) SMBendViewProviderTree(a.ViewObject) else: #FreeCAD.Console.PrintLog("found active body: " + activeBody.Name) a = doc.addObject("PartDesign::FeaturePython","SolidBend") SMSolidBend(a) SMBendViewProviderFlat(a.ViewObject) activeBody.addObject(a) FreeCADGui.Selection.clearSelection() doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False # selobj = Gui.Selection.getSelection()[0] for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selFace) != Part.Edge : return False return True Gui.addCommand('SMMakeBend',AddBendCommandClass())
self.tree_vbox.addWidget(remove_item_button) # test layout self.edit_items_layout = QtGui.QVBoxLayout(self.tree_widget) self.tree_vbox.addLayout(self.edit_items_layout) class CrossPieceCommand: def __init__(self): return def GetResources(self): return {'Pixmap': os.path.join(iconPath, 'crosspiece.xpm'), # the name of a svg file available in the resources 'MenuText': "Crosspiece", 'ToolTip': "Crosspiece"} def IsActive(self): #return len(FreeCADGui.Selection.getSelection()) > 0 return True def Activated(self): panel = CrossPiece() FreeCADGui.Control.showDialog(panel) return Gui.addCommand('crosspiece', CrossPieceCommand())
return { 'Pixmap': icon, # the name of a svg file available in the resources 'MenuText': "Add Press-Nut", 'ToolTip': "Add PEM Self Clinching Metric Nut" } def Activated(self): FastenerBase.FSGenerateObjects(FSPressNutObject, "PressNut") return def IsActive(self): return Gui.ActiveDocument != None Gui.addCommand("FSPressNut", FSPressnutCommand()) FastenerBase.FSCommands.append("FSPressNut", "screws", "PEM Inserts") ################################################################################### # PEM Self Clinching standoffs types: SO/SOS/SOA/SO4 SOLengths = { '3': 0, '4': 0, '6': 0, '8': 0, '10': 4, '12': 4, '14': 4, '16': 8, '18': 8, '20': 8,
elif len(sel) == 3: mode = '3sided' if mode == '4sided': poly0 = Gui.Selection.getSelection()[0] poly1 = Gui.Selection.getSelection()[1] poly2 = Gui.Selection.getSelection()[2] poly3 = Gui.Selection.getSelection()[3] a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ControlGrid66_4") AN.ControlGrid66_4(a, poly0, poly1, poly2, poly3) a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (0.67, 1.00, 1.00) a.ViewObject.PointSize = 4.00 a.ViewObject.PointColor = (0.00, 0.33, 1.00) FreeCAD.ActiveDocument.recompute() if mode == '3sided': print 'triangle mode not implemented' def GetResources(self): return { 'Pixmap': path_Silk_icons + '/ControlGrid66.svg', 'MenuText': 'ControlGrid66', 'ToolTip': 'ControlGrid66' } Gui.addCommand('ControlGrid66', ControlGrid66())
return doc.openTransaction("Extend") if (activeBody is None): a = doc.addObject("Part::FeaturePython", "Extend") SMExtrudeWall(a) SMViewProviderTree(a.ViewObject) else: a = doc.addObject("PartDesign::FeaturePython", "Extend") SMExtrudeWall(a) SMViewProviderFlat(a.ViewObject) activeBody.addObject(a) FreeCADGui.Selection.clearSelection() doc.recompute() doc.commitTransaction() return def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len( Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] if selobj.isDerivedFrom("Sketcher::SketchObject"): return False for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selFace) == Part.Vertex: return False return True Gui.addCommand('SMExtrudeFace', SMExtrudeCommandClass())
a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (0.67,1.00,1.00) a.ViewObject.PointSize = 4.00 a.ViewObject.PointColor = (0.00,0.33,1.00) FreeCAD.ActiveDocument.recompute() ''' if mode == '3sided': poly0 = Gui.Selection.getSelection()[0] poly1 = Gui.Selection.getSelection()[1] poly2 = Gui.Selection.getSelection()[2] a = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "ControlGrid44_3_Rotate") a.ViewObject.Proxy = 0 # just set it to something different from None (this assignment is needed to run an internal notification) AN.ControlGrid44_3_Rotate(a, poly0, poly1, poly2) a.ViewObject.LineWidth = 1.00 a.ViewObject.LineColor = (0.67, 1.00, 1.00) a.ViewObject.PointSize = 4.00 a.ViewObject.PointColor = (0.00, 0.33, 1.00) FreeCAD.ActiveDocument.recompute() def GetResources(self): return { 'Pixmap': path_Silk_icons + '/WIP.svg', 'MenuText': 'ControlGrid44_Rotate', 'ToolTip': 'ControlGrid44_Rotate' } Gui.addCommand('ControlGrid44_Rotate', ControlGrid44_Rotate())
def IsActive(self): selObjs = self.GetSelection() return len(selObjs) > 0 def GetSelection(self): screwObj = [] for selobj in Gui.Selection.getSelectionEx(): obj = selobj.Object #FreeCAD.Console.PrintLog("sel obj: " + str(obj) + "\n") if (hasattr(obj, 'Proxy') and isinstance(obj.Proxy, FSBaseObject)): if obj.baseObject != None: screwObj.append(obj) return screwObj Gui.addCommand('FSFlip', FSFlipCommand()) FSCommands.append('FSFlip', "command") class FSMoveCommand: """Move Screw command""" def GetResources(self): icon = os.path.join(iconPath, 'IconMove.svg') return { 'Pixmap': icon, # the name of a svg file available in the resources 'MenuText': "Move fastner", 'ToolTip': "Move fastner to a new location" } def Activated(self):
def set_transparency(self): for obj in self.other_object_list: freecad_object = obj['obj'] freecad_object.ViewObject.Transparency = 90 def check_is_in_active_view(self): if self.active_document != FreeCAD.ActiveDocument: raise ValueError("You have to select original document") return True class MultipleCommand: def __init__(self): return def GetResources(self): return {'Pixmap': os.path.join(iconPath, 'one_tab.xpm'), # the name of a svg file available in the resources 'MenuText': "Slots", 'ToolTip': "Slots"} def IsActive(self): return True def Activated(self): panel = MultipleJoins() FreeCADGui.Control.showDialog(panel) return Gui.addCommand('multiple_tabs_command', MultipleCommand())