Bug in ObjectMaterialSource


#1

Hi Steve
ObjectMaterialSource has a bug in the loop for multiple objects where the material source is changed (fixed below). It was not using the Enum to get the material source. I tried to check it directly into GitHub but got a forbidden note. How can I use GitHub properly. Will I have to make a new branch? I am using it actually as a SVN repro.
Silvan

def ObjectMaterialSource(object_ids, source=None):
"""Returns or modifies the rendering material source of an object.
Parameters:
  object_ids = one or more object identifiers
  source [opt] = The new rendering material source. If omitted and a single
    object is provided in object_ids, then the current material source is
    returned. This parameter is required if multiple objects are passed in
    object_ids
    0 = Material from layer
    1 = Material from object
    3 = Material from parent
Returns:
  If source is not specified, the current rendering material source
  If source is specified, the previous rendering material source
  If object_ids refers to multiple objects, the number of objects modified
"""
id = rhutil.coerceguid(object_ids, False)
if id: # working with single object
    rhino_object = rhutil.coercerhinoobject(id, True, True)
    rc = int(rhino_object.Attributes.MaterialSource)
    if source is not None:
        rhino_object.Attributes.MaterialSource = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source)
        rhino_object.CommitChanges()
    return rc
# else working with multiple objects
if source is None: raise Exception("source is required when object_ids represents multiple objects")
for id in object_ids:
    rhino_object = rhutil.coercerhinoobject(id, True, True)
    rhino_object.Attributes.MaterialSource = System.Enum.ToObject(Rhino.DocObjects.ObjectMaterialSource, source)
    rhino_object.CommitChanges()
return len(object_ids)

(Steve Baer) #2

Thanks Silvan, I fixed this in SR8.

As far as github, I use the fork and pull model as described here
https://help.github.com/articles/using-pull-requests

People fork my repository to their own accounts and then send in pull requests for the changes that they’ve made. This is quite a bit different than subversion (it actually is one of the key reasons git has been so successful with open source projects in recent years.)

Thanks for pointing out the bug.