Maybe add obj.Proxy = self in the onDocumentRestored method. (https://wiki.freecadweb.org/FeaturePython_methods)
And for the onChanged method a simpler way to do it could be by changing the obj.type strings as follow (add the curly bracket "{" and "}"] to replace each {variable} in the onchanged method with one call to fp.type.format(variable1=fp.variable1.value, variable2=fp.variable2,....).
Code: Select all
obj.type=['const, <{const_coef}>',
'cosine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, half, <{initial_value}>',
'cosine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, one, <{initial_value}>',
'cosine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, forever, <{initial_value}>',
'cosine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, <{number_of_cycles}>, <{initial_value}>',
'cubic, <{const_coef}>, <{linear_coef}>, <{parabolic_coef}>, <{cubic_coef}>',
'direct',
'double ramp, <{a_slope}>, <{a_initial_time}>, <{a_final_time}>, <{d_slope}>, <{d_initial_time}>, forever, <{initial_value}>',
'double ramp, <{a_slope}>, <{a_initial_time}>, <{a_final_time}>, <{d_slope}>, <{d_initial_time}>, <{d_final_time}>, <{initial_value}>',
'double step, <{initial_time}>, <{final_time}>, <{step_value}>, <{initial_value}>',
'linear, <{const_coef}>, <{slope_coef}>',
'ramp, <{slope}>, <{initial_time}>, forever, <{initial_value}>',
'ramp, <{slope}>, <{initial_time}>, <{final_time}>, <{initial_value}>',
'sine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, half, <{initial_value}>',
'sine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, one, <{initial_value}>',
'sine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, forever, <{initial_value}>',
'sine, <{initial_time}>, <{angular_vel}>, <{amplitude}>, <{number_of_cycles}>, <{initial_value}>',
'step, <{initial_time}>, <{step_value}>, <{initial_value}>',
'string, {string}',
'time',
'timestep',
'unit']
Code: Select all
fp.expression = fp.type.format(initial_time=fp.initial_time,
final_time=fp.final_time,
step_value=fp.step_value,
initial_value=fp.initial_value,
angular_vel=fp.angular_vel,
amplitude=fp.amplitude,
number_of_cycles=fp.number_of_cycles,
a_slope=fp.a_slope,
a_initial_time=fp.a_initial_time,
a_final_time=fp.a_final_time,
d_slope=fp.d_slope,
d_initial_time=fp.d_initial_time,
d_final_time=fp.d_final_time,
slope_coef=fp.slope_coef,
slope=fp.slope,
const_coef=fp.const_coef,
linear_coef=fp.linear_coef,
parabolic_coef=fp.parabolic_coef,
cubic_coef=fp.cubic_coef,
string=fp.string
)
Regards