ddg.blender.props module
- ddg.blender.props.hide_previous(func: Callable[[P], Union[bpy.types.Collection, bpy.types.Object]], /) Callable[[P], None][source]
Show and hide collections which depend on parameters.
- Parameters:
- funcCallable
A function that returns either a Blender object or collection. Every Blender object and collection returned by
funcmust be created withinfunc. Every parameter must be hashable.
- Returns:
- Callable
This function has the same signature as
func. It caches the output and selectively hides Blender objects and collections returned byfuncsuch that only the last call is visible.
Examples
>>> import bpy >>> import ddg >>> >>> @ddg.blender.props.hide_previous ... def f(x): ... # The collection is created within f and cannot be factored out. ... collection = ddg.blender.collection.collection("Collection") ... p = ddg.arrays.Points((x, 0, 0)) ... # The object is created within f and cannot be factored out. ... ddg.blender.convert(p, "Point", collection=collection) ... return collection ... >>> set(bpy.data.collections) set() >>> set(bpy.data.objects) set()
Calling
fcreates a new collection.>>> collection_0 = f(-5.3)
Note that the name of the collection and the Blender object it contains enumerate the number of calls to
f.>>> collection_0 bpy.data.collections['Collection 0'] >>> set(bpy.data.collections) {bpy.data.collections['Collection 0']} >>> set(collection_0.objects) {bpy.data.objects['Point 0']}
The results of the last (in this case also the first) call to
fare both visible.>>> collection_0.hide_render False >>> collection_0.hide_viewport False
Calling
fagain creates another collection.>>> collection_1 = f(2.7) >>> collection_1 bpy.data.collections['Collection 1'] >>> set(bpy.data.collections) {bpy.data.collections['Collection 0'], bpy.data.collections['Collection 1']} >>> set(collection_1.objects) {bpy.data.objects['Point 1']}
The results of the previous calls to
fare now hidden. In this example, only one collection, namely collection_0, is hidden. The results of the last call tofare visible.>>> collection_0.hide_render True >>> collection_0.hide_viewport True >>> collection_1.hide_render False >>> collection_1.hide_viewport False
If we pass -5.3 to
fa second time, we will get the cached result.>>> collection_0_again = f(-5.3) >>> collection_0 == collection_0_again True >>> collection_0.hide_render False >>> collection_0.hide_viewport False >>> collection_1.hide_render True >>> collection_1.hide_viewport True
- ddg.blender.props.add_props_with_callback_from_constructors(callback: Callable[[...], Any], positional_labels_constructors: dict[str, Callable[..., Any]], keyword_labels_constructors: dict[str, Callable[..., Any]]) None[source]
A more advanced version of
add_props_with_callback().Unlike
add_props_with_callback(), this function doesn’t infer what kind of Blender property to add. Instead, property constructors must be explicitly specified, which allows for control over the minimum and maximum value, step sizes and other property types.- Parameters:
- callbackCallable
This function is called whenever the properties’ value change.
- positional_labels_constructorsdict[str, Callable[…, Any]]
The keys are the labels of the properties. The values are Blender property constructors whose values will be passed to
callbackas positional arguments.- keyword_labels_constructorsdict[str, Callable[…, Any]]
The keys are the labels of the properties. The values are Blender property constructors whose values will be passed to
callbackas keyword arguments.
- Raises:
- ValueError
If the labels aren’t unique.
See also
Examples
See Finer Control over Properties in the user’s guide.
- ddg.blender.props.add_props_with_callback(callback: Callable[[...], Any], arg_labels: Sequence[str], *default_args: Any, **default_kwargs: Any) None[source]
Add Blender properties with a callback.
- Parameters:
- callbackCallable
This function is called whenever the properties’ value change.
- arg_labelsSequence[str]
Labels for the properties. The number of labels must equal the number of positional arguments of callback.
- *default_args
Default positional arguments for callback
- *default_kwargs
Default keyword arguments for callback
- Raises:
- ValueError
If the length of
arg_labelsisn’t equal to the number of positional arguments ofcallback.
Examples
See Animating ddg Objects in the user’s guide.
- ddg.blender.props.add_panel(prop_names: Sequence[str], text: str = '', panel_label: str = 'DDG Panel', idname: str = 'VIEW3D_PT_DDG', category: str = 'DDG')[source]
Create a Blender panel in the 3DViewport containing the properties.
- Parameters:
- prop_namesSequence of str
The properties’ names to be added to the panel.
- textstr
Text to be added at the beginning of the panel.
- panel_labelstr
Text used as the visible title of the panel.
- idnamestr
Name used internally to identify the panel. Must begin with
VIEW3D_PT_.- categorystr
String used as the name of the tab.
- Raises:
- ValueError
If
idnamedoes not start withVIEW3D_PT_.
- ddg.blender.props.update_func(callback: Callable[[...], Any], arg_names: Sequence[str], kwarg_names: Sequence[str]) Callable[[Any, Any], None][source]
Turn a function into a property update function.
- Parameters:
- callbackCallable
Callable which will be called when the properties value change.
- arg_namesSequence of str
The names of the properties corresponding to positional arguments of callback.
- arg_namesSequence of str
The names of the properties corresponding to keyword arguments of callback.
- Returns:
- updateCallable
A function to be used in e.g.
bpy.props.IntProperty(update=update).
- ddg.blender.props.set_prop_if_not_set(blender_id: Any, prop: str) None[source]
Set
blender_id.proptovalueif notblender_id.is_property_set(prop).This is a no-op when executed after loading from a .blend file that previously set
prop.- Parameters:
- blender_idAny
- propstr
- ddg.blender.props.save_props(file_name, bstruct, props)[source]
Save properties of a Blender object to a file.
- Parameters:
- file_namestr
The name of the file to save the props to.
- bstructbpy_struct
The Blender object whose properties should be saved.
- propsA list of str
Each string is the name of a property.
- ddg.blender.props.load_props(file_name, bstruct)[source]
Load the properties from and set them to a Blender object.
Assumes that the file was generated with
ddg.blender.props.save_props.- Parameters:
- file_namestr
The name of the file from which to load the props.
- bstructbpy_struct
The Blender object whose properties should be set.