Can't update appearance with script?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
bwheelz360
Posts: 14
Joined: Tue Feb 04, 2020 3:20 pm

Can't update appearance with script?

Post by bwheelz360 »

Hello all

I am building a model from a script.
As part of this script, I am attempting to change the color of certain objects with this line of code:

Code: Select all

doc.getObject(NewSliceName).ViewObject.ShapeColor = (0.4, 0.5, 0.3, 1.0)
This is actually successful, as you can see in the attached screenshot. The problem is, it doesn't actually update in the GUI. I have used this method before with no problems, and I can't figure out what I'm doing wrong here... I feel like I must be just missing some kind of update command?

I've attached my scripts. To recreate the issue run MultiSlicePhantomExample as a FreeCAD macro. Both scripts must be in the same directory.

Thanks!
Brendan
Screenshot from 2021-12-08 10-03-15.png
Screenshot from 2021-12-08 10-03-15.png (131.08 KiB) Viewed 3089 times
Attachments
PhantomBuilder.py
(14.86 KiB) Downloaded 40 times
MultiSlicePhantomExample.py
(1.36 KiB) Downloaded 37 times
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Can't update appearance with script?

Post by onekk »

FreeCAD version?

usually the data you are working on are visible in the View Tab of the combo view.

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/
chrisb
Veteran
Posts: 53920
Joined: Tue Mar 17, 2015 9:14 am

Re: Can't update appearance with script?

Post by chrisb »

Does it need a recompute to refresh the gui?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Can't update appearance with script?

Post by onekk »

It seems OP is showing "Display settings window" I'm on mobile so screen real estate is not helping.

If I guess right, if OP will look in the right place it will see that data are updated.

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/
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Can't update appearance with script?

Post by TheMarkster »

The data is updated, but on the screen the color isn't the one held by the Shape Color property. I don't know why. Set it to something distinctive like red and the problem still persists. You can see in the view tab clearly the color should be red, but it isn't. If you set to another color in the gui and then back to red then the red shows in the 3d view. recompute() and Gui.updateGui() do not force a refresh.
bwheelz360
Posts: 14
Joined: Tue Feb 04, 2020 3:20 pm

Re: Can't update appearance with script?

Post by bwheelz360 »

Thanks theMarkster, that’s exactly what I am experiencing
It’s free cad 0.18.something for the record.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Can't update appearance with script?

Post by TheMarkster »

Try to simplify into the simplest possible script where the issue still occurs. It might be helpful for diagnosing the issue. There seems to be a lot of "z-fighting" with the objects getting produced.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Can't update appearance with script?

Post by onekk »

Try to post simply the view Tab and not "display properties" as in the first image.

0.18 is old, so maybe better to use 0.19 (that is the actual stable release and is at his third update 0.19.3)

From the information given, this is not a bug, simply a "wrong place" where to look.


"display properties" are the default colors that a Shape will use if nothing is changed in his ViewObject properties.

using:

Code: Select all

doc.getObject(NewSliceName).ViewObject.ShapeColor = (0.4, 0.5, 0.3, 1.0)
You are changing the color only for the object "NewSliceName" and not for all the "documentObjects".

See this image:
shapecolor.png
shapecolor.png (25.88 KiB) Viewed 2766 times
Please post this tab with your actual setting, probably you will see that the property Shapecolor is what you want.

If you want to change "all objects, colors" you have to do something different.


So the image is perfectly right, as you are seeing "default screen properties" and not the Object properties that are in the "View Tab" of "NewSliceName".

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: 3440
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Can't update appearance with script?

Post by freedman »

I'm planning to post a small macro "Color copy"; Click on one object store colors, then click the next object to duplicate the colors. On my initial code I could copy the data but could not figure out what is required to make it stick. It seemed to work with Bodies but Links are complicated, they have overrides and hierarchy.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Can't update appearance with script?

Post by TheMarkster »

freedman wrote: Fri Dec 10, 2021 2:56 pm I'm planning to post a small macro "Color copy"; Click on one object store colors, then click the next object to duplicate the colors. On my initial code I could copy the data but could not figure out what is required to make it stick. It seemed to work with Bodies but Links are complicated, they have overrides and hierarchy.
Does it work where individual faces have different colors? I didn't think that was accessible via python.
Post Reply