getResources xfcn

Having trouble using an XCmd or XFcn? Post your questions here.

getResources xfcn

Postby JohnnyAndrews » Fri Mar 20, 2009 6:37 pm

What sort of file path is required for this, or can't you get the resources of your open project?

I tried:
Code: Select all
getResources("this project").

put the long name of this project into tFilePath
getResources(tFilePath)

put projectPath("this project") into tFilePath
getResources(tFilePath)

the last is obviously no good, as trace shows that tFilePath is the path to the project, without the project name appended. But the middle code puts the full path with the project name into tFilePath. Nevertheless, the result is "false (cr) Invalid file path".

I remember seeing something about file paths with slashes instead of colons. Is that what is required for this xfcn? Or can you only get the resources for a file which is not already open?

Johnny
iMac 24" 2.4 GHz Intel Core Duo, 4 GB RAM, OSX 10.5.6, SC 4.6.3
JohnnyAndrews
 
Posts: 32
Joined: Mon Jan 05, 2009 12:29 pm
Location: Carson City, NV

Re: getResources xfcn

Postby Lisa » Fri Mar 20, 2009 9:43 pm

JohnnyAndrews wrote:What sort of file path is required for this, or can't you get the resources of your open project?

I tried:
Code: Select all
getResources("this project").

put the long name of this project into tFilePath
getResources(tFilePath)

put projectPath("this project") into tFilePath
getResources(tFilePath)

the last is obviously no good, as trace shows that tFilePath is the path to the project, without the project name appended. But the middle code puts the full path with the project name into tFilePath. Nevertheless, the result is "false (cr) Invalid file path".

I remember seeing something about file paths with slashes instead of colons. Is that what is required for this xfcn? Or can you only get the resources for a file which is not already open?

Use this to get a correctly formed path:
Code: Select all
put (projPath(this proj) & short name of this proj) into tFilePath

FYI, file paths with slashes instead of colons, or POSIX paths, are now standard on Mac but they've not yet been incorporated into SC's scripting language -- all built-in SC and Xtend functions require the old-style HFS paths with colons, except for shell() scripts, which require POSIX paths.
iMac 24" 3.06 GHz Intel Core 2 Duo, 4 GB RAM, Mac OS X 10.6.8, SC 4.7.3
User avatar
Lisa
 
Posts: 303
Joined: Sun Jul 06, 2008 12:33 pm
Location: San Diego, CA

Re: getResources xfcn

Postby JohnnyAndrews » Fri Mar 20, 2009 10:34 pm

Thanks, Lisa

I now have the correct file path, but it still isn't working the way it is supposed to. This is the from the info in the xtend folder:
Optionally, a fork from which to retrieve a resource listing is supplied in <fork>. If this parameter is not empty, the resources found in the fork specified by this parameter are listed. Pass "D" for data fork, or "R" for resource fork. If this parameter is empty, the resources in the resource fork are listed.

This is the code in the script:
Code: Select all
                trace on
                put getResources(tFilePath,D) into tResList                          -- Project resources
                write "  Data fork resources - " & (the number of lines of tResList -1) &cr after file tReport
                repeat with index =2 to the number of lines of tResList
                        write "                        " & line index of tResList &cr after file tReport
                end repeat
                put getResources(tFilePath,R) into tResList
                write "  Resource fork resources - " & (the number of lines of tResList -1) &cr after file tReport
                repeat with index =2 to the number of lines of tResList
                        write "                            " & line index of tResList &cr after file tReport
                end repeat
                trace off
                write cr after file tReport
               

This doesn't give any error, but the Resource Manager view of the project says that there are 7 resources in the data fork (all xfcns) and 2 resources in the resource fork, and all I get is this:
Data fork resources - 2
<Untitled>,1,vers,18
<Untitled>,2,vers,37
Resource fork resources - 2
<Untitled>,1,vers,18
<Untitled>,2,vers,37

So the getResources xtend xfcn appears to be ignoring the parameter for the fork. I tried it this way, and also with quotes around the "D" and "R". No difference.

Johnny
iMac 24" 2.4 GHz Intel Core Duo, 4 GB RAM, OSX 10.5.6, SC 4.6.3
JohnnyAndrews
 
Posts: 32
Joined: Mon Jan 05, 2009 12:29 pm
Location: Carson City, NV

Re: getResources xfcn

Postby Lisa » Fri Mar 20, 2009 11:58 pm

