0
$\begingroup$

I try to figure out how via a pie command one could set the "Snap to Pixel" = true or false inside the UV editor and struggle with finding the right way to write this as a code instruction. For the pie menu I would like to have a button to press and each press can trigger either the true or false based on the current state which I think one could check via an if step. Right?

enter image description here

As it seems the console reads this out:

enter image description here

But unfortunately this is the same when selecting "Constraint to Image Bounds".

The command I think is:

spaceUVEditor.use_snap_to_pixels

And this being boolean so true or false.

$\endgroup$
3
$\begingroup$

You can use wm.context_set_boolean or wm.context_toggle to achieve this.

The code should look like this:

op_props = pie.operator("wm.context_set_boolean", text="Snap to pixels")
op_props.data_path = "space_data.uv_editor.use_snap_to_pixels"
op_props.value = True

#or

pie.operator("wm.context_toggle", text="Snap to Pixels").data_path = (
    "space_data.uv_editor.use_snap_to_pixels")
$\endgroup$
  • $\begingroup$ do you have an idea how to render this as a checkbox? Or since it is a 0 1 flag that is set how to check if it is activated so in case it is on it will be set to off and in case it is off it will be set to on? $\endgroup$ – Claas Kuhnen Jan 26 '16 at 18:23
2
$\begingroup$

you have to find the UV editor area to access this property, add the following inside the pie menu :

    for area in bpy.context.screen.areas: #loop through areas
        if area.type == 'IMAGE_EDITOR':   #find the image editor
            space_data = area.spaces.active
            pie.prop(space_data.uv_editor,"use_snap_to_pixels") #the uv editor is part of the image editor 
$\endgroup$

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.