2

What is the syntax to add option/types to a modifier line of py.

enter image description here

thanks

Sam Hanks
  • 560
  • 2
  • 11
  • 1
    Operators don't return the object they act upon. For creating a modifier you might as well use mod = bpy.context.active_object.modifiers.new(type="SCREW", name="Your modifier name") and then mod.axis or mod.angle – Gorgious Nov 18 '21 at 22:34

1 Answers1

1

The syntax of Python allows you to add no more than one dot operator to a function return, so you can't add a second one. Further, if you do add one dot operator, you can't access the return value from the function anymore, and so can't use the dot operator on it again.

Thus,

bpy.context.active_object.modifiers.new(type="SCREW", name="Your modifier name").axis = 'X'

is legal because bpy.context.active_object.modifiers.new returns a Modifier and you can immediately use the modifier. You will see this form in a few sample programs but it's generally not a good idea.

It is equivalent to mod = bpy.context.active_object.modifiers.new(type="SCREW", name="Your modifier name") ; mod.axis = 'X' ; del mod

But once you've done the equivalent of deleting mod, you can't access it again.

So the typical solution would be to do the assignment to retrieve the result of the function call, and then use that object to set the values, as in the answer mention in a comment on the question.

mod = bpy.context.active_object.modifiers.new(type="SCREW", name="Your modifier name")
mod.axis = 'X'
mod.angle = 6.28310
etc
Gorgious
  • 30,723
  • 2
  • 44
  • 101
Marty Fouts
  • 33,070
  • 10
  • 35
  • 79
  • 1
    Marty, It worked great! Thanks for the education and the example. It will be nice to work through the many modifiers I use and customize them to a more specific first-time assignment. – Sam Hanks Nov 19 '21 at 15:18