Hi-
I have just gotten started with pyOCC and have been working on converting the 
(C++) OpenCascade bottle tutorial to python code as an exercise for coming up 
to speed on pyOCC. I am using pyOCC version=0.6-beta.
The problem I am having is: BRepAlgoAPI_Fuse() doesn't seem to work. (See code 
appended below.)
As I searched for an answer, I came across an old solution written by Thomas 
Paviot at:
http://pythonocc.googlecode.com/svn-history/r72/trunk/tests/test_makebottle.py 
but this seems to have the same problem.
Am I doing something wrong or is there something broken in my version of pyOCC?

-          Doug


File:  OCC_BottleTutorial.py

# Adaptation to python of OCC tutorial at:
# http://www.opencascade.org/org/gettingstarted/appli
# Also found 2008 solution by Thomas Paviot at:
# http://pythonocc.googlecode.com/svn-history/r72/trunk/tests/test_makebottle.py

import math
from OCC.Display.SimpleGui import *
from OCC.gp import *
from OCC.BRepPrimAPI import *
from OCC.GC import *
from OCC.TopoDS import *
from OCC.BRepBuilderAPI import *
from OCC.TopExp import *
from OCC.TopAbs import *
from OCC.BRepFilletAPI import *
from OCC.BRepAlgoAPI import *
from OCC.STEPControl import *

display, start_display, add_menu, add_function_to_menu = init_display()

# Bottle dimensions
myHeight = 70
myWidth = 50
myThickness = 30

# Start with points defining the shape of half bottle
aPnt1 = gp_Pnt(-myWidth / 2. , 0 , 0)
aPnt2 = gp_Pnt(-myWidth / 2. , -myThickness / 4. , 0)
aPnt3 = gp_Pnt(0 , -myThickness / 2. , 0)
aPnt4 = gp_Pnt(myWidth / 2. , -myThickness / 4. , 0)
aPnt5 = gp_Pnt(myWidth / 2. , 0 , 0)

# Make lines defining the shape of half bottle
aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
aSegment2 = GC_MakeSegment(aPnt4, aPnt5)
aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
if aSegment1.IsDone():
    seg1handle = aSegment1.Value()
if aSegment2.IsDone():
    seg2handle = aSegment2.Value()
if aArcOfCircle.IsDone():
    arc_handle = aArcOfCircle.Value()

# Convert line segments to 'edges'
aEdge1 = BRepBuilderAPI_MakeEdge(seg1handle).Edge()
aEdge2 = BRepBuilderAPI_MakeEdge(arc_handle).Edge()
aEdge3 = BRepBuilderAPI_MakeEdge(seg2handle).Edge()

# Convert edges to wire
aWire = BRepBuilderAPI_MakeWire(aEdge1, aEdge2, aEdge3).Wire()

# Mirror wire and add to get 'whole' bottle
mirrorTransform = gp_Trsf()
mirrorTransform.SetMirror(gp_Pnt(0.0,0.0,0.0)) # I don't understand this
mirrorWireShape = BRepBuilderAPI_Transform(aWire , mirrorTransform).Shape()
wire = BRepBuilderAPI_MakeWire()
wire.Add(aWire)
mirrorWire = TopoDS.TopoDS().wire(mirrorWireShape)
wire.Add(mirrorWire)

# Make bottom face
botFace = BRepBuilderAPI_MakeFace(wire.Wire())
if botFace.IsDone():
    bottomFace = botFace.Face()

# Extrude body of bottle
bottle = BRepPrimAPI_MakePrism(bottomFace, gp_Vec(0, 0, myHeight))
if bottle.IsDone():
    bottleShape = bottle.Shape()

# Add fillets
edgeExplorer = TopExp_Explorer(bottleShape, TopAbs_EDGE)
mkFillet = BRepFilletAPI_MakeFillet(bottleShape)
while edgeExplorer.More():
    edg = edgeExplorer.Current()
    edge = TopoDS.TopoDS().edge(edg)
    mkFillet.Add(myThickness/12., edge)
    edgeExplorer.Next()
myBody = mkFillet.Shape()

# Body : Add the Neck
neckLocation = gp_Pnt(0 , 0 , myHeight)
neckNormal = gp().DZ()
neckAx2 = gp_Ax2(neckLocation , neckNormal)
myNeckRadius = myThickness / 4.
myNeckHeight = myHeight / 10.
MKCylinder = BRepPrimAPI_MakeCylinder(neckAx2 , myNeckRadius , myNeckHeight)
myNeck = MKCylinder.Shape()
print type(myBody)
print type(myNeck)
#myBody = BRepAlgoAPI_Fuse(myBody , myNeck) #TypeError: 'BRepAlgoAPI_Fuse' 
object is not iterable

# Export to STEP
step_export = STEPControl_Writer()
step_export.Transfer(myBody,STEPControl_AsIs)
step_export.Write('bottle.stp')

display.DisplayColoredShape(myNeck, 'GREEN')
display.DisplayColoredShape(myBody, 'RED')
display.DisplayColoredShape(bottomFace, 'YELLOW')
display.DisplayColoredShape(aWire, 'BLUE')
start_display()


_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to