0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ How exactly did you override in this case? $\endgroup$
    – satishgoda
    Jun 22 '17 at 0:54
  • $\begingroup$ It's pretty clearly demonstrated in the link to the other post. I did exactly the same. $\endgroup$
    – TeaCrab
    Jun 22 '17 at 0:55
  • 1
    $\begingroup$ 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. $\endgroup$
    – batFINGER
    Jun 22 '17 at 5:55
  • $\begingroup$ 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 $\endgroup$
    – TeaCrab
    Jun 22 '17 at 11:06
1
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ Thank you for this. I know there are presets, but I wanted a way using script. $\endgroup$
    – TeaCrab
    Jun 22 '17 at 11:08
  • $\begingroup$ 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. $\endgroup$
    – sambler
    Jun 22 '17 at 14:25
  • $\begingroup$ 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. $\endgroup$
    – TeaCrab
    Jun 22 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.