This question is answered.


Permlink Replies: 22 - Pages: 2 [ 1 2 | Next ] - Last Post: 10 Aug 21, 12:45 Last Post By: JeffTucker Threads: [ Previous | Next ]
RobM

Posts: 3,815
Registered: 4-Aug-2006
Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 18:47
 
  Click to reply to this thread Reply
In init.bsh, within a for (AlbumObject ao : root.getChildren()), I use
AlbumObjectProperties props = ao.getProperties();
vars = ao.getVars();
vars.get("varKey", varValue); //First run it will be null
...
...
vars.put("varKey", varValue); //Saved value should be present above on subsequent runs
props.put("vars", vars);
props.save();


I can get the key's value in index.htt using AlbumObject.getVars().get("varKey").
But that does not work earlier in init.bsh, the key is not present.

What I expect is on the first make the key won't exist and I get a null. Only subsequent makes I expect to get the stored value of the key, before it is possibly changed and saved.

What am I doing wrong?

in the .info file for the object there is an entry, which seems to hold the data somewhere
  <void method="put">
   <string>vars</string>
   <object class="se.datadosen.util.Scope">
    <void property="outer">
     <object class="se.datadosen.util.Scope">
      <void property="outer">
       <object class="se.datadosen.util.Scope">
        <void property="outer">
         <object class="se.datadosen.util.Scope"/>
        </void>
       </object>
      </void>
     </object>
    </void>
   </object>
  </void>
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 19:16   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I suspect that if you close and reopen the project before the second "make," the value will be there.

This feels like one of those "efficiency" things - don't keep re-reading the variables, but just do it once. The core isn't expecting a skin to be changing stored variables for an object, just using them.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 19:58   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
I suspect that if you close and reopen the project before the second "make," the value will be there.

This feels like one of those "efficiency" things - don't keep re-reading the variables, but just do it once. The core isn't expecting a skin to be changing stored variables for an object, just using them.

Unfortunately it doesn't make any difference. I think the data is just being held in memory and not being correctly written to the info file. Once I have put the value I can get it back in init.bsh, until the make process has finished.

Embarrassingly, we worked this out just over three years ago, but I can't find the code.
ctwist

Posts: 474
Registered: 27-Sep-2003
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 20:01   in response to: RobM in response to: RobM
Helpful
  Click to reply to this thread Reply
AFAIK vars is not saved permanently. It is built dynamically from various sources when an AlbumObject is initiated.

Don't use vars. Save the property as a "property". I.e.
props.put("varKey", varValue);
props.save();
.....
String myVar = props.get("varKey");
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 20:09   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
Sounds right. In the tool we created a few years ago:
AlbumObjectProperties aop = ao.getProperties();
Then do your put's and save's on aop.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 20:15   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
Embarrassingly, we worked this out just over three years ago, but I can't find the code.

