For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

How to get the TDF_Label of the currently selected shape?

Marko Knöbl's picture


I am developing a CAD program in which I am using a TDocStd_Document and displaying its contents through a V3d_Viewer.
Now I am searching for a way to get the label of the shape which is currently selected in the viewer. I can get the shape by calling "myViewer->Context->SelectedShape()".
Is there a simple way to retrieve the associated TDF_Label?
I want to use it e.g. to change the color of the shape or to remove the shape from the document.

PS: I'm using the pythonOCC bindings to work with OCC. I only have little experience with C++, but I think I will be able to understand code examples if you post some.

Thanks in advance,

seumonkey's picture

Hi, try this:
if (myContext->MoreCurrent()) {
Handle(TPrsStd_AISPresentation) ObjectPrs = Handle(TPrsStd_AISPresentation)::DownCast(myContext->Current()->GetOwner());
if (ObjectPrs.IsNull())
return NULL;

TDF_Label Label = ObjectPrs->Label();

Marko Knöbl's picture

Thanks for your answer!

Unfortunately it does not work as expected for me: It always returns label "0:1:1:1" no matter which shape I selected.
I can imagine that this is because I am already making an error when adding a shape to my document (I never truly understood what was going on there, but it mysteriously worked) - Could that be the cause of the problem?

Anyhow now I see that I'll have to use TPrsStd_AISPresentation for this task - This is already very valuable information for me.

Thank you!