Trying to detect when a Shapebinder is inserted in Body

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Trying to detect when a Shapebinder is inserted in Body

Post by freedman »

Lets say a new body is created and then a shapebinder is inserted, I can't find any way to detect the addition.
I have tried these slots but they don't trigger on inserting:

Code: Select all

void slotChangedDocument(const App::Document& Obj, const App::Property& Prop);
  
void slotCreatedObject(const App::DocumentObject& Obj);
  
void slotBeforeChangeObject(const App::DocumentObject& Obj, const App::Property& Prop);
   
void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);
I object slots only trigger on feature objects.
Any ideas?
Thanks
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Trying to detect when a Shapebinder is inserted in Body

Post by openBrain »

I would expect 'slotCreatedObject' to trigger. Maybe an issue in the code.
Just in case, did you also check slots of Gui document observer?
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Trying to detect when a Shapebinder is inserted in Body

Post by onekk »

freedman wrote: Thu Sep 29, 2022 2:56 pm Lets say a new body is created and then a shapebinder is inserted, I can't find any way to detect the addition.
What is the order:
  1. The new body is created
  2. A shapebinder is inserted
In other word you want to detect when in an existing Body a Shapebinder is inserted.

I would guess that:

Code: Select all

void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);
Is the right functions, if ShapeBinder or similar is a Property, it could be maybe a matter of property name.

At least if things works as in a Feature Python Object that is matching the name as string, when experimenting I have mispelled a property name and things were not triggered.

But is only a guess.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Trying to detect when a Shapebinder is inserted in Body

Post by freedman »

Sorry,sorry. I restarted FreeCAD and now it works. Thanks all. I'll try to remember to do that next time.

Edit: slotCreatedObject() does return the shapebinder name.
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Trying to detect when a Shapebinder is inserted in Body

Post by freedman »

My goals are to start a post about shapebinders. It seems to me that when a shapebinder is created (in the Active Body), the support object should be hidden and then a quick search thru the Doc and hide any other shapebinders with the same support.
If the shapebinder is hidden then the support object is shown.
Thanks again.
Post Reply