Bryan Cole a écrit : > Hi, > Hi Bryan,
> I'm in the process of writing a simple OCAF document browser. I can > browse the TDF_Label tree OK, but accessing the attributes is proving > tricky. Mostly, the problem is getting data out of OCC types back to > python. > > Can anyone suggest how to get the content out of a > TCollection.TCollection_ExtendedString ? > > Also, converting Standard_GUID to a python value is difficult. I'd like > to access the GUID as a string. To use the Standard_GUID::ToCString() > method, I need to pre-create a C-string (full of zeros), and pass it in > by reference (as a Standard_PCharacter). Phew, C++ make things so > hard... Does SWIG give us any tools to construct types manually (from > ctypes objects perhaps)? > I suggest the following 'manual tweak' to the file Standard.i: just add these lines after the definition of the class Standard_GUID: %extend Standard_GUID { Standard_PCharacter ToString() { Standard_PCharacter tmpstr=NULL; tmpstr = new char[strlen("00000000-0000-0000-0000-000000000000")+1]; strcpy(tmpstr,"00000000-0000-0000-0000-000000000000"); $self->ToCString(tmpstr); return tmpstr; } }; After the compilation is done, this is an example of how to use: >> import uuid >> u = uuid.uuid1() >> u UUID('652936b0-2ebd-11de-9469-001422f3600c') >> from OCC.Standard import * >> s = Standard_GUID('%s'%u) >> s.ToString() '652936b0-2ebd-11de-9469-001422f3600c' Cheers, Thomas _______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users