本文整理汇总了Python中OpenSCADUtils类的典型用法代码示例。如果您正苦于以下问题:Python OpenSCADUtils类的具体用法?Python OpenSCADUtils怎么用?Python OpenSCADUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OpenSCADUtils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fuse
def fuse(meshes):
meshes1 = []
meshes2 = []
for mesh in meshes:
o = orientation(mesh)
if o == "Forward":
meshes1.append(mesh)
elif o == "Reversed":
meshes2.append(complement(mesh))
else:
raise TypeError
# # broken
# mesh1 = None
# if len(meshes1) > 0:
# mesh1 = reduce(Mesh.Mesh.unite, meshes1)
# mesh2 = None
# if len(meshes2) > 0:
# mesh2 = reduce(Mesh.Mesh.intersect, meshes2)
# if mesh1 is None and mesh2 is None:
# return None
# elif mesh1 is None:
# return complement(mesh2)
# elif mesh2 is None:
# return mesh1
# else:
# return complement(mesh2.difference(mesh1))
mesh1 = None
if len(meshes1) > 1:
mesh1 = OpenSCADUtils.meshoptempfile('union', meshes1)
elif len(meshes1) == 1:
mesh1 = meshes1[0]
mesh2 = None
if len(meshes2) > 1:
mesh2 = OpenSCADUtils.meshoptempfile('intersection', meshes2)
elif len(meshes2) == 1:
mesh2 = meshes2[0]
if mesh1 is None and mesh2 is None:
return None
elif mesh1 is None:
return complement(mesh2)
elif mesh2 is None:
return mesh1
else:
return complement(OpenSCADUtils.meshoptempfile('difference', [mesh2, mesh1]))
示例2: execute
def execute(self,fp):
#arguments are ignored
maxmeshpoints = None #TBD: add as property
import Part,OpenSCADUtils
shape = OpenSCADUtils.process_ObjectsViaOpenSCADShape(fp.Document,fp.Children,\
fp.Operation, maxmeshpoints=maxmeshpoints)
if shape:
fp.Shape = shape
else:
raise ValueError
示例3: addelement
def addelement(self):
scadstr=unicode(self.form.textEdit.toPlainText())
asmesh=self.form.checkboxmesh.checkState()
import OpenSCADUtils, os
extension= 'stl' if asmesh else 'csg'
tmpfilename=OpenSCADUtils.callopenscadstring(scadstr,extension)
if tmpfilename:
doc=FreeCAD.activeDocument() or FreeCAD.newDocument()
if asmesh:
import Mesh
Mesh.insert(tmpfilename,doc.Name)
else:
import importCSG
importCSG.insert(tmpfilename,doc.Name)
os.unlink(tmpfilename)
else:
FreeCAD.Console.PrintError(unicode(translate('OpenSCAD','Running OpenSCAD failed'))+u'\n')
示例4: Initialize
def Initialize(self):
def QT_TRANSLATE_NOOP(scope, text):
return text
import OpenSCAD_rc,OpenSCADCommands
commands=['OpenSCAD_ReplaceObject','OpenSCAD_RemoveSubtree',\
'OpenSCAD_RefineShapeFeature',\
'OpenSCAD_IncreaseToleranceFeature', 'OpenSCAD_Edgestofaces', \
'OpenSCAD_ExpandPlacements','OpenSCAD_ExplodeGroup']
toolbarcommands=['OpenSCAD_ReplaceObject','OpenSCAD_RemoveSubtree',\
'OpenSCAD_ExplodeGroup','OpenSCAD_RefineShapeFeature']
#'OpenSCAD_IncreaseToleranceFeature' #icon still missing
import PartGui
parttoolbarcommands = ['Part_CheckGeometry',"Part_Primitives",\
"Part_Builder",'Part_Cut','Part_Fuse','Part_Common',\
'Part_Extrude',"Part_Revolve"]
import FreeCAD
param = FreeCAD.ParamGet(\
"User parameter:BaseApp/Preferences/Mod/OpenSCAD")
openscadfilename = param.GetString('openscadexecutable')
if not openscadfilename:
import OpenSCADUtils
openscadfilename = OpenSCADUtils.searchforopenscadexe()
if openscadfilename: #automatic search was succsessful
FreeCAD.addImportType("OpenSCAD Format (*.scad)","importCSG")
param.SetString('openscadexecutable',openscadfilename) #save the result
if openscadfilename:
commands.extend(['OpenSCAD_AddOpenSCADElement',
'OpenSCAD_MeshBoolean','OpenSCAD_Hull','OpenSCAD_Minkowski'])
toolbarcommands.extend(['OpenSCAD_AddOpenSCADElement',
'OpenSCAD_MeshBoolean','OpenSCAD_Hull','OpenSCAD_Minkowski'])
else:
FreeCAD.Console.PrintWarning('OpenSCAD executable not found\n')
self.appendToolbar(QT_TRANSLATE_NOOP('Workbench','OpenSCADTools'),toolbarcommands)
self.appendMenu('OpenSCAD',commands)
self.appendToolbar(QT_TRANSLATE_NOOP('Workbech','OpenSCAD Part tools'),parttoolbarcommands)
#self.appendMenu('OpenSCAD',["AddOpenSCADElement"])
###self.appendCommandbar("&Generic Tools",["ColorCodeShape"])
FreeCADGui.addIconPath(":/icons")
FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui","OpenSCAD")
示例5: readfile
def readfile(filename):
import os
global lastimportpath
lastimportpath,relname = os.path.split(filename)
isopenscad = relname.lower().endswith('.scad')
if isopenscad:
tmpfile=callopenscad(filename)
if OpenSCADUtils.workaroundforissue128needed():
lastimportpath = os.getcwd() #https://github.com/openscad/openscad/issues/128
f = pythonopen(tmpfile)
else:
f = pythonopen(filename)
rootnode=parsenode(f.read())[0]
f.close()
if isopenscad and tmpfile:
try:
os.unlink(tmpfile)
except OSError:
pass
return rootnode.flattengroups()
示例6: addelement
def addelement(self):
scadstr=unicode(self.form.textEdit.toPlainText()).encode('utf8')
asmesh=self.form.checkboxmesh.checkState()
import OpenSCADUtils, os
extension= 'stl' if asmesh else 'csg'
try:
tmpfilename=OpenSCADUtils.callopenscadstring(scadstr,extension)
doc=FreeCAD.activeDocument() or FreeCAD.newDocument()
if asmesh:
import Mesh
Mesh.insert(tmpfilename,doc.Name)
else:
import importCSG
importCSG.insert(tmpfilename,doc.Name)
try:
os.unlink(tmpfilename)
except OSError:
pass
except OpenSCADUtils.OpenSCADError, e:
FreeCAD.Console.PrintError(e.value)
示例7: openscadmesh
def openscadmesh(doc,scadstr,objname):
import Part,Mesh,os,OpenSCADUtils
tmpfilename=OpenSCADUtils.callopenscadstring(scadstr,'stl')
if tmpfilename:
#mesh1 = doc.getObject(objname) #reuse imported object
Mesh.insert(tmpfilename)
os.unlink(tmpfilename)
mesh1=doc.getObject(objname) #blog
mesh1.ViewObject.hide()
sh=Part.Shape()
sh.makeShapeFromMesh(mesh1.Mesh.Topology,0.1)
solid = Part.Solid(sh)
obj=doc.addObject("Part::FeaturePython",objname)
ImportObject(obj,mesh1) #This object is not mutable from the GUI
ViewProviderTree(obj.ViewObject)
solid=solid.removeSplitter()
if solid.Volume < 0:
solid.complement()
obj.Shape=solid#.removeSplitter()
return obj
else:
print scadstr
示例8: expandplacements
def expandplacements(obj,placement):
ownplacement=placement.multiply(obj.Placement)
if obj.isDerivedFrom('Part::FeaturePython') and isinstance(obj.Proxy,MatrixTransform):
#expandplacementsmatrix(obj,ownplacement.toMatrix())
expandplacementsmatrix(obj,placement.toMatrix())
elif likeprimitive(obj,False):
obj.Placement=ownplacement
elif obj.isDerivedFrom('Part::Mirroring'):
import OpenSCADUtils
mm = OpenSCADUtils.mirror2mat(obj.Normal,obj.Base)
#todo: set the base to 0,0,0
innerp=FreeCAD.Placement(mm * ownplacement.toMatrix() *mm)
expandplacements(obj.Source,innerp)
obj.Placement=FreeCAD.Placement()
else:
for outobj in obj.OutList:
if obj.isDerivedFrom('Part::Extrusion'):
obj.Dir=ownplacement.Rotation.multVec(obj.Dir)
elif obj.isDerivedFrom('Part::Revolution'):
obj.Axis=ownplacement.Rotation.multVec(obj.Axis)
#obj.Base=ownplacement.Rotation.multVec(obj.Base)
expandplacements(outobj,ownplacement)
obj.Placement=FreeCAD.Placement()
示例9: Activated
def Activated(self):
import OpenSCADUtils, FreeCADGui
OpenSCADUtils.removesubtree(FreeCADGui.Selection.getSelection())
示例10: execute
def execute(self, fp):
if fp.Base and fp.Base.Shape.isValid():
import OpenSCADUtils
sh=fp.Base.Shape.removeSplitter()
fp.Shape=OpenSCADUtils.applyPlacement(sh)