I have a script that creates a form with several fields. I want to save the contents of these fields in design, and the next time when I open the design and launches the script I have already configured the form.
There are functions for including the file or string to .brd-file, there are functions for working with the properties of the design...
What is the best way to save my settings?
Maybe someone has an example code?
I woud look at using Skill's disembodied property list and the save the list in the database as an attachment (see axlSetAttachment).
On read you can eval the attachment return (axlGetAttachment) which will give you free parsing and the disembodied prop list gives you some future profing if you need to latter on you need to extend what you are storing.
In reply to fxffxf:
It does not work. axlCreateAttachment () does not accept the list. It is necessary to print the list to a string?
In reply to Silver John:
You need to convert the disem prop list to a string and pass it as the argument t_data. Also s_dataFormat needs to be set to a value of 'string, To convert a disembodied prop list to a string just do:
dataString = sprintf(nil " '%L" myDisembodyPropStruct)
while it might be hard to see the single quote (') immediately before the %L is important for "Get" part of the process.
To convert back from a string do:
str = axlGetAttachment(... 'string)
myDisembodyPropStruct = errsetstring(str)
Thanks. It works.
Do you think this is a good solution for storing these data in design file? Or it may be better to save them in a separate file? Why?
For a better understanding of the issue: we are talking about additional editing tool for aligning objects on the board. The default tools are stored individual settings for each design (probably in the design).But would not it be negative consequences if I save my data in the design? Maybe in the next version of the editor, this feature will be unavailable or even break down the design? Or perhaps these data will be conflict with other programs?Does anyone have an opinion on this issue? How do you keep your variables, in the design or in a separate file?
In reply to eDave:
Thank you, Dave.
How long you use this method? Wasn't problems?
I've been trying to get this to work using the desribed method but don't seem to be able to go back to an disembodied property list.
I have the following simple example
mylist = ncons(nil)mylist->ccw = tmylist->middle = nilmylist->cx = 0.12mylist->cy = 10.192mylist->layer = "TOP"mylist->stype = "LEFT"
dataString = sprintf(nil " '%L" mylist)
axlCreateAttachment("_ns_planar_settings" nil 0 'string dataString)
The above does create my attachment. I can easily read it using
a_id = axlGetAttachment("_ns_planar_settings" 'string) which returns an attachment id
mylist1 = errsetstring(a_id->data) will return a list, but I cannot access the data using -> syntax
typing mylist1 at the skill development window works. but still how do I access the list?
I would expect mylist1->layer but that returns nil
Skill > mylist1((nil stype "LEFT" layer "TOP" cy 10.192 cx 0.12 middle nil ccw t ))
In reply to Ejlersen:
Find two differences ;)
Skill > mylist1 = errsetstring(a_id->data)((nil middle nil ccw t))Skill > mylist(nil middle nil ccw t)
Yes, I too faced with this problem.
You can use: mylist1 = car(errsetstring(a_id->data))
Also, I store the data without " ' ", and add an apostrophe at the time of restoring: sFormData = sprintf(nil "%L" _formData)...
sFormData = attachment->data
formData = car(errsetstring(strcat("'" sFormData)))
You are missing one last car since errsetstring returns a list which has a list, add
mylist1 = car(mylist1)
then you can do
thanks for your help, my mistake i missed the extra paranthesis.
This is really an excellent way to store skill program settings inside a database file
Summary of this technique:
This uses an attachment to store in the database a list of variables. For example, you design a form where the user enters in their preferences and you manage them in Skill via a disembodied property list. You would like to store the user's preferences with the design. ; create an attachment name, DO NOT USE "fxf". I would suggest using an ; underscore, company name and application to make it unique. For example: ; _acme_bom_rpt ; would be a good attachment name. attachName = "fxf" ; A typical disembodied property list mylist = ncons(nil) mylist->ccw = t mylist->middle = nil mylist->cx = 0.12 mylist->cy = 10.192 mylist->layer = "TOP" ; NOTE: ; Do NOT Store dbid's in the disembodied list or make sure to remove ; them before storing as an attachment. ; Store list in current design (assuming user saves design) dataString = sprintf(nil " '%L" mylist) axlCreateAttachment(attachName nil 0 'string dataString) ; Next time user runs your Skill code, here is how to init the list: attach = axlGetAttachment(attachName 'string) if( attach) then mylist = car(errsetstring(attach->data)) else ; no list stored in design so init to default settings mylist = ncons(nil) mylist->ccw = t )
Yes, excellent. Thanks again fxffxf.
Ole, you can see the implementation for the storing to attachment, to property or to a file in Align tool (storeFormData() and restoreFormData()).
fxffxf, how long you use the save as attachment? There were no problems?
PS I already feeling paranoid with this reliability.
This is just brilliant - I wish I knew this before.
Another tip is that if you program forms that depends on the board accuracy (for deciding the number of decimal points) then add 1 to the precision so that you don't end up with storing a 1 in the variable since it will then understand it as being an flonum
John, I'm not worried about this, in my 14 years working as a channel partner for Cadence I've not seen a board loose information going from one release to another. So I'm confident that this will work going forward also.