Ah, fantastic! I was going to post the same issue here, but have been just swamped at work. My work-around was to add all found shapes temporarily to a *TopTools_SequenceOfShape*, but the *ReInit()* way is much less of a hack.

By the way, the same issue happens when using *TopoDS_Iterator*, but it does not seem to have a ReInit method? E.g. here is how I currently work around this issue:

def GetShapeChildren(s):
   children = {}
   it = TopoDS_Iterator(s)
   totChildren = 0
   aSeq = TopTools_SequenceOfShape()
   while it.More():
       totChildren += 1
       ss = it.Value()
       aSeq.Append(ss)
       ss = aSeq.Value(aSeq.Length())
       stChildren = children.setdefault(subType, [])
       if ss not in stChildren:
           stChildren.append(ss)
       it.Next()
   return children

Any ideas?

- Frank


At the end of the iteration, e.g. when ex.More() is False, the TopExp_Explorer instance is cleared (with the Clear() method). Then all the references to subshapes are lost and your list contains NULL elements.

What's the correct way to store a references to sub-Shapes? I guess I
need a shallow copy of the shape-object returned by Explorer.Current()
but I can't figure how to achieve this.

You just have to ReInit() the TopExp_Explorer instance at the end of the loop.

Here is the corrected code:

from OCC import TopExp, BRepPrimAPI, TopAbs, TopoDS

box = BRepPrimAPI.BRepPrimAPI_MakeBox(10., 20., 30.)
ex = TopExp.TopExp_Explorer(box.Shape(), TopAbs.TopAbs_EDGE)

results = []

while ex.More():
    edge = TopoDS.TopoDS().Edge(ex.Current())
    print "is null?", bool(edge.IsNull())
    results.append(edge)
    ex.Next()
ex.ReInit() #to avoid loosing reference to objects found in the loop
for edge in results:
    print "null now?", bool(edge.IsNull())

cheers,

Cheers,

Bryan

Thomas


_______________________________________________
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