0
$\begingroup$

I have two questions both related to python scripting:

1) I want to set the units to mm, for that, I change the scale to 0.001 in both Scene and Display in the properties panel. When I copy the commands and run it as a script I get an AttributeError saying:

"AttributeError: 'SpaceTextEditor' object has no attribute 'context'"

In one of the answers, I understood that this just clicks the button in the properties editor and since we are running it from a script the line can be removed. But the next line, where you set the scale length, also throws an error saying:

"AttributeError: 'Scene' object has no attribute 'system'"

2) I want to scale an Ico sphere along the three axes, I change it in the properties panel but the code generated does not take into effect the changes in these values. Please find the code below:

import bpy
bpy.ops.object.delete(use_global=False)
bpy.data.objects["Camera"].hide = True
bpy.data.objects["Lamp"].hide = True
bpy.context.space_data.context = 'SCENE'
bpy.context.scene.system = 'METRIC'
bpy.context.scene.scale_length = 0.001
bpy.context.space_data.grid_scale = 0.001
bpy.ops.mesh.primitive_ico_sphere_add(size=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3, size=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.context.object.location[0] = 20
bpy.context.object.location[1] = 50
bpy.context.object.location[2] = -14
bpy.context.object.dimensions[0] = 2  # changes not taken into effect (40 on UI) 
bpy.context.object.dimensions[1] = 2 # (20 on UI)
bpy.context.object.dimensions[2] = 2 # (35 on UI)

I am new to blender and any suggestions would be greatly appreciated.

$\endgroup$
0
$\begingroup$

Error messages are pretty helpful in this case.

"AttributeError: 'Scene' object has no attribute 'system'"

Means that you can not access the scene's system property because there is none. In other words: the actual 'Object' (Scene in this case) has no attribute called .system so you can not access Scene.system.

Suggest using the auto complete feature (Ctrlspacebar) of the command line when searching for attributes:

>>> bpy.context.scene.u
                       nit_settings
                       pdate(
                       sers
                       ...
>>> bpy.context.scene.unit_settings.system
'METRIC'
>>> bpy.context.scene.unit_settings.scale_length
1.0

Note: Lines from the Info Area not always yield the 'correct path' to the attribute/property.

$\endgroup$
  • $\begingroup$ Thank you, this gave me a better idea on how to proceed. $\endgroup$ – Shailesh Bg Apr 15 at 13:38

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.