Page MenuHome

New Operator Set Collection Instance Offset from Object
Needs ReviewPublic

Authored by Duarte Farrajota Ramos (duarteframos) on Wed, Mar 11, 2:31 AM.

Details

Summary

This patch adds an operator to quickly set collection instance offset directly from object current object coordinates, rather than using the 3D Cursor.
It is accessible from the Collections Menu in the Properties Window > Object.

This can be useful in the common situation where an object actually represents the desired origin of a collection instance, like say an armature, or some master parent object.
Saves a few steps of snapping the 3D cursor to an object, every time it is moved and one wants to update collection origin to reflect the new position.

Is this a desirable operator? Would this be an acceptable feature to introduce?

Diff Detail

Event Timeline

Duarte Farrajota Ramos (duarteframos) retitled this revision from Operator to set collection offset from object to New Feature Set Collection Instance Offset from Object.Thu, Mar 12, 12:28 PM
Duarte Farrajota Ramos (duarteframos) edited the summary of this revision. (Show Details)

I created this small patch with a new feature I find useful for my workflows, not sure if this is acceptable or desirable to be included in Blender.
Added @William Reynish (billreynish) and @Julian Eisel (Severin) as reviewers since this affects both operators and UI for which you are module owners.

I'm not a coder or experienced in this kind of thing at all, so let me know if I did not follow the correct procedures.

Don't have a strong opinion on the feature itself, guess it can be useful.

This currently uses the location from object.location which does not have delta, constraint and parenting transforms applied. That may be something to consider. If you want that, you'd need to use object.matrix_world.translation instead.

Updated to use world transform matrix instead.

This currently uses the location from object.location which does not have delta, constraint and parenting transforms applied. If you want that, you'd need to use object.matrix_world.translation instead.

Indeed this seems like a better solution, diff updated accordingly

note I was also working on D6931: Transform: support 'Affect Only Origins' for collection instances (WIP), might be an alternative here.

This is indeed a feature I'd look forward to. It does make this patch look less relevant, so I understand if it not a desirable change.

This feature seems useful when using Collection Instances. You often need to be able to offset the origin.

However, this could also potentially be done via the Set Origin operator & menu instead - that would be more consistent with other object types. Although the two aren't necessarily mutually exclusive.

However, this could also potentially be done via the Set Origin operator & menu instead

That would indeed be another convenient place to access these, but it would probably have to be a slightly different operator for the menu.
When called from elsewhere how would the operator know which collection to ser the origin for? Should it go through all collections the active object belongs to? Should it iterate through all selected objects' collections?

Actually I currently have something like that setup for personal use already, it iterates through all selected objects then through all collections they belong to and batch sets origins for them.
This might however seem to behave unpredictably from a user point of view.
If several selected objects belong to the same collection how would it know where to set the offset from? Should it set origins for parent collections too?

This is roughly the sample code I use.

for obj in bpy.context.selected_objects:
			collections = obj.users_collection
			loc = obj.matrix_world.translation
			for col in collections:
				col.instance_offset = loc

Would something like this be desirable? Not sure if it would live up to the release quality standards

Brecht Van Lommel (brecht) requested changes to this revision.Thu, Mar 26, 2:35 PM

I don't think putting this in Set Origin works well, which collection(s) it applies to is unclear then.

release/scripts/startup/bl_operators/object.py
887–893

poll checks active_object, while execute uses object, which is not necessarily the same thing when pinning in the properties editor.

I would remove the mention of "active" entirely from the operator description and bl_idname.

This revision now requires changes to proceed.Thu, Mar 26, 2:35 PM

Updated to remove all references to "active object", make it consistent with polls function.

Duarte Farrajota Ramos (duarteframos) retitled this revision from New Feature Set Collection Instance Offset from Object to New Operator Set Collection Instance Offset from Object.Thu, Mar 26, 5:22 PM
Duarte Farrajota Ramos (duarteframos) edited the summary of this revision. (Show Details)

I don't think putting this in Set Origin works well, which collection(s) it applies to is unclear then.

Was this comment targeted at the diff?
At the moment this is currently only accessible from the Properties Window > Object > Collections > Collection Context Menu, as far as I can tell, unless it is being unintentionally added elsewhere to menus automatically.