Equivalent rs.MatchObjectAttributes in RhinoCommon?

What is the simplest way of copying all attributes from one object to another with RhinoCommon ?

I tried the following (with Python), but it seems not to produce any change:

import Rhino

go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select first object")
go.Get()
object1 = go.Object(0).Object()

go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select second object")
go.DisablePreSelect()
go.Get()
object2 = go.Object(0).Object()

object1.Attributes = object2.Attributes.Duplicate()

Hi @felix.mariotto

import Rhino

# Get the first object
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select first object")
go.Get()
object1 = go.Object(0).Object()

# Get the second object
go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select second object")
go.DisablePreSelect()
go.Get()
object2 = go.Object(0).Object()

# Copy attributes from object2 to object1
object1.Attributes = object2.Attributes.Duplicate()

# Commit changes
object1.CommitChanges()

You must commit the changes in order for the attributes to update
Hope this helps,

Farouk

3 Likes

Thanks a lot Farouk, this CommitChanges is what was missing !