Discouraging to realize that we've forgotten more things than we currently know. And it's not going to get any better. :(
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 20:32   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
AFAIK vars is not saved permanently. It is built dynamically from various sources when an AlbumObject is initiated.

Don't use vars. Save the property as a "property". I.e.

props.put("varKey", varValue);
props.save();
.....
String myVar = props.get("varKey");
It works, for a string but not for a numeric.
Stripped down code
for (AlbumObject ao : root.getChildren()) {
AlbumObjectProperties props = ao.getProperties();
 
System.out.println(ao + " outputThumbPath " + props.get("outputThumbPath") + " tocWidth " + props.get("tocWidth") + " tocHeight " + props.get("tocHeight"));				
 
vars = ao.getVars();
tocWidth = vars.get("thumbWidth");
tocHeight = vars.get("thumbHeight");
//Make a custom thumbnail image and get its dimensions
tocWidth = ai.getImage().getWidth()/2;
tocHeight = ai.getImage().getHeight()/2;
 
props.put("tocWidth", tocWidth);
props.put("tocHeight", tocHeight);
props.put("outputThumbPath", dest.toString());
props.save();

And the result in the System console
Nature outputThumbPath /Users/robert/My Albums/Sample Project/album/Nature/jthumbs/diana-parkhouse.jpg tocWidth null tocHeight null


I'm at a total loss, All I can think of is to not bother about needlessly remaking thumbnails on the single 'index' page, which is what I was trying to code to avoid doing.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 21:02   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
ctwist wrote:
AFAIK vars is not saved permanently. It is built dynamically from various sources when an AlbumObject is initiated.

Don't use vars. Save the property as a "property". I.e.codeprops.put("varKey", varValue);
props.save();

Having deleted the project file and started afresh, it works :)
Thanks to both of you, it has been driving me nuts - and I need to remember when messing with such stuff to keep deleting the project.

Edited by: RobM on 8 Aug 2021, 20:14
ctwist

Posts: 474
Registered: 27-Sep-2003
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 21:16   in response to: RobM in response to: RobM
Correct
  Click to reply to this thread Reply
You should cast tocWidth and tocHeight to a specific object type. E.g.
tocWidth = [Integer] ai.getImage().getWidth()/2;
or maybe int, otherwise you may need to untangle some unexpected object types such as Double.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 21:29   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
You should cast tocWidth and tocHeight to a specific object type. E.g.
tocWidth = [Integer] ai.getImage().getWidth()/2;
or maybe int, otherwise you may need to untangle some unexpected object types such as Double.
Yes, but first I need to tidy up all the edits and remarked out lines of code, and get it all functioning (I already cast the final dimension variables to int, as they are scaled by a percentage value.)

Of course, if we had a folder thumbnail setting I wouldn't have gotten myself into such a state ;)
This is for Journal skin, a one 'index' page with the option of thumbnails. So, I had to deactivate normal thumbnails as I only wanted the folder's thumbnail image. Then make myself a single thumbnail for each folder, but put it in a folder not named 'thumbs' as they get deleted. And that led to having to check if the thumbnail was new, resized etc.
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 21:48   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
You might find it easier (or not) to embed some properties into the image file itself. In short, you can embed things like the image bounds, fixed/non-fixed setting, etc., etc. into the folder thumbnail file you've generated. It's then fairly straightforward to check the EmbeddedProperties to see if the image needs to be regenerated.

Rather than trot out all the code here, take a look at the folderiterate.inc file in any of my primary skins, like Neptune.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 21:56   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
You might find it easier (or not) to embed some properties into the image file itself. In short, you can embed things like the image bounds, fixed/non-fixed setting, etc., etc. into the folder thumbnail file you've generated. It's then fairly straightforward to check the EmbeddedProperties to see if the image needs to be regenerated.

Rather than trot out all the code here, take a look at the folderiterate.inc file in any of my primary skins, like Neptune.

Thanks, I’ll have a look, once I’ve fixed all the stuff I think I might just have broken. ;)
JeffTucker

Posts: 8,039
Registered: 31-Jan-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 22:02   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Where's the fun in that? You should change at least 20 things, many of them seemingly unrelated, before you even attempt to debug it.

Every once in a while I have to throw out everything and retreat to the last known safe version. ;)
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 8 Aug 21, 22:05   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Where's the fun in that? You should change at least 20 things, many of them seemingly unrelated, before you even attempt to debug it.

Every once in a while I have to throw out everything and retreat to the last known safe version. ;)

I’m living dangerously, it is more fun, last known safe version is on the skins page.
RobM

Posts: 3,815
Registered: 4-Aug-2006
Re: Getting AlbumObjectProperty in init.bsh
Posted: 9 Aug 21, 00:38   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
You might find it easier (or not) to embed some properties into the image file itself. In short, you can embed things like the image bounds, fixed/non-fixed setting, etc., etc. into the folder thumbnail file you've generated. It's then fairly straightforward to check the EmbeddedProperties to see if the image needs to be regenerated.

Rather than trot out all the code here, take a look at the folderiterate.inc file in any of my primary skins, like Neptune.

I'm most of the way there now, just need to embed the image bounds options and pass the current settings to my routine. It is looking very much like your code, but I'm sticking with putting the properties in the folder object - I think it is easier for me.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums