2011/1/4 Balint Balassa <balint.bala...@gmx.de>

> Hi everyone,
>
> I'm relatively new to pythonOCC and I'm having a bit of a problem with my
> code. It's really quite basic. I created a cylinder and extracted an edge,
> which I made into a wire and a face, which in theory should not be a
> problem. Unfortunately the face does not show up in the display window (see
> the code below). I've tried the doxygen documentation, but didn't find
> anything helpful. Is there any way to make a face from extracted edges?
> Thank you very much for your help in advance.
>
> Regards,
> Balint
>
>
>
> import OCC.TopoDS
> from OCC.Utils.Topology import Topo
> from OCC.TopTools import *
> import math
>
> from OCC.Display.SimpleGui import *
> display, start_display, add_menu, add_function_to_menu = init_display()
>
> shroudRadius = 3.0
> hubRadius = 1.0
> radius = 0.2
> epsilon = 1.0e-1
>
> ## Creating circle and making cylinder:
> centerCircle = OCC.gp.gp_Pnt(hubRadius-epsilon, 0, 0.5)
> myAX2 = OCC.gp.gp_Ax2(centerCircle,OCC.gp.gp_Dir(1, 0, 0))
> circle = OCC.gp.gp_Circ(myAX2, radius)
>
> Edge2 = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeEdge(circle, 0,
> 2.0*math.pi).Edge()
> ExistingWire = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeWire(Edge2).Wire()
> PrismFace =
> OCC.BRepBuilderAPI.BRepBuilderAPI_MakeFace(ExistingWire).Shape()
>
> length = OCC.gp.gp_Vec(shroudRadius-hubRadius+2.0*epsilon, 0, 0)
>
> bladeSurface = OCC.BRepPrimAPI.BRepPrimAPI_MakePrism(PrismFace,
> length).Shape()
> bladeSurface = OCC.BRepPrimAPI.BRepPrimAPI_MakePrism(ExistingWire,
> length).Shape()
> #display.DisplayShape(bladeSurface)
> topoBlade = OCC.Utils.Topology.Topo(bladeSurface)
> topoBlade.number_of_shells()
> bladeFace = topoBlade.faces().next()
>
> ## Getting the desired edge:
> edges = []
> for edge in topoBlade.edges_from_face(bladeFace):
>        edge.Reverse()
>        edges.append(edge)
>
> ## Creating wire and face
> edgeWire = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeWire(edges[1]).Wire()
> edgeFace = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeFace(edgeWire).Shape()
> display.DisplayShape(edgeFace)
> start_display()
>

Hi Balint,

Jelle's fix works perfectly, and is quite more pythonic than your code,
however you may know *why* the planar face is not displayed. So here is a
code that reproduces the issue you reported:

#######
from OCC.BRepPrimAPI import *
from OCC.BRepBuilderAPI import *
from OCC.Utils.Construct import *
from OCC.gp import *
import math

from OCC.Display.SimpleGui import *
display, start_display, add_menu, add_function_to_menu = init_display()

## Creating circle
centerCircle = gp_Pnt(1, 0, 0.5)
myAX2 = gp_Ax2(centerCircle,gp_Dir(1, 0, 0))
circle = gp_Circ(myAX2, 0.2)
edge = BRepBuilderAPI_MakeEdge(circle, 0, 2.0*math.pi).Edge()
wire = BRepBuilderAPI_MakeWire(edge).Wire()

## Creating cylinder from extrusion of wire
extrusion_vector = gp_Vec(2., 0., 0.)
cylinderSurface = BRepPrimAPI_MakePrism(wire, extrusion_vector).Shape()
planeFace = BRepBuilderAPI_MakeFace(wire).Shape()

display.DisplayShape(planeFace)
display.DisplayShape(cylinderSurface)
start_display()
############

You will notice that the 'planeFace' is not displayed. However, if you
switch the cylinderSurface and planeFace lines as following:
planeFace = BRepBuilderAPI_MakeFace(wire).Shape()
cylinderSurface = BRepPrimAPI_MakePrism(wire, extrusion_vector).Shape()

Then this time, both planarFace and cylindersSurface will be displayed!
Weird, no? There are strange things happening here with C++ references and
pointers. Jelle's make_prim function actually pass the 'True' Parameter to
the BRepPrimAPI_MakePrism class. Here is a part of the OCC documentation
related to the BRepAPI_MakePrism class:
"""
//! Builds the prism of base S and vector V. If C is true, <br>
//!          S is copied. If Canonize is true then generated surfaces <br>
//!          are attempted to be canonized in simple types <br>
Standard_EXPORT BRepPrimAPI_MakePrism(const TopoDS_Shape& S,const gp_Vec&
V,const Standard_Boolean Copy = Standard_False,const Standard_Boolean
Canonize = Standard_True);
"""

Just passing the 'True' parameter to BRepPrimAPI_MakePrism then makes the
__init__ method copy the S shape and build the prism from that function.
It's enough to solve the references/pointers/shared objects issues.

Then, here is my solution to fix your code : just move the line
cylinderSurface = BRepPrimAPI_MakePrism(wire, extrusion_vector).Shape()
to
cylinderSurface = BRepPrimAPI_MakePrism(wire, extrusion_vector,True).Shape()

Less pythonic than Jelle (how could it be *more* pythonic than Jelle ;) ?),
but I hope you will deeply understand what happened.

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

Reply via email to