Python FreeCAD.newDocument() Examples
The following are 21
code examples of FreeCAD.newDocument().
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: pasteSVG.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def Activated(self): cb = QtGui.QApplication.clipboard() t=cb.text() if t[0:5] == '<?xml': h = importSVG.svgHandler() doc = FreeCAD.ActiveDocument if not doc: doc = FreeCAD.newDocument("SvgImport") h.doc = doc xml.sax.parseString(t,h) doc.recompute() FreeCADGui.SendMsgToActiveView("ViewFit") else: FreeCAD.Console.PrintError('Invalid clipboard content.\n') #def IsActive(self): #return(True)
Example #2
Source File: FC_interaction_example.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def __init__(self, points=[], fp = None): self.points = points self.curve = Part.BSplineCurve() self.fp = fp self.root_inserted = False #self.support = None # Not yet implemented if len(points) > 0: if isinstance(points[0],FreeCAD.Vector): self.points = [ConnectionMarker([p]) for p in points] elif isinstance(points[0],(tuple,list)): self.points = [MarkerOnEdge([p]) for p in points] else: FreeCAD.Console.PrintError("InterpolationPolygon : bad input") # Setup coin objects if not FreeCAD.ActiveDocument: appdoc = FreeCAD.newDocument("New") self.guidoc = FreeCADGui.ActiveDocument self.view = self.guidoc.ActiveView self.rm = self.view.getViewer().getSoRenderManager() self.sg = self.view.getSceneGraph() self.setup_InteractionSeparator() self.update_curve()
Example #3
Source File: test_data_data_utils.py From qmt with MIT License | 6 votes |
def test_store_serial(datadir, fix_FCDoc): """Test serialisation to memory.""" import FreeCAD # Serialise document obj = fix_FCDoc.addObject("App::FeaturePython", "some_content") serial_data = store_serial(fix_FCDoc, lambda d, p: d.saveAs(p), "fcstd") # Write to a file file_path = os.path.join(datadir, "test.fcstd") data = codecs.decode(serial_data.encode(), "base64") with open(file_path, "wb") as of: of.write(data) # Load back and check doc = FreeCAD.newDocument("instance") FreeCAD.setActiveDocument("instance") doc.load(file_path) assert doc.getObject("some_content") is not None FreeCAD.closeDocument("instance")
Example #4
Source File: kicad.py From fcad_pcb with MIT License | 5 votes |
def getActiveDoc(): if FreeCAD.ActiveDocument is None: return FreeCAD.newDocument('kicad_fcad') return FreeCAD.ActiveDocument
Example #5
Source File: ExportPanel.py From LCInterlocking with GNU Lesser General Public License v2.1 | 5 votes |
def Activated(self): parts_list = get_freecad_object() new_doc = FreeCAD.newDocument("export_shape") self.export_list(parts_list, new_doc) FreeCADGui.getDocument(new_doc.Name).ActiveView.fitAll() return
Example #6
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 #7
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 #8
Source File: KeyboardCAD.py From KeyboardCAD with GNU Affero General Public License v3.0 | 5 votes |
def initializeCAD(): global doc doc = FreeCAD.newDocument() #initialize the document pad(sketchRectangle(0, 0, plateXDim, plateYDim, False, False)) #draw the plate
Example #9
Source File: TestAnim.py From Animation with GNU General Public License v2.0 | 5 votes |
def setUp(self): # setting a new document to hold the tests if FreeCAD.ActiveDocument: if FreeCAD.ActiveDocument.Name != "AnimTest": FreeCAD.newDocument("AnimTest") else: FreeCAD.newDocument("AnimTest") FreeCAD.setActiveDocument("AnimTest")
Example #10
Source File: tests.py From FreeCAD_assembly2 with GNU Lesser General Public License v2.1 | 5 votes |
def test_simple_box( self ): Doc = FreeCAD.newDocument('doc1') Doc.addObject("Part::Box","Box") Doc.Box.Placement.Base = Base.Vector( 2, 3, 4 ) Doc.recompute() d = self._test_parsing( Doc, '/tmp/test_a2import_block.fcstd' ) self.assertTrue( d.Name == 'test_a2import_block', d.Name )
Example #11
Source File: geo_3d_data.py From qmt with MIT License | 5 votes |
def get_data(self, data_name: str, scratch_dir: Optional[str] = None): """Get data from stored serial format. Parameters ---------- data_name : str "fcdoc" freeCAD document. scratch_dir : str Optional existing temporary (fast) storage location. (Default value = None) mesh : (Default value = None) Returns ------- data """ if data_name == "fcdoc": def _load_fct(path): doc = FreeCAD.newDocument("instance") FreeCAD.setActiveDocument("instance") doc.load(path) return doc return load_serial(self.serial_fcdoc, _load_fct, scratch_dir=scratch_dir) else: raise ValueError(f"{data_name} was not a valid data_name.")
Example #12
Source File: test_geo_objects.py From qmt with MIT License | 5 votes |
def test_overlapping_parts(datadir): """ This tests that two parts that were generated from lithography over a wire register as intersecting. Due to an OCC bug, FC 0.18 at one point would claim that these didn't intersect, resulting in geometry and meshing errors. """ path = os.path.join(datadir, "intersection_test.FCStd") doc = FreeCAD.newDocument("instance") FreeCAD.setActiveDocument("instance") doc.load(path) shape_1 = doc.Objects[0] shape_2 = doc.Objects[1] assert checkOverlap([shape_1, shape_2]) FreeCAD.closeDocument(doc.Name)
Example #13
Source File: conftest.py From qmt with MIT License | 5 votes |
def fix_FCDoc(): """Set up and tear down a FreeCAD document.""" import FreeCAD doc = FreeCAD.newDocument("testDoc") yield doc FreeCAD.closeDocument("testDoc") ################################################################################ # Sketches
Example #14
Source File: InitGui.py From ExplodedAssembly with GNU General Public License v2.0 | 5 votes |
def Activated(self): import ExplodedAssembly as ea if not(FreeCAD.ActiveDocument): FreeCAD.newDocument() ea.checkDocumentStructure() FreeCAD.Console.PrintMessage('Exploded Assembly workbench loaded\n')
Example #15
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 #16
Source File: blendsurf_editor.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, seg=[]): self.segments = list() #self.curve = Part.BSplineCurve() self.root_inserted = False #self.support = None # Not yet implemented for p in seg: if isinstance(p,FreeCAD.Vector): self.points.append(MarkerOnShape([p])) elif isinstance(p,(tuple,list)): self.points.append(MarkerOnShape([p[0]],p[1])) elif isinstance(p,(MarkerOnShape, ConnectionMarker)): self.points.append(p) else: FreeCAD.Console.PrintError("InterpoCurveEditor : bad input") # Setup coin objects if self.fp: self.guidoc = self.fp.ViewObject.Document else: if not FreeCADGui.ActiveDocument: appdoc = FreeCAD.newDocument("New") self.guidoc = FreeCADGui.ActiveDocument self.view = self.guidoc.ActiveView self.rm = self.view.getViewer().getSoRenderManager() self.sg = self.view.getSceneGraph() self.setup_InteractionSeparator() self.update_curve()
Example #17
Source File: profile_editor.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, points=[], fp = None): self.points = list() self.curve = Part.BSplineCurve() self.fp = fp self.root_inserted = False self.periodic = False self.param_factor = 1.0 #self.support = None # Not yet implemented for p in points: if isinstance(p,FreeCAD.Vector): self.points.append(MarkerOnShape([p])) elif isinstance(p,(tuple,list)): self.points.append(MarkerOnShape([p[0]],p[1])) elif isinstance(p,(MarkerOnShape, ConnectionMarker)): self.points.append(p) else: FreeCAD.Console.PrintError("InterpoCurveEditor : bad input") # Setup coin objects if self.fp: self.guidoc = self.fp.ViewObject.Document else: if not FreeCADGui.ActiveDocument: appdoc = FreeCAD.newDocument("New") self.guidoc = FreeCADGui.ActiveDocument self.view = self.guidoc.ActiveView self.rm = self.view.getViewer().getSoRenderManager() self.sg = self.view.getSceneGraph() self.setup_InteractionSeparator() self.update_curve()
Example #18
Source File: ParametricBlendCurve.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, points=[], fp = None): self.points = list() self.fp = fp self.curve = None self.root_inserted = False self.ctrl_keys = {"i" : [self.insert], "v" : [self.text_change], "q" : [self.quit], "\uffff" : [self.remove_point]} for p in points: if isinstance(p,FreeCAD.Vector): self.points.append(manipulators.ShapeSnap(p)) elif isinstance(p,(tuple,list)): self.points.append(manipulators.ShapeSnap(p[0],p[1])) elif isinstance(p, manipulators.ShapeSnap): self.points.append(p) elif isinstance(p, manipulators.CustomText): self.points.append(p) else: FreeCAD.Console.PrintError("pointEditor : bad input") for p in points: if hasattr(p, "ctrl_keys"): for key in p.ctrl_keys: if key in self.ctrl_keys: #print(key) self.ctrl_keys[key].extend(p.ctrl_keys[key]) else: self.ctrl_keys[key] = p.ctrl_keys[key] # Setup coin objects if self.fp: self.guidoc = self.fp.ViewObject.Document else: if not FreeCADGui.ActiveDocument: appdoc = FreeCAD.newDocument("New") self.guidoc = FreeCADGui.ActiveDocument self.view = self.guidoc.ActiveView self.rm = self.view.getViewer().getSoRenderManager() self.sg = self.view.getSceneGraph() self.setup_InteractionSeparator()
Example #19
Source File: gui.py From FreeCAD_assembly3 with GNU General Public License v3.0 | 5 votes |
def Activated(cls,idx=0): _ = idx from .assembly import Assembly objs = [] for obj in FreeCADGui.Selection.getSelection(): if obj.isDerivedFrom('App::LinkGroup'): objs.append(obj) else: objs = None break filenames = None if not objs: filenames = QtGui.QFileDialog.getOpenFileNames( QtGui.QApplication.activeWindow(), 'Please select file', None, 'STEP (*.stp *.step);;All (*.*)')[0] if not filenames: return FreeCAD.setActiveTransaction('Assembly import') doc = FreeCAD.ActiveDocument if not doc: doc = FreeCAD.newDocument() if filenames: import ImportGui for name in filenames: obj = ImportGui.insert(name,doc.Name,merge=False, useLinkGroup=True,mode=cls.importMode()) if obj: objs.append(obj) for obj in objs: Assembly.fromLinkGroup(obj) FreeCAD.closeActiveTransaction() return
Example #20
Source File: dev.py From NodeEditor with MIT License | 4 votes |
def run_FreeCAD_bakery(self): workspace=self.getData("Workspace") name=self.getData("name") shape=self.getPinObject('Shape_in') s=shape l=FreeCAD.listDocuments() if workspace=='' or workspace=='None': try: w=l['Unnamed'] except: w=FreeCAD.newDocument("Unnamed") FreeCADGui.runCommand("Std_TileWindows") else: if workspace in l.keys(): w=l[workspace] else: w=FreeCAD.newDocument(workspace) #Std_CascadeWindows FreeCADGui.runCommand("Std_ViewDimetric") FreeCADGui.runCommand("Std_ViewFitAll") FreeCADGui.runCommand("Std_TileWindows") #s=store.store().get(shape) f=w.getObject(name) #say("AB",time.time()-timeA) if 1 or f == None: f = w.addObject('Part::Feature', name) if s != None: # say("AC",time.time()-timeA) f.Shape=s # say("AD",time.time()-timeA) #say("shape",s);say("name",name) #say("A",time.time()-timeA) w.recompute() #say("B",time.time()-timeA) if 1: color=(random.random(),random.random(),1.) f.ViewObject.ShapeColor = color f.ViewObject.LineColor = color f.ViewObject.PointColor = color #f.ViewObject.Transparency = transparency #say("E",time.time()-timeA)
Example #21
Source File: splitCurves_2.py From CurvesWB with GNU Lesser General Public License v2.1 | 4 votes |
def __init__(self, points=[], fp = None): self.points = list() self.fp = fp self.curve = None self.root_inserted = False self.ctrl_keys = {"i" : [self.insert], "v" : [self.text_change], "q" : [self.quit], "\uffff" : [self.remove_point]} for p in points: if isinstance(p,FreeCAD.Vector): self.points.append(MarkerOnEdge(p)) elif isinstance(p,(tuple,list)): self.points.append(MarkerOnEdge(p[0],p[1])) elif isinstance(p, MarkerOnEdge): self.points.append(p) else: FreeCAD.Console.PrintError("pointEditor : bad input") for p in points: if hasattr(p, "ctrl_keys"): for key in p.ctrl_keys: if key in self.ctrl_keys: #print(key) self.ctrl_keys[key].extend(p.ctrl_keys[key]) else: self.ctrl_keys[key] = p.ctrl_keys[key] # Setup coin objects if self.fp: self.guidoc = self.fp.ViewObject.Document else: if not FreeCADGui.ActiveDocument: appdoc = FreeCAD.newDocument("New") self.guidoc = FreeCADGui.ActiveDocument self.view = self.guidoc.ActiveView self.rm = self.view.getViewer().getSoRenderManager() self.sg = self.view.getSceneGraph() self.setup_InteractionSeparator()