The fork specifier (D or R) needs to be the third parameter. The second parameter specifies the kind of resource, or you can pass empty if you want all kinds:
Code: Select all
get getResources(tFilePath,"","D")
(You'll note I quoted the D -- don't know if that's required or not but that's how I've always done it...)

Also note that the function returns true or false in its first line, so you can build error-checking into your code:
Code: Select all
get getResources(tFilePath,empty,"R")
if line 1 of it is true then
    delete line 1 of it
    -- continue with script
else
    -- report error and abort script
end if
iMac 24" 3.06 GHz Intel Core 2 Duo, 4 GB RAM, Mac OS X 10.6.8, SC 4.7.3
User avatar
Lisa
 
Posts: 303
Joined: Sun Jul 06, 2008 12:33 pm
Location: San Diego, CA

Re: getResources xfcn

Postby JohnnyAndrews » Sat Mar 21, 2009 11:06 am

Thanks again, Lisa

This worked. Is this required for all xfcns, that you have to pass some form of intermediate parameters between the first and last?

Also, if you have worked with them. When you are looking at the info window for objects, i.e. after double-clicking with the arrow tool, one of the buttons is for user properties. When you select this, you get a window with two panes, the user property, and the contents. I have found that I can get at the user property, if it exists, with the userProps keyword. But is there a way to get and/or set the contents data in a script?

When creating a new project, I could put in the user properties in any object manually. But I have a converted HyperCard stack which has 10,900+ data cards. And 57 background fields on each data card! I would like to create a script attached to a button which would got through these cards and set the text font, size and style for each of these fields. But the fields do not always have any content. I tried this button with textFont and textSize for the field. Unfortunately, these attributes do not seem to hold if the field has no text in it. Therefore if I go to a data card, and create a new card, if I access a field on the new card which was empty on the earlier card, I get the default which was carried over from HyperCard - Geneva 12 point. I want, in most but not all cases, Lucida Grande 9 point or 10 point. I thought I could force this with the field custom properties, but it would take forever to go through 10,900+ cards and all the fields setting the user properties manually for each field in the background. Assuming, of course, that I have now seen enough to figure out what belongs in the property and contents fields.

Johnny
iMac 24" 2.4 GHz Intel Core Duo, 4 GB RAM, OSX 10.5.6, SC 4.6.3
JohnnyAndrews
 
Posts: 32
Joined: Mon Jan 05, 2009 12:29 pm
Location: Carson City, NV

Re: getResources xfcn

Postby Lisa » Sat Mar 21, 2009 12:06 pm

JohnnyAndrews wrote:This worked. Is this required for all xfcns, that you have to pass some form of intermediate parameters between the first and last?

Yeah, you have to pass the parameters in the order the function is expecting them; you can't just skip over one and expect the function to know that the second value you pass is meant for the function's third parameter.

JohnnyAndrews wrote:Also, if you have worked with them. When you are looking at the info window for objects, i.e. after double-clicking with the arrow tool, one of the buttons is for user properties. When you select this, you get a window with two panes, the user property, and the contents. I have found that I can get at the user property, if it exists, with the userProps keyword. But is there a way to get and/or set the contents data in a script?

Yes. Look up define in the SLG to create a userProp for an object (and undefine to destroy). Then get/set the value of the userProp just as you would any other property (but make sure to use "the" whenever dealing with userProps):
Code: Select all
define the uDate of this card
set the uDate of this card to "21-Mar-2009"
get the uDate of this card
put (the uDate of this card) into cd fld 1

Sorry, Johnny, I gotta run now -- but I'll get back to you on the last part of your post if nobody else comes along with an answer.
iMac 24" 3.06 GHz Intel Core 2 Duo, 4 GB RAM, Mac OS X 10.6.8, SC 4.7.3
User avatar
Lisa
 
Posts: 303
Joined: Sun Jul 06, 2008 12:33 pm
Location: San Diego, CA

Re: getResources xfcn

Postby Lisa » Sun Mar 22, 2009 2:56 pm

JohnnyAndrews wrote:When creating a new project, I could put in the user properties in any object manually. But I have a converted HyperCard stack which has 10,900+ data cards. And 57 background fields on each data card! I would like to create a script attached to a button which would got through these cards and set the text font, size and style for each of these fields. But the fields do not always have any content. I tried this button with textFont and textSize for the field. Unfortunately, these attributes do not seem to hold if the field has no text in it.

I believe I have run across that problem before. I don't remember the circumstances and I can't replicate it now. I think it was discussed on the SC mailing list and it might even have been acknowledged as a known issue at some point.

JohnnyAndrews wrote:Therefore if I go to a data card, and create a new card, if I access a field on the new card which was empty on the earlier card, I get the default which was carried over from HyperCard - Geneva 12 point. I want, in most but not all cases, Lucida Grande 9 point or 10 point. I thought I could force this with the field custom properties, but it would take forever to go through 10,900+ cards and all the fields setting the user properties manually for each field in the background. Assuming, of course, that I have now seen enough to figure out what belongs in the property and contents fields.

I think you're going to have to think in terms of work-arounds here. This has nothing to do, by the way, with user properties -- textFont and textSize are automatic, built-in properties of fields. I doubt that setting user properties would be the most efficient way to work around this problem.

First, if you want all the fields in the project to have the same font and size, try setting the textFont/Size globally, ie. without specifying a particular object, in your openProject script, which should cause any newly created fields to take on those attributes:
Code: Select all
set the textFont to "Lucida Grande"
set the textSize to 12

You could also use a newCard handler to set field properties -- a newCard message is sent whenever a new card is created. So add a newCard handler to the relevant background or window script and set the text attributes of the fields as desired:
Code: Select all
on newCard
    repeat with x = 1 to (num of cd flds)
        set the textFont of cd fld x to "Lucida Grande"
        set the textSize of cd fld x to 12
    end repeat
end newCard

None of the above will do anything about the empty fields in the already existing cards, however. If you never plan to add any text to those fields, it probably doesn't matter. Otherwise you could set the font/size for those fields in, say, a closeField handler in the background or window script, so that after you enter some text it will be changed to the appropriate attributes.

HTH, Lisa
iMac 24" 3.06 GHz Intel Core 2 Duo, 4 GB RAM, Mac OS X 10.6.8, SC 4.7.3
User avatar
Lisa
 
Posts: 303
Joined: Sun Jul 06, 2008 12:33 pm
Location: San Diego, CA


Return to Using Externals

Who is online

Users browsing this forum: No registered users and 1 guest