How do I get the item ID from a selected entity in a sketch?

m.s.peglar
Participant

How do I get the item ID from a selected entity in a sketch?

m.s.peglar
Participant
Participant

Hi everyone,

 

I'm trying to get the coords of the start point of a user selected line inside a sketch. I have managed to get the entity and test that it is a line, but how do I then get the line ID of the entity so i can get the coords?

I *think* it might be something to do with cast but I really can't work it out!

 

thanks in advance!

 

Ptr<Selection> selection1 = ui->activeSelections()->item(0);
Ptr<Base> selectedEnt1 = selection1->entity();

if (selectedEnt1->objectType() != LINE_TYPE) {
  ui->messageBox("Selected entities are not sketch lines.");
  return false;
}

int ID = *HOW DO I GET THIS?*
Ptr <Point3D> p0 = lines->item(ID)->startSketchPoint()->worldGeometry();
double x = p0->x();
double y = p0->y();
double z = p0->z();

0 Likes
Reply
Accepted solutions (2)
768 Views
2 Replies
Replies (2)

nnikbin
Collaborator
Collaborator
Accepted solution

Hi @m.s.peglar 

You are right, one solution is casting. You can use the automatic casting performed by the Ptr template and you do not need any ID.

 

Ptr<SketchLine> sketchLine = Ptr<SketchLine>(selectedEnt1);
Ptr<Point3D> p0 = sketchLine->worldGeometry()->startPoint();

 

Here in Object Types and Casting section you can find useful relevant information.

0 Likes

m.s.peglar
Participant
Participant
Accepted solution

You couldn't have answered better! Thanks for your help again Navid! It's really very appreciated 🙂

0 Likes