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?
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
[email protected]
https://mail.gna.org/listinfo/pythonocc-users