Python FreeCAD.getDocument() Examples
The following are 30
code examples of FreeCAD.getDocument().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
FreeCAD
, or try the search function
.
Example #1
Source File: bezierCurve.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def getGeomPoint(self): obj = FreeCAD.getDocument(self.snapShape[0]).getObject(self.snapShape[1]) FreeCAD.Console.PrintMessage('%s\n'%str(self.snapShape)) if 'Vertex' in self.snapShape[2]: n = eval(self.snapShape[2].lstrip('Vertex')) shape = obj.Shape.Vertexes[n-1] if 'Point' in self.snapShape[2]: # Datum Point shape = obj.Shape elif 'Edge' in self.snapShape[2]: n = eval(self.snapShape[2].lstrip('Edge')) shape = obj.Shape.Edges[n-1] elif 'Face' in self.snapShape[2]: n = eval(self.snapShape[2].lstrip('Face')) shape = obj.Shape.Faces[n-1] v = Part.Vertex(self.point) dist, pts, sols = v.distToShape(shape) if len(pts) == 2: self.point = pts[1]
Example #2
Source File: Animation.py From Animation with GNU General Public License v2.0 | 6 votes |
def createStyler(name='MyStyler'): obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name) obj.addProperty("App::PropertyInteger","start","Base","start").start=10 obj.addProperty("App::PropertyInteger","end","Base","end").end=40 obj.addProperty("App::PropertyInteger","duration","Base","end") # obj.addProperty("App::PropertyFloat","va","intervall","va").va=0 # obj.addProperty("App::PropertyFloat","ve","intervall","ve").ve=40 obj.addProperty("App::PropertyLink","obj","Object","Objekt") # obj.addProperty("App::PropertyInteger","nr","Object","nummer Datum").nr=1# # obj.addProperty("App::PropertyEnumeration","unit","3D Param","einheit").unit=['deg','mm'] # FreeCADGui.getDocument("Unnamed").getObject("Box").Transparency = 2 obj.addProperty("App::PropertyBool","transparency","Transparency","start").transparency=False obj.addProperty("App::PropertyInteger","transpaStart","Transparency","start").transpaStart=0 obj.addProperty("App::PropertyInteger","transpaEnd","Transparency","end").transpaEnd=40 obj.addProperty("App::PropertyEnumeration","DisplayStyle","Transparency","end").DisplayStyle=['Flat Lines','Shaded','Wireframe'] obj.addProperty("App::PropertyBool","visibility","Visibility","toggle visibility").visibility=False # obj.addProperty("App::PropertyInteger","transpaStart","transparency","start").transpaStart=0 # obj.addProperty("App::PropertyInteger","transpaEnd","transparency","end").transpaEnd=40 _Styler(obj) _ViewProviderStyler(obj.ViewObject) return obj
Example #3
Source File: Commands.py From NodeEditor with MIT License | 6 votes |
def test_AA(): import FreeCAD import FreeCADGui App=FreeCAD Gui=FreeCADGui ### Begin command Std_RecentFiles try: App.closeDocument('Unnamed') except: pass App.setActiveDocument("") App.ActiveDocument=None Gui.ActiveDocument=None FreeCAD.open(u"/home/thomas/Schreibtisch/move_2.FCStd") App.setActiveDocument("move_2") App.ActiveDocument=App.getDocument("move_2") Gui.ActiveDocument=Gui.getDocument("move_2") ### End command Std_RecentFiles loadGraph()
Example #4
Source File: Shared.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
def clearActiveDocument(): """Clears the currently active 3D view so that we can re-render""" # Grab our code editor so we can interact with it mw = FreeCADGui.getMainWindow() mdi = mw.findChild(QtGui.QMdiArea) currentWin = mdi.currentSubWindow() if currentWin == None: return winName = currentWin.windowTitle().split(" ")[0].split('.')[0] # Translate dashes so that they can be safetly used since theyare common if '-' in winName: winName= winName.replace('-', "__") try: doc = FreeCAD.getDocument(winName) # Make sure we have an active document to work with if doc is not None: for obj in doc.Objects: doc.removeObject(obj.Name) except: pass
Example #5
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def addSelection(self,doc,obj,sub,pnt): lastSel=FreeCAD.getDocument(doc).getObject(obj) subLastSel=lastSel.Shape.getElement(sub) if subLastSel.ShapeType=="Edge": self.edges.append(subLastSel) FreeCAD.Console.PrintMessage('Edge'+str(len(self.edges))+' OK.\n') if len(self.edges)==2: try: FreeCAD.activeDocument().openTransaction('rotJoin') frameCmd.rotjoinTheBeam() FreeCAD.activeDocument().commitTransaction() FreeCAD.activeDocument().recompute() FreeCAD.Console.PrintWarning("Edges aligned.\n") except: FreeCAD.Console.PrintError("Edges must be selected holding [Ctrl] down for the correct execution. \nRetry.\n") self.edges=[] FreeCADGui.Selection.clearSelection() FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")
Example #6
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def addSelection(self,doc,obj,sub,pnt): lastSel=FreeCAD.getDocument(doc).getObject(obj) subLastSel=lastSel.Shape.getElement(sub) if lastSel.TypeId=='Part::FeaturePython' and hasattr(lastSel,"Height") and subLastSel.ShapeType=="Edge": self.edges.append(subLastSel) self.beams.append(lastSel) FreeCAD.Console.PrintMessage('Edge/beam pair nr.'+str(len(self.edges))+' selected.\n') if (len(self.edges)==len(self.beams)==2): if frameCmd.isOrtho(*self.edges): self.beams.reverse() FreeCAD.ActiveDocument.openTransaction('Adjust angle') for i in range(len(self.edges)): frameCmd.extendTheBeam(self.beams[i],self.edges[i]) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.Console.PrintWarning("Adjustment executed.\n") else: FreeCAD.Console.PrintError("Edges must be orthogonal.\n") self.edges=[] self.beams=[] FreeCADGui.Selection.clearSelection() FreeCAD.activeDocument().recompute() FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")
Example #7
Source File: multiplejoins.py From LCInterlocking with GNU Lesser General Public License v2.1 | 5 votes |
def preview(self, fp): if fp.preview != PREVIEW_NONE: fast = False if fp.preview == PREVIEW_FAST: fast = True fp.preview = PREVIEW_NONE document = fp.Document preview_doc_name = str(fp.Name) + "_preview_parts" new_doc = False try: preview_doc = FreeCAD.getDocument(preview_doc_name) objs = preview_doc.Objects for obj in objs: preview_doc.removeObject(obj.Name) except: new_doc = True preview_doc = FreeCAD.newDocument(preview_doc_name) parts = [] tabs = [] for part in fp.parts.lst: cp_part = copy.deepcopy(part) freecad_obj = document.getObject(cp_part.name) cp_part.recomputeInit(freecad_obj) parts.append(cp_part) for tab in fp.faces.lst: cp_tab = copy.deepcopy(tab) freecad_obj = document.getObject(cp_tab.freecad_obj_name) freecad_face = document.getObject(cp_tab.freecad_obj_name).Shape.getElement(cp_tab.face_name) cp_tab.recomputeInit(freecad_obj, freecad_face) tabs.append(cp_tab) computed_parts = make_tabs_joins(parts, tabs) for part in computed_parts: new_shape = preview_doc.addObject("Part::Feature", part.get_new_name()) new_shape.Shape = part.get_shape(fast) preview_doc.recompute() if new_doc: FreeCADGui.getDocument(preview_doc.Name).ActiveView.fitAll()
Example #8
Source File: gui.py From FreeCAD_assembly3 with GNU General Public License v3.0 | 5 votes |
def setElementVisible(self,docname,objname,subname,vis,presel=False): if FreeCAD.isRestoring(): self.resetElementVisible() return if not AsmCmdManager.AutoElementVis \ or (self.viewParam and self.viewParam.GetBool('ShowSelectionOnTop',False)): self.elements.clear() return doc = FreeCAD.getDocument(docname) if not doc: return obj = doc.getObject(objname) if not obj: return key = (docname,objname,subname) val = None if not vis: val = self.elements.get(key,None) if val is None or (presel and val): return if logger.catchWarn('',self._setElementVisible, obj,subname,vis) is False and presel: return if not vis: self.elements.pop(key,None) elif not presel: self.elements[key] = True else: self.elements.setdefault(key,False)
Example #9
Source File: crosspiece.py From LCInterlocking with GNU Lesser General Public License v2.1 | 5 votes |
def preview(self, fp): if fp.preview != PREVIEW_NONE: fp.preview = PREVIEW_NONE document = fp.Document preview_doc_name = str(fp.Name) + "_preview_parts" new_doc = False try: preview_doc = FreeCAD.getDocument(preview_doc_name) objs = preview_doc.Objects for obj in objs: preview_doc.removeObject(obj.Name) except: new_doc = True preview_doc = FreeCAD.newDocument(preview_doc_name) parts = [] tabs = [] for part in fp.parts.lst: cp_part = copy.deepcopy(part) freecad_obj = document.getObject(cp_part.name) cp_part.recomputeInit(freecad_obj) parts.append(cp_part) computed_parts = make_cross_parts(parts) for part in computed_parts: new_shape = preview_doc.addObject("Part::Feature", part.get_new_name()) new_shape.Shape = part.get_shape() preview_doc.recompute() if new_doc: FreeCADGui.getDocument(preview_doc.Name).ActiveView.fitAll()
Example #10
Source File: cq_cad_tools.py From kicad-3d-models-in-freecad with GNU General Public License v2.0 | 5 votes |
def saveFCdoc(App, Gui, doc, modelName,dir, saving = True): ## Save to disk in native format App.ActiveDocument=None Gui.ActiveDocument=None App.setActiveDocument(doc.Name) App.ActiveDocument=App.getDocument(doc.Name) Gui.ActiveDocument=Gui.getDocument(doc.Name) ## outdir=os.path.dirname(os.path.realpath(__file__))+dir outdir=dir #FreeCAD.Console.PrintMessage('\r\n'+outdir) FCName=outdir+os.sep+modelName+'.FCStd' #FreeCAD.Console.PrintMessage('\r\n'+FCName+'\r\n') App.getDocument(doc.Name).saveAs(FCName) App.ActiveDocument.recompute() App.getDocument(doc.Name).Label = doc.Name Gui.SendMsgToActiveView("Save") App.getDocument(doc.Name).save() try: os.remove(outdir+os.sep+modelName+'.FCStd1') #removing backup file except Exception as exp: FreeCAD.Console.PrintWarning("Error while trying to remove backup file in saveFCdoc:") FreeCAD.Console.PrintWarning('{:s}\n'.format(str(exp))) if saving == False: try: os.remove(outdir+os.sep+modelName+'.FCStd') #removing project file except Exception as exp: FreeCAD.Console.PrintWarning("Error while trying to remove file in saveFCdoc (with save == False):") FreeCAD.Console.PrintWarning('{:s}\n'.format(exp)) else: FreeCAD.Console.PrintMessage(outdir+os.sep+modelName+'.FCStd saved\n') return 0 ################################################################### # checkRequirements() maui # Function to check FC and CQ minimum versions # ###################################################################
Example #11
Source File: cq_cad_tools.py From kicad-3d-models-in-freecad with GNU General Public License v2.0 | 5 votes |
def z_RotateObject(doc, rot): # z-Rotate objs=GetListOfObjects(FreeCAD, doc) FreeCAD.getDocument(doc.Name).getObject(objs[0].Name).Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),rot)) return 0 ################################################################### # exportSTEP() maui # Function to Export to STEP # ###################################################################
Example #12
Source File: cq_cad_tools.py From kicad-3d-models-in-freecad with GNU General Public License v2.0 | 5 votes |
def multiFuseObjs_wColors(App, Gui, docName, objs, keepOriginals=False): # Fuse two objects App.ActiveDocument=None Gui.ActiveDocument=None App.setActiveDocument(docName) App.ActiveDocument=App.getDocument(docName) Gui.ActiveDocument=Gui.getDocument(docName) App.activeDocument().addObject("Part::MultiFuse","Fusion") App.activeDocument().Fusion.Shapes = objs Gui.ActiveDocument.Fusion.ShapeColor=Gui.ActiveDocument.getObject(objs[0].Name).ShapeColor Gui.ActiveDocument.Fusion.DisplayMode=Gui.ActiveDocument.getObject(objs[0].Name).DisplayMode App.ActiveDocument.recompute() App.ActiveDocument.addObject('Part::Feature','Fusion').Shape=App.ActiveDocument.Fusion.Shape App.ActiveDocument.ActiveObject.Label=docName fused_obj = App.ActiveDocument.ActiveObject Gui.ActiveDocument.ActiveObject.ShapeColor=Gui.ActiveDocument.Fusion.ShapeColor Gui.ActiveDocument.ActiveObject.LineColor=Gui.ActiveDocument.Fusion.LineColor Gui.ActiveDocument.ActiveObject.PointColor=Gui.ActiveDocument.Fusion.PointColor Gui.ActiveDocument.ActiveObject.DiffuseColor=Gui.ActiveDocument.Fusion.DiffuseColor App.ActiveDocument.recompute() # Remove the part1 part2 objects if not keepOriginals: for o in objs: App.getDocument(docName).removeObject(o.Name) # Remove the fusion itself App.getDocument(docName).removeObject("Fusion") return fused_obj ################################################################### # FuseObjs_wColors_naming() maui # Function to fuse two objects together. ###################################################################
Example #13
Source File: cq_cad_tools.py From kicad-3d-models-in-freecad with GNU General Public License v2.0 | 5 votes |
def multiFuseObjs_wColors(App, Gui, docName, objs, keepOriginals=False): # Fuse two objects App.ActiveDocument=None Gui.ActiveDocument=None App.setActiveDocument(docName) App.ActiveDocument=App.getDocument(docName) Gui.ActiveDocument=Gui.getDocument(docName) App.activeDocument().addObject("Part::MultiFuse","Fusion") App.activeDocument().Fusion.Shapes = objs Gui.ActiveDocument.Fusion.ShapeColor=Gui.ActiveDocument.getObject(objs[0].Name).ShapeColor Gui.ActiveDocument.Fusion.DisplayMode=Gui.ActiveDocument.getObject(objs[0].Name).DisplayMode App.ActiveDocument.recompute() App.ActiveDocument.addObject('Part::Feature','Fusion').Shape=App.ActiveDocument.Fusion.Shape App.ActiveDocument.ActiveObject.Label=docName fused_obj = App.ActiveDocument.ActiveObject Gui.ActiveDocument.ActiveObject.ShapeColor=Gui.ActiveDocument.Fusion.ShapeColor Gui.ActiveDocument.ActiveObject.LineColor=Gui.ActiveDocument.Fusion.LineColor Gui.ActiveDocument.ActiveObject.PointColor=Gui.ActiveDocument.Fusion.PointColor Gui.ActiveDocument.ActiveObject.DiffuseColor=Gui.ActiveDocument.Fusion.DiffuseColor App.ActiveDocument.recompute() # Remove the part1 part2 objects if not keepOriginals: for o in objs: App.getDocument(docName).removeObject(o.Name) # Remove the fusion itself fusedObj = App.ActiveDocument.ActiveObject SimpleCopy_wColors(fusedObj) FreeCAD.ActiveDocument.removeObject(fusedObj.Name) fused_obj = App.ActiveDocument.ActiveObject return fused_obj ################################################################### # FuseObjs_wColors() poeschlr # Function to fuse multible objects together. ###################################################################
Example #14
Source File: cq_cad_tools.py From kicad-3d-models-in-freecad with GNU General Public License v2.0 | 5 votes |
def close_CQ_Example(App, Gui): #close the example App.setActiveDocument("Ex000_Introduction") App.ActiveDocument=App.getDocument("Ex000_Introduction") Gui.ActiveDocument=Gui.getDocument("Ex000_Introduction") App.closeDocument("Ex000_Introduction") FreeCAD.Console.PrintMessage('\r\nEx000 Closed\r\n') #Getting the main window will allow us to start setting things up the way we want mw = FreeCADGui.getMainWindow() #Adjust the docks as usual dockWidgets = mw.findChildren(QtGui.QDockWidget) for widget in dockWidgets: if (widget.objectName() == "Report view") or (widget.objectName() == "Python console") or (widget.objectName() == "Combo View"): widget.setVisible(True) if (widget.objectName()=="cqCodeView"): widget.setVisible(False) FreeCAD.Console.PrintMessage('Dock adjusted\r\n') return 0 ################################################################### # FuseObjs_wColors() maui # Function to fuse two objects together. ###################################################################
Example #15
Source File: a2plib.py From A2plus with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, docName, objName, sub): self.Document = FreeCAD.getDocument(docName) self.ObjectName = objName self.Object = self.Document.getObject(objName) self.SubElementNames = [sub] #------------------------------------------------------------------------------
Example #16
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def addSelection(self,doc,obj,sub,pnt): subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub) if subObject.ShapeType=="Edge": self.edges.append(subObject) FreeCAD.Console.PrintMessage("Edge"+str(len(self.edges))+" OK\n") if len(self.edges)>1: sel=FreeCADGui.Selection.getSelection() beam=sel[len(sel)-1] FreeCAD.activeDocument().openTransaction('joinTheBeamsEdges') frameCmd.joinTheBeamsEdges(beam,self.edges[0],self.edges[1]) FreeCAD.activeDocument().commitTransaction() FreeCAD.Console.PrintMessage('Done.\n') self.edges=[] FreeCAD.Console.PrintWarning('Select other edges or [ESC] to exit\n')
Example #17
Source File: gui.py From FreeCAD_assembly3 with GNU General Public License v3.0 | 5 votes |
def resetElementVisible(self): elements = list(self.elements) self.elements.clear() for docname,objname,subname in elements: doc = FreeCAD.getDocument(docname) if not doc: continue obj = doc.getObject(objname) if not obj: continue logger.catchWarn('',self._setElementVisible,obj,subname,False)
Example #18
Source File: property_editor.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def set_prop(self,data): docname = self.fp.Document.Name objname = self.fp.Name st = "FreeCAD.getDocument('"+docname+"').getObject('"+objname+"')."+self.prop+"="+str(data) FreeCADGui.doCommand(st)
Example #19
Source File: import3DM.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def insert(filename,docname): "called when freecad imports a file" global doc groupname = os.path.splitext(os.path.basename(filename))[0] try: doc=FreeCAD.getDocument(docname) except NameError: doc=FreeCAD.newDocument(docname) if filename.lower().endswith('.3dm'): process3DM(doc,filename)
Example #20
Source File: bezierCurve-selection.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def setPreselection(self,doc,obj,sub): snapObj = FreeCAD.getDocument(doc).getObject(obj) if 'Vertex' in sub: n = eval(sub.lstrip('Vertex')) self.snapShape = snapObj.Shape.Vertexes[n-1] elif 'Edge' in sub: n = eval(sub.lstrip('Edge')) self.snapShape = snapObj.Shape.Edges[n-1] elif 'Face' in sub: n = eval(sub.lstrip('Face')) self.snapShape = snapObj.Shape.Faces[n-1]
Example #21
Source File: nurbs_surface_match.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def old_main(): doc = App.getDocument("Gordon_1") appro = doc.getObject("Approximation_Curve") appface = appro.Shape.Face1 ruled = doc.getObject("Ruled_Surface") rulface = ruled.Shape.Face1 r1 = ruled.Shape.Edge1 r2 = ruled.Shape.Edge2 surf1 = appface.Surface.copy() surf2 = rulface.Surface.copy() matchUDegree( surf1, surf2) matchURange( surf1, surf2) matchVDegree( surf1, surf2) matchVRange( surf1, surf2) matchUknots( surf1, surf2) matchVknots( surf1, surf2) matchUMults( surf1, surf2) matchVMults( surf1, surf2) # Now, the 2 surfaces should have identical topologies (same degrees, knots, mults) # Only their poles, weights are different #print(surf1.getPoles()[0]) #print(surf2.getPoles()[0]) surf1.exchangeUV() surf2.exchangeUV() l = len(surf1.getPoles()) surf1.setPoleRow(1,surf2.getPoles()[0]) surf1.setPoleRow(l,surf2.getPoles()[-1]) Part.show(surf1.toShape()) #Part.show(surf2.toShape())
Example #22
Source File: nurbs_surface_match.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def main(): doc = FreeCAD.getDocument("Gordon_1") loft = doc.getObject("Loft") profloft = loft.Shape.Face1 inter = doc.getObject("Shape") interpts = inter.Shape.Face1 loft2 = doc.getObject("Ruled_Surface") railloft = loft2.Shape.Face1 surf1 = profloft.Surface.copy() surf2 = railloft.Surface.copy() surf3 = interpts.Surface.copy() surf1.exchangeUV() matchSurfaces(surf1, surf2) matchSurfaces(surf2, surf3) matchSurfaces(surf3, surf1) checkPoles([surf1,surf2,surf3]) # Now, the 3 surfaces should have identical topologies (same degrees, knots, mults) # Only their poles, weights are different poles1 = addPoles(surf1.getPoles(), surf2.getPoles()) poles2 = subPoles(poles1, surf3.getPoles()) gordon = surf1.copy() for i in range(len(poles2)): gordon.setPoleRow(i+1, poles2[i]) Part.show(surf1.toShape()) Part.show(surf2.toShape()) Part.show(surf3.toShape()) Part.show(gordon.toShape())
Example #23
Source File: Commands.py From NodeEditor with MIT License | 5 votes |
def loadAll(): showPyFlow() try: FreeCAD.getDocument(fn) except: FreeCAD.open(u"/home/thomas/{}.FCStd".format(fn)) FreeCAD.setActiveDocument(fn) FreeCAD.ActiveDocument=FreeCAD.getDocument(fn) FreeCADGui.ActiveDocument=FreeCADGui.getDocument(fn) loadGraph() pass
Example #24
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def addSelection(self,doc,obj,sub,pnt): if self.beam==None and FreeCAD.getDocument(doc).getObject(obj).TypeId=='Part::FeaturePython': self.beam=FreeCAD.getDocument(doc).getObject(obj) FreeCAD.Console.PrintMessage('Beam type selected.\n') else: subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub) if subObject.ShapeType=="Edge" and self.beam!=None: frameCmd.placeTheBeam(FreeCAD.activeDocument().copyObject(self.beam,True),subObject)
Example #25
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def addSelection(self,doc,obj,sub,pnt): subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub) if subObject.ShapeType=="Face": if self.targetFace==None: self.targetFace=subObject FreeCAD.Console.PrintMessage('Target face selected.\n') else: beam=FreeCAD.getDocument(doc).getObject(obj) FreeCAD.activeDocument().openTransaction('levelTheBeam') frameCmd.levelTheBeam(beam,[self.targetFace,subObject]) FreeCAD.activeDocument().commitTransaction() FreeCAD.Console.PrintMessage('Face moved.\n') FreeCAD.Console.PrintWarning('Select another face or press [ESC].\n')
Example #26
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def addSelection(self,doc,obj,sub,pnt): subObject=FreeCAD.getDocument(doc).getObject(obj).Shape.getElement(sub) if subObject.ShapeType=="Face": if self.faceBase==None: self.faceBase=subObject FreeCAD.Console.PrintMessage('Target face selected.\n') else: FreeCAD.activeDocument().openTransaction('alignFlange') frameCmd.rotTheBeam(FreeCAD.getDocument(doc).getObject(obj),self.faceBase,subObject) FreeCAD.activeDocument().commitTransaction()
Example #27
Source File: frameObservers.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def addSelection(self,doc,obj,sub,pnt): Obj=FreeCAD.getDocument(doc).getObject(obj) if self.beam==None and Obj.TypeId=='Part::FeaturePython' and hasattr(Obj,'Height'): self.beam=Obj FreeCAD.Console.PrintMessage('Beam type selected.\n') from PySide.QtGui import QInputDialog as qid dist=float(qid.getText(None,"stretch a beam","old length = "+str(self.beam.Height)+"\nnew length?")[0]) frameCmd.stretchTheBeam(self.beam,dist) FreeCAD.activeDocument().recompute() self.av.removeEventCallback("SoKeyboardEvent",self.stop) FreeCADGui.Selection.removeObserver(self) FreeCAD.Console.PrintMessage("I quit.")
Example #28
Source File: Animation.py From Animation with GNU General Public License v2.0 | 4 votes |
def step_slice(self,now): say("Slicer step!" + str(now)) self.ignore=True if now<=self.obj2.start: self.obj2.objCommon.ViewObject.Visibility=False if now<=self.obj2.start or now>self.obj2.end: sayd("ausserhalb") pass else: if not self.obj2.obj: errorDialog("kein Sketch zugeordnet") raise Exception(' self.obj2.obj nicht definiert') f=self.obj2.objFiller maxz=12 # relative=rel say(now) say(self.obj2.start) say(self.obj2.duration) relative=float(now-self.obj2.start)/self.obj2.duration #if False: say(relative) #f.Height= maxz*relative #say(f.Height) #--------------------------------------------- maxz=10 minz=-2 # relative=rel diff=1 ba=f.Placement.Base f.Placement.Base=FreeCAD.Vector(ba.x,ba.y,minz+relative*(maxz-minz+diff)-diff) f.Height=diff FreeCAD.ActiveDocument.recompute() # obj=FreeCAD.getDocument("Unnamed").getObject("Common") obj=self.obj2.objCommon if relative <=0 or relative>=1: obj.ViewObject.Visibility=False else: obj.ViewObject.Visibility=True # obj.ViewObject.ShapeColor=(1.0,.0,0.0) #------------------------- FreeCAD.ActiveDocument.recompute() # if f.Height<=0: # obj.ViewObject.Visibility=False # else: # obj.ViewObject.Visibility=True #obj.ViewObject.ShapeColor=(1.0,.0,0.0) obj.ViewObject.ShapeColor=obj=self.obj2.color self.ignore=False
Example #29
Source File: Animation.py From Animation with GNU General Public License v2.0 | 4 votes |
def execute(self,obj): obj.end=obj.start+obj.duration obj.setEditorMode("end", 1) #ro obj.setEditorMode("objFiller", 1) #ro obj.setEditorMode("objCommon", 1) #ro obj.setEditorMode("direction", 1) #ro say("execute _Filler") if self.ignore: say("ignore") return obj.end=obj.start+obj.duration # wenn noch keine zuordnung erfolgt ist App=FreeCAD #b=FreeCAD.getDocument("Unnamed").getObject("Fusion") FreeCAD.ff=self b=self.obj2.obj bb=b.Shape.BoundBox pim=FreeCAD.Vector(bb.XMin,bb.YMin,bb.ZMin) if not self.obj2.objFiller: say("erzeuge filler") f=FreeCAD.ActiveDocument.addObject("Part::Box","Filler") self.obj2.objFiller=f else: f=self.obj2.objFiller f.Placement.Base=pim f.Length=bb.XMax-bb.XMin f.Width=bb.YMax-bb.YMin f.Height=bb.ZMax-bb.ZMin if not self.obj2.objCommon: say("erzeuge common") c=FreeCAD.activeDocument().addObject("Part::MultiCommon","Common") self.obj2.objCommon=c else: c=self.obj2.objCommon say("erzeugt") c.Shapes = [b,f] f.Height= 0.5*f.Height if False: FreeCAD.ActiveDocument.recompute() c.ViewObject.ShapeColor=(1.0,.0,0.0) c.ViewObject.Transparency=20 b.ViewObject.Transparency=90 b.ViewObject.Visibility=True c.ViewObject.DisplayMode = "Shaded"
Example #30
Source File: cq_cad_tools.py From kicad-3d-models-in-freecad with GNU General Public License v2.0 | 4 votes |
def FuseObjs_wColors(App, Gui, docName, part1, part2, keepOriginals=False): # Fuse two objects App.ActiveDocument=None Gui.ActiveDocument=None App.setActiveDocument(docName) App.ActiveDocument=App.getDocument(docName) Gui.ActiveDocument=Gui.getDocument(docName) App.activeDocument().addObject("Part::MultiFuse","Fusion") App.activeDocument().Fusion.Shapes = [App.activeDocument().getObject(part1),App.activeDocument().getObject(part2),] Gui.activeDocument().getObject(part1).Visibility=False Gui.activeDocument().getObject(part2).Visibility=False Gui.ActiveDocument.Fusion.ShapeColor=Gui.activeDocument().getObject(part1).ShapeColor Gui.ActiveDocument.Fusion.DisplayMode=Gui.activeDocument().getObject(part1).DisplayMode App.ActiveDocument.ActiveObject.Label=docName App.ActiveDocument.recompute() fusedObj = App.ActiveDocument.ActiveObject SimpleCopy_wColors(fusedObj) FreeCAD.ActiveDocument.removeObject(fusedObj.Name) App.getDocument(docName).removeObject(part1) App.getDocument(docName).removeObject(part2) fused_obj = App.ActiveDocument.ActiveObject ## ## TBD refine Shape to reduce size maui ## App.ActiveDocument.addObject('Part::Feature','Fusion').Shape=App.ActiveDocument.Fusion.Shape.removeSplitter() ## App.ActiveDocument.ActiveObject.Label=App.ActiveDocument.Fusion.Label ## Gui.ActiveDocument.Fusion.hide() ## ## Gui.ActiveDocument.ActiveObject.ShapeColor=Gui.ActiveDocument.Fusion.ShapeColor ## Gui.ActiveDocument.ActiveObject.LineColor=Gui.ActiveDocument.Fusion.LineColor ## Gui.ActiveDocument.ActiveObject.PointColor=Gui.ActiveDocument.Fusion.PointColor ## Gui.ActiveDocument.ActiveObject.DiffuseColor=Gui.ActiveDocument.Fusion.DiffuseColor ## App.ActiveDocument.recompute() ## App.ActiveDocument.ActiveObject.Label=docName ####################################################### # Remove the part1 part2 objects return fused_obj ################################################################### # SimpleCopy_wColors() maui # Function to make a simple copy with colors ###################################################################