def main(): shape = Part.Shape() #shape_formats = ['.brp', '.igs', '.stp'] if in_ext in mesh_formats: print("Opening mesh file: ", in_f) Mesh.open(in_f) o = FreeCAD.getDocument("Unnamed").findObjects()[0] #print("dir: ", dir(o)) if out_ext in mesh_formats: print("Exporting to mesh file: ", out_f) Mesh.export([o], out_f) else: # TODO This is not optimizing the resulting amount of faces! # see http://www.freecadweb.org/wiki/index.php?title=Mesh_to_Part shape.makeShapeFromMesh(o.Mesh.Topology, 0.05) # tolerance for sewing exportParametric(shape, out_f, out_ext) elif out_ext in mesh_formats: print("Opening parametric file: ", in_f) Part.open(in_f) o = FreeCAD.getDocument("Unnamed").findObjects()[0] print("Exporting to mesh file: ", out_f) Mesh.export([o], out_f) else: # Parametric -> Parametric print("Opening parametric file: ", in_f) shape.read(in_f) exportParametric(shape, out_f, out_ext)
def writeProps(brep, name): """ Write the inertial properties and initial conditions to a file """ Part.open(brep) key = brep.split('.')[0] App.ActiveDocument = App.getDocument(key) doc = App.getDocument(key) doc.recompute() shape = doc.getObject(key).Shape # Retrieve the solid from shape solid = shape.Solids[0] J = solid.MatrixOfInertia print "Creating property file", key + '.dat' c = [0.0, 0.0, 0.0] Jmat = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] xcm = [0.0, 0.0, 0.0] CTMP = [ solid.StaticMoments[0], solid.StaticMoments[1], solid.StaticMoments[2] ] JTMP = [J.A11, J.A12, J.A13, J.A22, J.A23, J.A33] xcmtmp = [solid.CenterOfMass.x, solid.CenterOfMass.y, solid.CenterOfMass.z] for i in xrange(3): #if abs(CTMP[i]) > 1.0e-16: if abs(CTMP[i]) > 1.0e-16: c[i] = CTMP[i] xcm[i] = xcmtmp[i] for i in xrange(6): if abs(JTMP[i]) > 1.0e-16: Jmat[i] = JTMP[i] # Assert the equivalence of xcg and c/volume assert ((np.allclose(np.array(xcm), np.array(c) / solid.Volume)), 1) fp = open(key + '.dat', 'w') fp.write('name %s\n' % name) fp.write('density %s\n' % Density) fp.write('volume %s\n' % solid.Volume) fp.write('c %s %s %s\n' % (c[0], c[1], c[2])) fp.write('J %s %s %s %s %s %s\n' % (Jmat[0], Jmat[1], Jmat[2], Jmat[3], Jmat[4], Jmat[5])) fp.write('xcg %s %s %s\n' % (xcm[0], xcm[1], xcm[2])) fp.write('vel %s %s %s\n' % (0.0, 0.0, vz)) fp.write('omega %s %s %s\n' % (0.0, 0.0, Omega)) fp.write('grav %s %s %s\n' % (0.0, 0.0, Grav)) fp.write('mesh %s %s %s\n' % (key + '.bdf', mesh_type, 'None')) fp.close()
def generate(body): """ Evaluates the solid properties using FREECAD that uses OPENCASCADE geoemtry engine """ Part.open(body.brep_file) key = os.path.basename(body.brep_file).split('.brep')[0] doc = App.getDocument(key) doc.recompute() shape = doc.getObject(key).Shape body.solid_props = shape.Solids[0] return
import Part, Drawing Part.open("D:/_Projekte/FreeCAD/FreeCADData/Schenkel.stp") App.activeDocument().addObject('Drawing::FeaturePage', 'Page') App.activeDocument( ).Page.Template = 'D:/_Projekte/FreeCAD/FreeCAD_0.9_LibPack7/Mod/Drawing/Templates/A3_Landscape.svg' App.activeDocument().addObject('Drawing::FeatureViewPart', 'View') App.activeDocument().View.Source = App.activeDocument().Schenkel App.activeDocument().View.Direction = (0.0, 1.0, 0.0) App.activeDocument().View.X = 30.0 App.activeDocument().View.Y = 30.0 App.activeDocument().View.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View) App.activeDocument().addObject('Drawing::FeatureViewPart', 'View1') App.activeDocument().View1.Source = App.activeDocument().Schenkel App.activeDocument().View1.Direction = (0.0, 0.0, 1.0) App.activeDocument().View1.X = 70.0 App.activeDocument().View1.Y = 30.0 App.activeDocument().View1.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View1) App.activeDocument().addObject('Drawing::FeatureViewPart', 'View2') App.activeDocument().View2.Source = App.activeDocument().Schenkel App.activeDocument().View2.Direction = (1.0, 0.0, 0.0) App.activeDocument().View2.X = 70.0 App.activeDocument().View2.Y = 200.0 App.activeDocument().View2.Rotation = 90.0 App.activeDocument().View2.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View2)
import Part, Drawing Part.open("D:/_Projekte/FreeCAD/FreeCADData/Schenkel.stp") App.activeDocument().addObject('Drawing::FeaturePage','Page') App.activeDocument().Page.Template = 'D:/_Projekte/FreeCAD/FreeCAD_0.9_LibPack7/Mod/Drawing/Templates/A3_Landscape.svg' App.activeDocument().addObject('Drawing::FeatureViewPart','View') App.activeDocument().View.Source = App.activeDocument().Schenkel App.activeDocument().View.Direction = (0.0,1.0,0.0) App.activeDocument().View.X = 30.0 App.activeDocument().View.Y = 30.0 App.activeDocument().View.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View) App.activeDocument().addObject('Drawing::FeatureViewPart','View1') App.activeDocument().View1.Source = App.activeDocument().Schenkel App.activeDocument().View1.Direction = (0.0,0.0,1.0) App.activeDocument().View1.X = 70.0 App.activeDocument().View1.Y = 30.0 App.activeDocument().View1.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View1) App.activeDocument().addObject('Drawing::FeatureViewPart','View2') App.activeDocument().View2.Source = App.activeDocument().Schenkel App.activeDocument().View2.Direction = (1.0,0.0,0.0) App.activeDocument().View2.X = 70.0 App.activeDocument().View2.Y = 200.0 App.activeDocument().View2.Rotation = 90.0 App.activeDocument().View2.Scale = 1.0 App.activeDocument().Page.addObject(App.activeDocument().View2) App.activeDocument().addObject('Drawing::FeatureViewPart','View3') App.activeDocument().View3.Source = App.activeDocument().Schenkel
#!/usr/bin/env python import FreeCAD, Part, Mesh import os, sys print 'Load step file this takes a while' Part.open(os.path.abspath(sys.argv[1])) objs = FreeCAD.getDocument("Unnamed").findObjects() print 'Saving stl file this takes a while' Mesh.export(objs, os.path.abspath(sys.argv[2]))
def explodeOBJS(): if not inputFile or not outputFile: sys.exit(2); Part.open(inputFile); Mesh.export(FreeCAD.ActiveDocument.Objects,outputFile);
#*************************************************************************** #* * #* Copyright (c) 2012 * #* Yorik van Havre <*****@*****.**> * #* * #* This program is free software; you can redistribute it and/or modify * #* it under the terms of the GNU Lesser General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * #* * #* This program is distributed in the hope that it will be useful, * #* but WITHOUT ANY WARRANTY; without even the implied warranty of * #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * #* GNU Library General Public License for more details. * #* * #* You should have received a copy of the GNU Library General Public * #* License along with this program; if not, write to the Free Software * #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * #* * #*************************************************************************** import FreeCAD,FreeCADGui,Part Part.open(FreeCAD.getResourceDir()+"examples/Schenkel.stp") FreeCADGui.activeDocument().sendMsgToViews("ViewFit") FreeCADGui.activeDocument().sendMsgToViews("ViewAxo")
#!/usr/bin/freecadcmd # Uses freecadcmd to convert from one supported format to another import os import sys import FreeCAD import Part import Mesh try: infile, outfile = sys.argv[2], sys.argv[3] except ValueError: print "Uses freecadcmd to convert from one supported format to another" print "Usage: {} [source file] [dest file]".format(sys.argv[0]) sys.exit() def touch(fname, times=None): with open(fname, 'a'): os.utime(fname, times) touch(outfile) Part.open(infile) o = [FreeCAD.getDocument("Unnamed").findObjects()[0]] Mesh.export(o, outfile)
import sys FREECADPATH = '/usr/lib/freecad/lib/' sys.path.append(FREECADPATH) import FreeCAD import Part import Mesh in_fn, out_fn = sys.argv[1], sys.argv[2] try: FreeCAD.open(in_fn) #FCStd files except: Part.open(in_fn) #STEP / IGES files objs = FreeCAD.ActiveDocument.Objects Mesh.export(objs, out_fn)
def explodeOBJS(): if not inputFile or not outputFile: sys.exit(2) Part.open(inputFile) Mesh.export(FreeCAD.ActiveDocument.Objects, outputFile)
#!/usr/bin/freecadcmd # Uses freecadcmd to convert from one supported format to another import os import sys import FreeCAD import Part import Mesh try: infile, outfile = sys.argv[2], sys.argv[3] except ValueError: print "Uses freecadcmd to convert from one supported format to another" print "Usage: {} [source file] [dest file]".format(sys.argv[0]) sys.exit() def touch(fname, times=None): with open(fname, 'a'): os.utime(fname, times) touch(outfile) Part.open(infile) o = [ FreeCAD.getDocument("Unnamed").findObjects()[0] ] Mesh.export(o, outfile)
import sys import Mesh import Part import FreeCAD # This file is run by Freecads own version of python to do step file conversion # The exporter will shell out to Freecad and provide the path to this file in_fn, out_fn = sys.argv[2], sys.argv[3] try: Part.open(in_fn) except: sys.exit(1) o = [FreeCAD.getDocument("Unnamed").findObjects()[0]] Mesh.export(o, out_fn)
#*************************************************************************** #* * #* Copyright (c) 2012 * #* Yorik van Havre <*****@*****.**> * #* * #* This program is free software; you can redistribute it and/or modify * #* it under the terms of the GNU Lesser General Public License (LGPL) * #* as published by the Free Software Foundation; either version 2 of * #* the License, or (at your option) any later version. * #* for detail see the LICENCE text file. * #* * #* This program is distributed in the hope that it will be useful, * #* but WITHOUT ANY WARRANTY; without even the implied warranty of * #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * #* GNU Library General Public License for more details. * #* * #* You should have received a copy of the GNU Library General Public * #* License along with this program; if not, write to the Free Software * #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * #* USA * #* * #*************************************************************************** import FreeCAD, FreeCADGui, Part Part.open(FreeCAD.getResourceDir() + "examples/Schenkel.stp") FreeCADGui.activeDocument().sendMsgToViews("ViewFit") FreeCADGui.activeDocument().sendMsgToViews("ViewAxo")
FREECADPATH='/usr/lib/freecad/lib/' import sys sys.path.append(FREECADPATH) import FreeCAD import Part import Mesh import sys in_fn, out_fn = sys.argv[1], sys.argv[2] Part.open(in_fn) o = [ FreeCAD.getDocument("Unnamed").findObjects()[0] ] Mesh.export(o, out_fn)