One object cannot update another

Need help, or want to share a macro? Post here!
User avatar
iplayfast
Posts: 135
Joined: Sat Sep 07, 2019 6:55 am

One object cannot update another

Postby iplayfast » Wed Sep 16, 2020 6:48 am

I'm trying to split things out of my cycloidal gearbox to make it a bit more readable, and have somehow introduced a bug that I can't figure out. Any help is appreciated. I'm using FreeCad 19, fresh compile.

To reproduce (assuming a linux box)
cd ~/.FreeCAD/Mod
git clone https://github.com/iplayfast/CycloidGearBox.git
cd CycloidGearBox
git checkout splitfiles
start up free cad

you will have new CycloidGearBox workbench, select it.
The toolbar will have one orange icon, click it.
You should see a new document and the gearbox showing up.

The way it works is GearBoxParameters holds all the parameters of the gearbox, as all the parts need to reference common values.
If you change a parameter in GearBoxParameters the model changes (and all the subparts properties reflect the change).

For example, changing the GearBoxParameters.pin_disk_diameter to 30 will make the outer disk small.
If you look at the pin_disk.pin_disk_diameter it will be also set to 30.
So far so good.

The bugs
1. If you change pin_disk.pin_disk_diameter the GearBoxParameters.pin_disk_diameter is updated, but the model doesn't change. (even forcing recalculation doesn't update the model).

2. Changing the value in any property shouldn't cause the recalculate until enter is pushed.

again thanks for any help you can give.
chrisb
Posts: 27203
Joined: Tue Mar 17, 2015 9:14 am

Re: One object cannot update another

Postby chrisb » Wed Sep 16, 2020 6:53 am

Is this rather about Python programming? If so I would move it to the corresponding forum.
User avatar
iplayfast
Posts: 135
Joined: Sat Sep 07, 2019 6:55 am

Re: One object cannot update another

Postby iplayfast » Wed Sep 16, 2020 7:05 am

It is about python programming, but related to how objects work within freecad. If there is a better forum please feel free to move it.
chrisb
Posts: 27203
Joined: Tue Mar 17, 2015 9:14 am

Re: One object cannot update another

Postby chrisb » Wed Sep 16, 2020 7:28 am

I moved it to the Python forum. It may find more attention there.
User avatar
vanuan
Posts: 428
Joined: Wed Oct 24, 2018 9:49 pm

Re: One object cannot update another

Postby vanuan » Wed Sep 16, 2020 8:28 pm

chrisb wrote:
Wed Sep 16, 2020 7:28 am
I moved it to the Python forum. It may find more attention there.
Offtopic: maybe "Python scripting and macros" should be split into "users > addon showcase & user requests" and "developers > addon development and code". This clearly belongs to "development"
User avatar
iplayfast
Posts: 135
Joined: Sat Sep 07, 2019 6:55 am

Re: One object cannot update another

Postby iplayfast » Thu Sep 17, 2020 6:37 am

I think the question I have, (trying to boil it down) is
If my the python code updates
FreeCAD.getDocument('Unnamed').getObject('GearBoxParameters').pin_disk_diameter = '31 mm'

Nothing happens,

But if I put that in the console it updates.

I don't understand why.

Also, why is it that entering a number for a length immediately changes the length, shouldn't it wait until the return key is pushed?
chrisb
Posts: 27203
Joined: Tue Mar 17, 2015 9:14 am

Re: One object cannot update another

Postby chrisb » Thu Sep 17, 2020 10:09 am

iplayfast wrote:
Thu Sep 17, 2020 6:37 am
Also, why is it that entering a number for a length immediately changes the length, shouldn't it wait until the return key is pushed?
Some input fields cause an immediate change of the corresponding object. However, they don't trigger a recompute. You can see this with a Part cube being a member of a union. If you change e.g. the length of the cube, it changes on every keypress. The union recompute is delayed until enter is pressed.
User avatar
iplayfast
Posts: 135
Joined: Sat Sep 07, 2019 6:55 am

Re: One object cannot update another

Postby iplayfast » Thu Sep 17, 2020 2:15 pm

chrisb wrote:
Thu Sep 17, 2020 10:09 am
Some input fields cause an immediate change of the corresponding object. However, they don't trigger a recompute. You can see this with a Part cube being a member of a union. If you change e.g. the length of the cube, it changes on every keypress. The union recompute is delayed until enter is pressed.
Exactly. So how to cause this effect? Some of the calculations are CPU intensive and make no sense to do key by key.
chrisb
Posts: 27203
Joined: Tue Mar 17, 2015 9:14 am

Re: One object cannot update another

Postby chrisb » Thu Sep 17, 2020 4:17 pm

It seems to be fast enough for the basic primitives. If the same technique is used for rather complicated things, such as pads or pockets, there usually is - or should be! - a checkbox "Update view" or similar.
User avatar
iplayfast
Posts: 135
Joined: Sat Sep 07, 2019 6:55 am

Re: One object cannot update another

Postby iplayfast » Thu Sep 17, 2020 7:17 pm

chrisb wrote:
Thu Sep 17, 2020 4:17 pm
It seems to be fast enough for the basic primitives. If the same technique is used for rather complicated things, such as pads or pockets, there usually is - or should be! - a checkbox "Update view" or similar.
I feel that you are trying to help me, but I don't understand how this leads me to a coding solution. The python code I'm talking about does shape creations, and pads as needed for a rather complex set of objects. The best solution would be to set a variable to not update the property until the enter key is pressed. I don't know of such a variable.