2010/2/25 Willy Hertz <willy.he...@yahoo.com>

> The conversion between TopoDS_Shapes, Vertices and Coordinates is driving
> me crazy.
> My goal is to find the vertex coordinates of any displayed object. I found
> a few similar questions here and in the opencascade forums, but the replies
> seem not to work with pythonOCC. I am trying the following procedure:
> 1) extract all vertices with TopExp_Explorer
> 2) convert each TopoDS_Shape into a Vertex
> 3) get the coordinates using OCC.BRep.Brep_Tool.Pnt(vertex) ... not
> discussed in this post
>
> Please have a look at the following code, which creates an Edge and
> attempts to extract the vertices.
> Unfortunately in step 1) three shapes with ShapeType=Vertex are returned,
> the first two being identical and pointing to Null. Why?
>

Hi Willy,

This point has already been discussed on this ml (I don't have the reference
to the discussion, will find it).

Jelle implemented a topology traversing algorithm on top of the built-in
TopExp_Explorer class. I sugest you use it. It can be done very simply:

from OCC.Topology import topo
t = Topo(my_TopoDS_Shape)

Then you can iterate to ver shapes, vertices, edges etc:

for vertex in t.vertices():
    ...do_whatever_you_want

Have a look at the source code of the Topo class (
http://code.google.com/p/pythonocc/source/browse/trunk/src/addons/Utils/Topology.py)
and/or the documentation (http://www.pythonocc.org/APIREF/index.html).

Best Regards,

Thomas


> In step 2) the method TopoDS.Vertex(vs[2]), applied to the third shape
> vs[2] complains about "<type 'exceptions.RuntimeError'>:
> Standard_TypeMismatch".
>
> How do I retrieve the Vertex coordinates of an Edge or (later) any other
> Shape?
>
> Regards,
> Willy
>
> The code example:
> from OCC.BRepBuilderAPI import *
> from OCC.TopoDS import *
> from OCC.TopAbs import *
> from OCC.TopExp import *
> from OCC.gp import *
>
> e=BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,0),gp_Pnt(0,0,1)).Edge();
> exp=TopExp_Explorer()
> exp.Init(e,TopAbs_VERTEX)
> vs=[exp.Current()]
> exp.Next()
> vs=vs+[exp.Current()]
> exp.Next()
> vs=vs+[exp.Current()] #strangely 3 vertices are found
>
> print 'identical:'
> print vs[0]==vs[1] #True
> print vs[1]==vs[2] #False
> print 'IsNull:'
> print vs[0].IsNull() #True
> print vs[1].IsNull() #True
> print vs[2].IsNull() #False
>
> tds=TopoDS()
> vx=tds.Vertex(vs[2]) #ERROR: <type 'exceptions.RuntimeError'>:
> Standard_TypeMismatch
> print vx
>
>
> _______________________________________________
> Pythonocc-users mailing list
> Pythonocc-users@gna.org
> https://mail.gna.org/listinfo/pythonocc-users
>
>
_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to