[SOLVED]persistent storage between different macros

Need help, or want to share a macro? Post here!
User avatar
piffpoof
Posts: 347
Joined: Sun Nov 30, 2014 11:00 am
Location: Mare Nostrum
Contact:

[SOLVED]persistent storage between different macros

Postby piffpoof » Fri Dec 12, 2014 1:36 pm

hello

is there a supported method for persistent storage between two macros in one session of FreeCAD - aside from writing out to file?

I have a number of macros which operate on a collection of geometric objects which have a screen portrayal:

1 macro#1: the objects are created and positioned from file, a data structure created by the macro holds all the objects and their view objects

2 macro#2: the user iterates over the object model until happy, they do this exclusively through the FreeCAD GUI, there is no involvement with macro code. Also they are only affecting the View Object at this point they do not alter the geometric object model.

3 macro#3: the program takes the accumulated GUI results from macro#2, combines them with the values in the data structure from macro#1, writes them out to the permanent storage in a file

I'm not looking for persistence over multiple invocations of FreeCAD, I would use the file structure for that if needed. What I am looking for is someway to maintain data structures between macro#1 and macro#3, all taking place in the same FreeCAD session.

I have tried to use Global variables but they seem to get garbage collected...

thanks

Dean
Last edited by piffpoof on Wed Dec 24, 2014 6:49 am, edited 1 time in total.
jreinhardt
Posts: 329
Joined: Mon Sep 09, 2013 6:08 pm

Re: persistent storage between different macros

Postby jreinhardt » Fri Dec 12, 2014 3:15 pm

Sounds like this could be realized by letting step 1 create a custom python feature
Scripted_objects
in that way you can store data directly on the object (along with the geometric shape)
and access it later.

This even works after saving and loading to a FCstd file.
BOLTS, standard parts library for FreeCAD Thread, Help with Translation
User avatar
piffpoof
Posts: 347
Joined: Sun Nov 30, 2014 11:00 am
Location: Mare Nostrum
Contact:

Re: persistent storage between different macros

Postby piffpoof » Fri Dec 12, 2014 3:51 pm

jreinhardt wrote:Sounds like this could be realized by letting step 1 create a custom python feature
Scripted_objects
in that way you can store data directly on the object (along with the geometric shape)
and access it later.

This even works after saving and loading to a FCstd file.
hi
I have steps 1,2 & 3 all working from the console as one large Python file as there is persistent storage while they run on the console. I am now trying to split them into 3 Macros and because the Macros run in a different name space than the console there is no persistent storage between one Macro execution and the next. At least not that I can find out about.

From reading the page you mentioned, it seems to write out binary objects to FCStd files, something I already have working (although not in FCStd format file). I don't want to write the intermediate results out to a data file as it seems rather old world in an OO environment. But if I have to I guess I have to. I am trying to find keep the intermediate results in memory, I could store them on an object from the classes mentioned on the page you mentioned but it would surely get garbage collected as my own class does once all references to it end when the macro finishes executing.

Dean
User avatar
yorik
Site Admin
Posts: 11645
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: persistent storage between different macros

Postby yorik » Fri Dec 12, 2014 4:25 pm

There is a very simple way:

Code: Select all

FreeCAD.myVariable = "something"
User avatar
piffpoof
Posts: 347
Joined: Sun Nov 30, 2014 11:00 am
Location: Mare Nostrum
Contact:

Re: persistent storage between different macros

Postby piffpoof » Fri Dec 12, 2014 6:56 pm

yorik wrote:There is a very simple way:

Code: Select all

FreeCAD.myVariable = "something"
worked a charm

thanks

Dean
User avatar
microelly2
Posts: 4560
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: persistent storage between different macros

Postby microelly2 » Fri Dec 12, 2014 11:52 pm

yorik wrote:There is a very simple way:

Code: Select all

FreeCAD.myVariable = "something"
I use this too,

but there should be some naming space conventions to avoid

that multiple macros/workbenches share/modify/overwrite the same attribute.

ideas

FreeCAD.Macro.MyMacro.myAttr=7
FreeCAD.WB.MyWorkbench.myAttr=8
FreeCAD.MyWorkbench.myAttr=9