sc.doc.ActiveDoc.Objects.ModifyAttributes example?

Hi,

Can I get an example using:

sc.doc.ActiveDoc.Objects.ModifyAttributes()

Help on built-in function ModifyAttributes

| ModifyAttributes(…)
| ModifyAttributes(self: ObjectTable, objectId: Guid, newAttributes: ObjectAttributes, quiet: bool) -> bool
|
| Modifies an object’s attributes. Cannot be used to change object id.
|
| objectId: Id of object to modify.
| newAttributes: new attributes.
| quiet: if true, then warning message boxes are disabled.
| Returns: true if successful.
| ModifyAttributes(self: ObjectTable, obj: RhinoObject, newAttributes: ObjectAttributes, quiet: bool) -> bool
|
| Modifies an object’s attributes. Cannot be used to change object id.
|
| obj: object to modify.
| newAttributes: new attributes.
| quiet: if true, then warning message boxes are disabled.
| Returns: true if successful.
| ModifyAttributes(self: ObjectTable, objref: ObjRef, newAttributes: ObjectAttributes, quiet: bool) -> bool
|
| Modifies an object’s attributes. Cannot be used to change object id.
|
| objref: reference to object to modify.
| newAttributes: new attributes.
| quiet: if true, then warning message boxes are disabled.
| Returns: true if successful.
|

Where is this self: ObjectTable coming from?

gives you

It means that it is an instance method, so you call it on an instance, in the example case the instance of ObjectTable is scriptcontext.doc.Objects

The self parameter name is a convention in the Python world for the instance of a class.

1 Like

You should make the search in Discourse to search also inside GitHub :wink:

Just bookmark https://github.com/mcneel/rhino-developer-samples/ and use it as your first go-to place for questions on usage of functions :slight_smile:

I use it regularly too!

1 Like

I know this, but from the help of that method it is not clear where it is coming from.

Any class that ends in Table like ObjectTable (but see https://developer.rhino3d.com/api/RhinoCommon/html/N_Rhino_DocObjects_Tables.htm for the others) have an instance in the (instance of) RhinoDoc.

This here.

If it was ModifyAttributes(self:doc.Objects it would be clearer.

I don’t know if I have to look in ActiveDoc’s objects or the Objects that I have selected with GetObjects(). This makes it not clear enough.

You’ll find that GetObjects() does not return an ObjectTable - that should be pretty clear…

Why do I have to try? It could’ve been explained in the help and see it when I open the brackets!

You don’t try it, you read the doc/help

image

just as you read the help for ModifyAttributes.

That should then of course be ModifyAttributes(self:Rhino.DocObjects.Tables.ObjectTable, since doc doesn’t tell you what it is. I suppose could be useful to have full names, but then signatures will become rather tedious to read with even a moderate amount of parameters.

:thinking:

image

No ObjectTable under Rhino.DocObjects

Yes, I typoed, I meant Rhino.DocObjects.Tables (which I already linked to earlier). Updating original typoed reply.

Ah, and I didn’t pay attention too.

Rhino.DocObjects.Tables.ObjectTable is also not clear enough when you’re inside GetObjects(). Finally do you mean all objects in the document or the list of objects that you’ve selected?

See, this is the confusion that forces me to always ask for examples.

Another helpful thing would be some kind of TypeBrowser automation that will automatically highlight the type you’re looking for inside the API browser.

Not sure what you are getting at but GetObjects() != ObjectTable.

The first gives you a list of Guid. The second you can iterate over like so: selobs = [o for o in sc.doc.Objects if o.IsSelected(False)] # a list of RhinoObject instances, that is selected objects from the document.

And this is why I say RhinoCommon api is confusing (to not use a harsher word)

I don’t want to sound rude, but I think your active aversion of C# is hindering you in grokking the documentation. I honestly think that you’ll benefit if you take the time - a few days, say - to at least understand C# (and through that .NET in general) a bit better. Not saying you have to switch, no. Feel free to continue using Python, it is a nice language. But I constantly get the feeling you make things unnecessarily hard for yourself.

/Nathan

Not sounding rude at all. And you’re probably right. This is the same as to why I don’t speak German I hate it, period. I hate how it sounds. Same with C# I hate the syntax. But the main reason is - time is a limited resource.

RhinoCommon’s api is not noob friendly and I stand behind what I said above. It is unclear in the help of that command what is required.

Well, maybe that’s because it’s aimed at a more advanced level, assumes some foreknowledge, and is thus more abstract. That’s why rhinoscriptsyntax exists, it’s more explicit and easier to grasp.

I’m not saying the RhinoCommon doc can’t be improved, it can, but once you do learn how to read it and how the OOP stuff basically works, it is adequate for a lot of things.

1 Like

And this kind of stuff doesn’t help anyone trying to learn… :grimacing:

image

3 Likes

You know, I can live with that if we could get more Python examples.