prop skip save problem !

i have a script which is working nicely
i did a copy and added a new scene property

bpy.types.Scene.MyFloatdx1 = FloatProperty( # Myfloat
name=“DX”, # Name printed in button
description=“Enter a DX”, # Tip tool
default = 0.5,
min = 0.001,
max = 100.0,
options={‘SKIP_SAVE’})

i added the skip save so that the prop would not change

and this is not working i still get another value for the prop in panel!

here the default should be 0.5 and in panel i get 0.12

and my first menu is not working anymore!

any suggestion to correct this error

thanks

That option is more pertinent to operator properties Ricky. The value will have reverted to default next time the Op is run.

ok so you mean it is not usable with a scene prop!

anyway to get the default value for a scene prop without having to use an init class?

or not possible at all !

thanks

It will return the default value when you first register it. … until it’s been set.

or



scene.bl_rna.properties.get("MyFLoatdx1").default


or there is some reset operator… that’s called when you right click and reset to default.

did a test using prop

bpy.types.Scene.MyFloat1 = bpy.props.FloatVectorProperty( # property
name=“Float”, # Name printed in button
description=“Enter a float”, # Tip tool
default = 33.33,
min = -100,
max = 100,
options={‘SKIP_SAVE’})

but does not like it anymore!

where can this
scene.bl_rna.properties.get(“MyFLoatdx1”).default

in the class panel ?

any simple example for this reset operator thing?

when i select my menu it goes to an operator
but not certain you can change prop in this operator

i has only scene prop in my first script and it
did use the saved file value but not realy practical !

got this one

