0

Following this Stack Exchange page:

How to set the default vertex count to added geometry?

I was able to effectively override the default property for the circle, cylinder and UV sphere.

When I followed the exact principle, imported the MESH_OT for torus primitive and try to override its defaults, blender fails at importing its MESH_OT module.

Code:

from bpy.types import (
    MESH_OT_primitive_torus_add
    )

According to Blender, this can not be imported, I fail to understand why!

If anyone has experience with this and has successfully done so, please lend a hand.

Here is a screenshot of the error message: enter image description here

unwave
  • 1,643
  • 5
  • 14
TeaCrab
  • 559
  • 2
  • 8
  • How exactly did you override in this case? – satishgoda Jun 22 '17 at 00:54
  • It's pretty clearly demonstrated in the link to the other post. I did exactly the same. – TeaCrab Jun 22 '17 at 00:55
  • 1
    Have a look at 2.78/scripts/startup/bl_operators/add_mesh_torus.py You can from bl_operators.add_mesh_torus import AddTorus change default params and re-regisiter. Btw the stackexchange link above returns a 404, as it is the condensed ( "blah...blah") version. – batFINGER Jun 22 '17 at 05:55
  • Hey, thank you very much. Importing from bl_operators worked! I'm still curious about what's the principal behind it. There seem to be a big difference between the torus and other primitives of how they are created? PS: I have no clue why the page went offline. I got to see it yesterday for the method. @batFINGER – TeaCrab Jun 22 '17 at 11:06

1 Answers1

1

The issue seems to be where you are trying to do the import, I expect the script you are adding is read too early to get access to bpy.types. While there is a way to alter the default setting, it doesn't seem to effect creating new objects, my guess is that the presets system overrides the defaults.

If you are adding a torus with a python script you can set the parameters used in your script.

bpy.ops.mesh.primitive_torus_add(major_segments=12, minor_segments=8)

For adding objects manually, the best way I can see is to use the presets system. You do this by adding a torus, then use the operator properties panel to adjust the options used, then click the + next to operator Presets and give it a name.

name a preset

then your preset options will be available.

operator properties with presets

sambler
  • 55,387
  • 3
  • 59
  • 192
  • Thank you for this. I know there are presets, but I wanted a way using script. – TeaCrab Jun 22 '17 at 11:08
  • You can specify settings to a bpy.ops call, to change the defaults that are used when you manually add a torus you will need to alter add_mesh_torus.py, or replace the operator with your own. Even if you change the apparent default with bpy.types.MESH_OT_primitive_torus_add.major_segments[1]['default'] = 12 it isn't used when you add a torus, it appears that the presets override the default settings. – sambler Jun 22 '17 at 14:25
  • I'm already able to override the properties using the method commented in the question by @batFINGER. I will mark your answer as approved to close this question. – TeaCrab Jun 22 '17 at 14:30