Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 8753 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I am setting up a database of images included in a catalog and would like to find some way for the image name to be automaticly entered into a text field when the image is placed in the container.

How would I do this, with a script or is there some way to link the text box to the container? If anything if I could get the file name to be displayed along with the image.

THANKS!

B. P.

Posted

If you're using a Mac, AppleScript can do this for you. If you're on Windows, I think that Troi's File Plug-In will do the trick.

Chuck

Posted

I am on a mac, so how do I setup the apple script? I am ashamed to say I have never actually used an Applescript in all my years of MACing.

Posted

There are two options to do this with AppleScript. Option 1 has a better user interface, but will increase the size of the FileMaker database.

Here's how it works. When you want to import a graphics file, you have AppleScript handle the choosing of the file. Once the file is chosen, AppleScript takes note of the file's location and places the path in a field in FileMaker, then makes a copy of the file in a known location using a known name (I usually use a name like Dummy.gif). From this point on, FileMaker does the work of importing the Dummy file (the script step can be performed with a dialog and can be set to just import the same file every time, so long as it has the same name and location), storing the actual graphic in the database. The storing of the actual graphic in the database (rather than a reference to the graphic) is what bloats the database size, but it's necessary because the contents of the Dummy file will change with every run of the script. Now you have the graphic in the database and you have the path to the graphic in the database.

Option 2 is poor user interface, but will not bloat the size of the database because it doesn't store the graphic. But the tradeoff is that the user is presented with two dialog boxes: one for AppleScript to get the path to the file and one for FileMaker to import it.

This would all be unnecessary if there was a way in FileMaker to access the reference that FileMaker stores internally when it stores a reference to a graphic.

Let me know which option you're interested in and I'll go into more detail.

Chuck

[This message has been edited by Chuck (edited November 29, 2000).]

Posted

Thanks Chuck,

If you could go over the second option that would be great. The database is going to be of over 4000 seperate images so the file will probably get to be rather large.

THANKS!!

B

Posted

OK, I'm going to call the field for the graphic Image and the field for it's location Image_Path.

Here's the script in FileMaker, including the attached AppleScript:

Perform AppleScript [ set cell "Image_Path" of layout 0 of database "Images.fp5" to (choose file) as string ]

Go to Field [ Image ]

Import Picture []

What this script will do is present the user with a dialog box to select a file. The path to this file is placed in the field "Image_Path". Then a dialog box is presented again, this time to actually import the graphic.

You can get more specific with the (choose file) part of the AppleScript. For instance, you could edit it to be (choose file of type "GIFf") and only gif images will appear in the dialog box. Just find out the four letter codes for file type you want the user to see (it can be more than one, such as gifs and jpegs).

When the second dialog box comes up, make sure that "Store only a reference" is checked.

Chuck

Posted

Very cool, thank you very very much. This will speed things up ALOT!

I'll give it a shot and let you know how it goes

B

Posted

Ok, let me see if I am doing this correctly.

Do I place:

Perform AppleScript [ set cell "Image_Path" of layout 0 of database "Images.fp5" to (choose file) as string ]

Go to Field [ Image ]

Import Picture []

In the scriptmaker for FM or do I use The Apple Script Editor program?

again, THANK YOU for your help.

If it helps any

my image field is named: Image

the file name field is: File name

Posted

It goes in the dialog box for Perform AppleScript. Click Specify for the script step and enter the script.

What I usually do is write the AppleScript in a script editor. Scripter is my favorite. That makes it much easier to debug. Once I have it working, I then copy and paste it into the ScriptMaker's Perform AppleScript step.

BTW, the script I wrote for you will place the entire path to the file in the field, not just the field name. However, you can use a Set Field in your script to extract the file name, which is everything after the last colon.

The step you would have to add for this would be

Set Field [ FileName, Right( FileName, Length( FileName ) - Position( FileName, ":", 1, PatternCount( FileName, ":" ) ) ) ]

AppleScript is a wonderful way to augment the capabilities of FileMaker, BTW. Nine times out of ten, I've found that if there's something I can't do with FileMaker (such as display a dialog box that allows the user to enter data), I can do it with AppleScript and FileMaker. If you develop with FileMaker on the Mac, I would highly recommend getting Danny Goodman's AppleScript Handbook, which is what I used to learn AppleScript.