bpy.types.Scene.your_prop[1][‘default’
will test it

for scene prop

thanks

yeah UI and button ops are near on impossible to get context on… ie they won’t poll from a script.

vector props have a default_array value

you can’t put bl_rna stuff into panel props, needs to be ID props… the bl_rna is the inner workings of such

your best bet would be to set up an update boolean… BoolProperty(update=somefunc)

then

def somefunc(self, context):
if self.flag:
reset the props to default

or you could set the update up on myfloat itself to return its default after you process the changed value… which would be like an instant skip save.

but if instead of using scene prop
can i use prop only may be

when you say uisng a bool prop
you mean adding a new check button to update prop values !

i got this old one here

class InitProps(bpy.types.Operator):

bl_idname = “scene.foobar”
bl_label = “Init Props”

def execute(self, context):

scn = context.scene

scn.MyCkeckbox1 = False
scn.MyFloat1 = 333.111
scn.Int1 = 777
scn.Int2 = 999

return {‘FINISHED’}

so i would have to call this from a bool prop some how
with the real prop i have

also how come my first menu does not work anymore
seems to be related somehow

thanks

how does this one works
bpy.types.Scene.your_prop[1][‘default’]
what is this your_prop[1][ ?
is name of the prop with [1]

thanks

Much of a muchness Ricky… call the op from a button or in code.

A quick update function like this saves writing and registering an op. Put the boolprop in a panel or set to true in code and it will fire. (post rego restricted context ofcourse)


def initprops(self, context):
    if self.set_init:
        scene = context.scene
        scene.blah = 10
        scene.blahblah = "blah"  
        scene.resettodefault = scene.bl_rna.properties.get("resettodefault").default
        self.set_init = False

bpy.types.Sometype.set_init = BoolProperty(update=iniitprops, default=False)

I have no idea where you pulled your “bpy.types.Scene.your_prop[1][‘default’]” from.

Not sure what the problem is… If you have a global property (bpy.types.*.your_prop), you can add an operator to panel to reset the value of the property for e.g. current scene:

props = layout.operator("wm.context_set_float")
props.data_path = "scene.MyFloatdx1"
props.value = 0.5

and where do you put that in the panel ?

let me prepare a shorter version of my script
there is still this menu problem
and no error i cannot select the first time this first menu
and this is since i added one new scene prop fo float dx!

thanks

here is file should be faster

2 errors

name for calling function initprop

at line 238
bpy.types.Sometype.set_init = BoolProperty(update=initprops, default=False)
what name i can use instead of Sometype.set_init?

and then the first menu selection in panel does not work anymore
and no error

this is since i added the new scene prop

bpy.types.Scene.MyFloatdx1 = FloatProperty( # Myfloat is the name of the Float variable = Scene property
name=“DX”, # Name printed in button
description=“Enter a DX”, # Tip tool
default = 0.5,
min = 0.001,
max = 100.0

file

ztest1.blend (604 KB)

idea is that i don’t wont the default scene prop to change values when you save file
has to use the default values from the script

unless there is a way to do it with prop pass to scene properties

thanks

has to use the default values from the script

When does it need to use these values? If user clicks a button? An entry from the dropdown of an enumprop? After .blend saving / loading?

A bit bad practice (invoke calls execute), but it does run the op with a default of 0.5 every time:

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    val = bpy.props.FloatProperty(min=-1, max=1)

    @classmethod
    def poll(cls, context):
        return context.active_object is not None
    
    def invoke(self, context, event):
        self.val = 0.5
        print("invoke")
        return self.execute(context) #{'FINISHED'}

    def execute(self, context):
        print("exec, val =", self.val)
        context.object.location.x += self.val
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()


An even worse, a button to set a value in redo panel:

import bpy
class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"
    bl_options = {'REGISTER', 'UNDO'}
    
    val = bpy.props.FloatProperty(min=-1, max=1)

    @classmethod
    def poll(cls, context):
        return context.active_object is not None
    
    def invoke(self, context, event):
        self.val = 0.5
        print("invoke")
        return self.execute(context) #{'FINISHED'}

    def execute(self, context):
        print("exec, val =", self.val)
        context.object.location.x += self.val
        return {'FINISHED'}
    
    def draw(self, context):
        layout = self.layout
        layout.prop(self, "val")
        props = layout.operator("wm.context_set_float", text="Set to 0.25")
        props.data_path = "active_operator.val"
        props.value = 0.25

def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":
    register()

only for save then load
as long as button takes same value when starting script

how do you call these operators
i tried label id name and did not work

where can i use this in my little panel script ?

i think the init func should work
if i can find how to call it !

thanks

spacebar over 3d view, “Simple Object Operator”, return

Better solution:

import bpy

class ResetHelloWorldPanel(bpy.types.Operator):
    bl_idname = "wm.reset_hello_world_panel"
    bl_label = "Reset Hello World-Panel"

    def execute(self, context):
        context.scene.p = bpy.types.Scene.bl_rna.properties['p'].default
        context.scene.pp = bpy.types.Scene.bl_rna.properties['pp'].default
        return {'FINISHED'}
    
        
class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        layout.prop(context.scene, "p")
        layout.prop(context.scene, "pp")
        
        layout.operator("wm.reset_hello_world_panel", text="Reset")

def register():
    bpy.utils.register_class(HelloWorldPanel)
    bpy.utils.register_class(ResetHelloWorldPanel)
    bpy.types.Scene.p = bpy.props.IntProperty(default=1337, options={'SKIP_SAVE'})
    bpy.types.Scene.pp = bpy.props.StringProperty(default="Foobar", options={'SKIP_SAVE'})


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)
    bpy.utils.unregister_class(ResetHelloWorldPanel)
    del bpy.types.Scene.p
    del bpy.types.Scene.pp


if __name__ == "__main__":
    register()


Reset to default prior to save:

import bpy

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        layout.prop(context.scene, "p")
        layout.prop(context.scene, "pp")

# might need to make hander func persistent
#from bpy.app.handlers import persistent
#@persistent
def reset_hello_world_panel(scene):
    context.scene.p = bpy.types.Scene.bl_rna.properties['p'].default
    context.scene.pp = bpy.types.Scene.bl_rna.properties['pp'].default

def register():
    bpy.utils.register_class(HelloWorldPanel)
    bpy.utils.register_class(ResetHelloWorldPanel)
    bpy.types.Scene.p = bpy.props.IntProperty(default=1337, options={'SKIP_SAVE'})
    bpy.types.Scene.pp = bpy.props.StringProperty(default="Foobar", options={'SKIP_SAVE'})
    bpy.app.handlers.save_pre.append(reset_hello_world_panel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)
    bpy.utils.unregister_class(ResetHelloWorldPanel)
    del bpy.types.Scene.p
    del bpy.types.Scene.pp
    bpy.app.handlers.save_pre.remove(reset_hello_world_panel)


if __name__ == "__main__":
    register()


With a persistent app handler, you could also try to reset before load.

ok i found error

this mustahave a selected object in viewport
my scene was empty !

also work with call from script!

thanks

i foudn the error for the menu

there is these lines

@classmethod
def poll(cls, context):
return context.active_object is not None

so there must be an active ojbect for it to work!

is there a way not too need an object?
i guess it coudl be remove in this case
object is not really needed for that script !

thanks

I provided a quickly hacked script, which was based on the Operator Simple template. It contains a poll to check for a context object, which is of course not needed in this case. But you may add another condition, to ensure the op will only run in an appropriate context.