Hello,
I made a little script that allows me to increase grid, as well as another one to decrease the grid size. By it self it works well. However, i am trying to figure out how to convert into an addon. So i was wondering if someone could look at it and tell me what im doing wrong.
A few things im not sure about is, what class i should be using. Is obviously not a mesh tool, but is also not an operator, is it?
Here is the stand alone script
curGridSize = bpy.context.scene.unit_settings.scale_length #get the current grid size
maxGridSize = 1 # This is the default grid size
minGridSize = 64 # This is the minimun grid size
#Increase the grid
if (curGridSize == minGridSize):
print(“minimun grid size reached”)
else:
bpy.context.scene.unit_settings.scale_length = (curGridSize*2)
and here it is as an addon.
bl_info ={
“name”: “ODN_GridDecrease”,
“author”: “Raul Aparicio [email protected]”,
“version”: (0, 1),
“blender”: (2, 80, 0),
“location”: “”,
“description”: “GridOps, will decrease the grid”,
“warning”: “This is experimental, use at your own risk”,
“wiki_url”: “”,
“category”: “View3DOverlay”,
}
import bpy
############################################
##ODN_GridDecrease
##This operator decrease the size of the grid by half.
##bpy.context.space_data.overlay.grid_scale = 1.5
############################################
class OVERLAY_ODN_GridDecrease(bpy.types.View3DOverlay):
“”“Connect Stuff”""
bl_idname = “overlay.gridIncrease”
bl_label = “ODN_GridIncrease”
def execute(self,context):
##Code goes here
curGridSize = bpy.context.scene.unit_settings.scale_length #get the current grid size
maxGridSize = 1 # This is the default grid size
minGridSize = 64 # This is the minimun grid size
#Increase the grid
if (curGridSize == minGridSize):
print(“minimun grid size reached”)
else:
bpy.context.scene.unit_settings.scale_length = (curGridSize*2)
return{‘FINISHED’}
def register():
bpy.utils.register_class(View3DOverlay_ODN_GridDecrease)
def unregister():
bpy.utils.unregister_class(View3DOverlay_ODN_GridDecrease)
############################################
####END OF ODN Collapse
############################################