I just wish it were available on Windows. I've heard that similar capabilities are possible with WinBatch, but I haven't tried it out.

Chuck

[This message has been edited by Chuck (edited November 30, 2000).]

Posted

well I got the script working and importing the picture, and adding the name automaticlly. But i cant get it to shorten the name down to just the file name.

when i enter the script you posted it doesnt do anything. I have it entered in a set filed command of the script, I specified and pasted it in.

here is what i have:

File name, Right( File name, Length( File name ) - Position( File name, ":", 1, PatternCount( File name, ":" ) ) )

it gives me errors on the first "File name," saying it expects an operator.

I tried putting = + - / *

I think I am missing somethign BIG for this part.

also there are 5 colons in the path to the file (there may be mor when i startusing a networked disk) do i ned to specify a nuber of colons for it to delete to?

THANK YOU AGAIN!!!!

Brad

Posted

The Set Field step takes two arguments: the field to set and what to set it to.

Select the Set Field step in your script. Click the Specify Field... button at the bottom of the script window. Find the field File name, and click OK.

Click Specify... This is where you tell FMP what to set the field to. Enter this equation:

Right( File name, Length( File name ) - Position( File name, ":", 1, PatternCount( File name, ":" ) ) )

When typing out text, you'll often see this format:

Set Field [ X, Y ]

Where X is the field to be set and Y is what to set it to. You don't actually enter both of those arguments in the Specify section. The reason I tend to write it that way is that's just about how it looks in the script code when you look at it in the script window.

FileMaker also counts the number of colons in the path. That's what the PatternCount( File name, ":" ) portion does. This returns the number of times the colon appears in the field File name. I use it as the fourth argument for the Position function because the fourth argument is which colon to get the position of (the last one), which in this case, is the number of colons in the field.

Calculations can get complicated, so FYI, I'll go over what I've built.

I want to take a text string such as "abc:def:ghi:jkl" and return "jkl". So let's apply the calc to that string by replacing the File name in the calc with my test contents "abc:def:ghi:jkl":

Right( "abc:def:ghi:jkl", Length( "abc:def:ghi:jkl" ) - Position( "abc:def:ghi:jkl", ":", 1, PatternCount( "abc:def:ghi:jkl", ":" ) ) )

Now we'll work from the inside out. PatternCount( "abc:def:ghi:jkl", ":" ) returns 3 because there are three colons in the text. So our equation becomes:

Right( "abc:def:ghi:jkl", Length( "abc:def:ghi:jkl" ) - Position( "abc:def:ghi:jkl", ":", 1, 3 ) )

The Position function gives me the position in the string of a character I specify. The first argument is the string to look at. The second is the character to find. The third is the position I want to start from (in this case, the first character, or 1). The fourth argument is the occurance of the character. I want the position of the last occurance, the number of which I got from the PatternCount function.

Four our test string, the Position function is going to return 12 because the last colon is the twelth character in the string. Our calc becomes:

Right( "abc:def:ghi:jkl", Length( "abc:def:ghi:jkl" ) - 12 )

The Length function is pretty straight forward, taking as its argument a string and returning the number of characters in the string, in our case 15.

Right( "abc:def:ghi:jkl", 15 - 12 )

which becomes:

Right( "abc:def:ghi:jkl", 3 )

The Right function takes as it's arguments a string and the number of characters to return. Since we want three characters, our calculation, at it's end, returns:

"jkl"

which is what we wanted.

Hope that helps explain why the calculation works.

Chuck

Posted

Well everything works, but only once.

All the scripts and formulaes are owrking fine on the first entry. after that all I cna do is insert a picture, everything else is just blank unless I enter the text by hand.

Do I need to tell it to do everything in a different record or something?

Again I GREATLY APPRECIATE all your help, I just wish there was osmething I could do to repay...

Brad

Posted

Why don't you show me what the exact script is. Also, feel free to email the files to me ([email protected]) if you want. It may be that since you're importing images into multiple fields on the same record, you have a reference in your script that only works with one of the sets of fields.

Chuck

This topic is 8753 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.