enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
243 stars 33 forks source link

LIVENODING 1044 / Thinking Macros and Basic Operators #429

Open enzyme69 opened 6 years ago

enzyme69 commented 6 years ago

Creating a new modifier "REMESH" for bunch of objects

import bpy
obs = bpy.context.selected_objects
for ob in list(obs):
    ob.modifiers.new("blah", "REMESH") # assign new modifier of type "REMESH" named "blah"
enzyme69 commented 6 years ago

Creating multiple modifier combo for bunch of objects:

import bpy
obs = bpy.context.selected_objects
for ob in list(obs):
    ob.modifiers.new("blah1", "REMESH")
    ob.modifiers.new("blah2", "WIREFRAME")
    ob.modifiers.new("blah3", "SUBSURF")
enzyme69 commented 6 years ago

For a single object, you can always run operators with ACTIVE OBJECT selected.. for example: A Combo of creating Remesh - Wireframe - Subsurf and few modification:

import bpy

bpy.ops.object.modifier_add(type='REMESH')
bpy.ops.object.modifier_add(type='WIREFRAME')
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.context.object.modifiers["Wireframe"].use_relative_offset = True
bpy.context.object.modifiers["Wireframe"].thickness = 0.02038
bpy.context.object.modifiers["Remesh"].octree_depth = 3
bpy.context.object.modifiers["Remesh"].mode = 'SMOOTH'
enzyme69 commented 6 years ago

Blender Operators documentations: https://docs.blender.org/api/blender_python_api_2_76_1/bpy.ops.html

SV Macro good read: https://github.com/nortikin/sverchok/wiki/Macros https://github.com/nortikin/sverchok/issues/1538 https://github.com/nortikin/sverchok/issues/1537

Related "Script Node Lite": https://github.com/nortikin/sverchok/issues/942

enzyme69 commented 6 years ago

Ideally: Macros or a series of commands operators can become a button and can work on multiple objects, regardless. This is definitely possible with some special arrangement.

In general, BPY OPS is a good start to make snippet of MACROS. There are many occasions when instead of using the BPY OPS, we simply use the object "methods".