OpenSCAD use Part::Prism

This commit is contained in:
Sebastian Hoogen 2013-09-23 09:36:45 +02:00 committed by Yorik van Havre
parent 34cce64edc
commit cf2d437c73
3 changed files with 38 additions and 23 deletions

View File

@ -141,6 +141,16 @@ def process_object(csg,ob):
if mm == 1 : csg.write("}\n")
else : # Cannot convert to rotate extrude so best effort is polyhedron
csg.write('%s\n' % shape2polyhedron(ob.Shape))
elif ob.TypeId == "Part::Prism":
import math
f = str(ob.Polygon)
# r = str(ob.Length/2.0/math.sin(math.pi/ob.Polygon))
r = str(ob.Length) #length seems to be the outer radius
h = str(ob.Height)
mm = check_multmatrix(csg,ob,0,0,-float(h)/2)
csg.write("cylinder($fn = "+f+", "+fafs+", h = "+h+", r1 = "+r+\
", r2 = "+r+", center = "+center(mm)+");\n")
if mm == 1: csg.write("}\n")
elif ob.TypeId == "Part::Extrusion" :
print "Extrusion"

View File

@ -798,23 +798,29 @@ def p_cylinder_action(p):
mycyl.Radius = r1
else :
if printverbose: print "Make Prism"
mycyl=doc.addObject("Part::Extrusion","prism")
mycyl.Dir = (0,0,h)
try :
import Draft
mycyl.Base = Draft.makePolygon(n,r1)
except :
# If Draft can't import (probably due to lack of Pivy on Mac and
# Linux builds of FreeCAD), this is a fallback.
# or old level of FreeCAD
if printverbose: print "Draft makePolygon Failed, falling back on manual polygon"
mycyl.Base = myPolygon(n,r1)
if False: #user Draft Polygon
mycyl=doc.addObject("Part::Extrusion","prism")
mycyl.Dir = (0,0,h)
try :
import Draft
mycyl.Base = Draft.makePolygon(n,r1)
except :
# If Draft can't import (probably due to lack of Pivy on Mac and
# Linux builds of FreeCAD), this is a fallback.
# or old level of FreeCAD
if printverbose: print "Draft makePolygon Failed, falling back on manual polygon"
mycyl.Base = myPolygon(n,r1)
# mycyl.Solid = True
else :
pass
if gui:
mycyl.Base.ViewObject.hide()
# mycyl.Solid = True
else :
pass
if gui:
mycyl.Base.ViewObject.hide()
else: #Use Part::Prism primitive
mycyl=doc.addObject("Part::Prism","prism")
mycyl.Polygon = n
mycyl.Length = r1
mycyl.Height = h
else:
if printverbose: print "Make Cone"

View File

@ -132,13 +132,12 @@ class Node:
h = self.arguments['h']
r1 ,r2 = self.arguments['r1'], self.arguments['r2']
if '$fn' in self.arguments and self.arguments['$fn'] > 2 \
and self.arguments['$fn']<=Node.fnmin:
if r1 == r2:
import Draft
base = Draft.makePolygon(int(self.arguments['$fn']),r1)
obj = doc.addObject("Part::Extrusion",'prism')
obj.Base= base
obj.Dir = (0,0,h)
and self.arguments['$fn']<=Node.fnmin: # polygonal
if r1 == r2: # prismatic
obj = doc.addObject("Part::Prism","prism")
obj.Polygon = int(self.arguments['$fn'])
obj.Length = r1
obj.Height = h
if self.arguments['center']:
center(obj,0,0,h)
base.ViewObject.hide()