How to copy Appearance from an object to other(s)?

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

How to copy Appearance from an object to other(s)?

Post by DorinDXN »

Hi all, hope you're well :)

In FreeCAD if I have an oject with Appearance set with material colors etc.
How to copy and appply its appearance to other object(s)?

cheers,
Dorin
domad
Veteran
Posts: 2051
Joined: Mon Jun 22, 2020 12:16 pm

Re: How to copy Appearance from an object to other(s)?

Post by domad »

DorinDXN wrote: Tue Jan 31, 2023 10:47 am ....
Hi DorinDXN, Greetings to the Community!
... from "settig Style" you can create a style and apply it to another object
Attachments
setting_Style.png
setting_Style.png (88.37 KiB) Viewed 762 times
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to copy Appearance from an object to other(s)?

Post by DorinDXN »

Thanks for quick reply, like I said it is about material colors.

If you select a cube in Part wrokbench then right-click and choose Appearence,
then Select Material as bronze, then click on [...] and adjust the colors...

There is no save properties as preset, nor copy.

How to apply that Appearance to other objects without going through every color?

cheers,
Dorin
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: How to copy Appearance from an object to other(s)?

Post by heron »

DorinDXN wrote: Tue Jan 31, 2023 12:54 pm How to apply that Appearance to other objects without going through every color?
With a bit of Python coding, it is possible to apply one object's color to others:

Code: Select all

sel = Gui.Selection.getSelection()
sel_origin = sel[0]
color_origin = sel_origin.ViewObject.ShapeColor

if len(sel)<2:
    App.Console.PrintMessage("select at least two objects")
else:
    for i in sel:
        if i.Name == sel_origin.Name:
            pass
        i.ViewObject.ShapeColor = color_origin
The color of the first selected object will be applied to all other objects.
Use:
- Select two or more objects.
- Run the code. You can do it using a macro or just copy the code and paste it into the Python Console.

It would be possible to extend the code and add all the appearance properties that you want to be inherited.
DorinDXN
Posts: 66
Joined: Sat Oct 31, 2020 8:07 am

Re: How to copy Appearance from an object to other(s)?

Post by DorinDXN »

Thank you for reply,
I noticed only after I had an work-around I was happy with

I made some buttons on a toolbar to a set speciffic material to all selected objects
e.g. this is for black shiny Al.

Code: Select all

import FreeCAD as App, FreeCADGui as Gui
s=FreeCADGui.Selection.getSelection()
sc=len(s)
for p in range(sc):
	if not(("Base" == App.ActiveDocument.getObject(s[p].Name).ViewObject.DisplayMode) or ("Group" == App.ActiveDocument.getObject(s[p].Name).ViewObject.DisplayMode)):
		App.ActiveDocument.getObject(s[p].Name).ViewObject.DisplayMode="Shaded"
	App.ActiveDocument.getObject(s[p].Name).touch()
	if (hasattr(App.ActiveDocument.getObject(s[p].Name).ViewObject, 'ShapeMaterial')):
		r=43
		g=43
		b=43
		col=(r/255.0,g/255.0,b/255.0,1.0)
		App.ActiveDocument.getObject(s[p].Name).ViewObject.ShapeMaterial.DiffuseColor=col
		r=32
		g=32
		b=32
		col=(r/255.0,g/255.0,b/255.0,1.0)
		App.ActiveDocument.getObject(s[p].Name).ViewObject.ShapeMaterial.AmbientColor=col
		r=0
		g=0
		b=0
		col=(r/255.0,g/255.0,b/255.0,1.0)
		App.ActiveDocument.getObject(s[p].Name).ViewObject.ShapeMaterial.EmissiveColor=col
		r=150
		g=150
		b=150
		col=(r/255.0,g/255.0,b/255.0,1.0)
		App.ActiveDocument.getObject(s[p].Name).ViewObject.ShapeMaterial.SpecularColor=col
		sn=0.99
		App.ActiveDocument.getObject(s[p].Name).ViewObject.ShapeMaterial.Shininess=sn
	App.ActiveDocument.getObject(s[p].Name).touch()	
App.ActiveDocument.recompute()

cheers,
Dorin
Post Reply