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

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

Recommended Posts

Posted

Can some kind person please give me a script that will:
(1) place a Text field on the current layout, with location and size taken from 4 fields (x_origin, y_origin,width,height)
(2) insert into that field the contents of a Text field called 'this_text' formatted with font, size, color, alignment taken from 4 other fields (fontname, fontsize, fontcolor, alignment)

Thanks you.   Philip Caplan

Posted

(1) It is not possible to add a field to the layout with a script. In fact, it is not possible to modify a layout programmatically at all.

(2) There are text formatting functions for font, size and text color, so you could do something like:

Set Field [ YourTable::TargetField ; TextSize ( TextFont ( TextColor ( YourTable::this_text ; YourTable::fontcolor ) ; YourTable::fontName ) ] 

There is no function to control text alignment. There is a rather awkward workaround for this. Note that alignment is a paragraph attribute - unlike the other attributes that can be applied to individual characters.

This has all the signs of an XY question. What is it that you are really trying to accomplish here?

 

Posted

Hi comment.  Many thanks for your answer, very useful as always.

What I am "really trying to accomplish" is the production of a 2-page A4 PDF which can be printed on an inkjet printer to produce a "personalized greeting card".

The front-end of my idea is already working: it is a PHP/Javascript-based website on which a user chooses an image and then completes a simple form with their wording and choice of font and fontcolor to overlay and/or go beneath the image.

When they click "SUBMIT" the site sends me an email with all their data,. I copy-and-paste that email's contents into a FMPro database on my desktop Mac, and using FMPro calculation fields you have previously helped me with which extracts their data into fields, I then trigger a script which immediately outputs all the HTML files I need to upload to my site, and then I trigger another script which sends them an email with a button they click to see their Greeting online, which they can then forward to their recipient. And it all works!!!

It then occurred to me [actually my wife said "I'd want a real card, not an online one"!!] that some people prefer a "real" greeting card (in addition to or instead of an) online one, so I experimented with using my existing Epson EcoTank printer, and found that it could print a 2-sided card which looked as good as the ones advertised on TV. Total cost for card, envelope and ink, less than 35-cents. Total time to print, about 2 minutes. That sounds like a viable idea. (My business plan is not based on making a profit: I'm a more-or-less-retired printing company owner, and my idea is to provide this as a service to my local community, while keeping my brain active and trying to see what I can achieve after 40+ years of using computers as an end-user rather than a programmer).

So, my original hope of using calc-fields in my DB to generate different positioning and size of picture and text fields so that one Layout can be used for multiple greeting card designs will seemingly not be possible, since you say that "it is not possible to modify a layout programmatically at all."

So, I have to perhaps think about creating a separate Layout for every design on my website. By design I mean that if a picture requires the text overlay to be top-left, and a different design needs text-overlay to be centred near the bottom of the picture, that requires 2 Layouts. A "design" could offer multiple choices of image (including an image uploaded by the user such as a family, group or pet photograph) with multiple choices of font and fontcolor, but the positioning of elements would probably need to be fixed.

So, I am now thinking I can use calc-fields to select which Layout to go to based on which "design" the users selects, and then populate a Container field with their chosen image, and use the "Set Field" as you described above to populate each specific Text field on that Layout with the customer's choice of wording, font, fontcolor, etc, (although the alignment would have to be fixed for each design, not a problem). Then I would need to output a PDF of that Layout.

Ultimately what I need is to produce an A4 2-page PDF, with images and text-fields in place, one page for the front of the printed card, the 2nd page for the reverse.

So, you asked "what I am trying to accomplish". And now I hope I have given a clear explanation.

Any thoughts? And can I use Set Field to put an image from my Mac into a Container field on a Layout?  If not, how?

Thanks again for all your help,  Philip Caplan

Posted

First we need to state the obvious: Filemaker is not a page layout program. You will have to lower your expectations.

The way I would approach this is define a repeating calculation field (result is Text) along the lines of:

If (
Extend ( SelectedRepetition ) = Get ( CalculationRepetitionNumber ) ;
TextSize ( TextFont ( TextColor ( Extend ( RequestedText ) ; RequestedTextColor ) ; RequestedTextFont ) RequestedTextSize ) 
)

This will place the text in the RequestedText field, formatted as defined in the RequestedTextColor, RequestedTextFont and RequestedTextSize fields, into the repetition specified in the SelectedRepetition field.

Now place any number of individual repetitions of this field on your layout, in any place you think it may be needed - even overlapping, if you want to have a finer resolution (make sure they have no fill or border). Note that each repetition can be aligned individually, so that would also take care of that.

Now you just need to select the repetition number and have the formatted text auto-magically appear in place.

 

  • Like 1
Posted

Thanks comment

I am having difficulty understanding why this needs to be a REPEATING calculation field, and how SelectedRepetition and CalculationRepetitionNumber get their values.

If (
Extend ( SelectedRepetition ) = Get ( CalculationRepetitionNumber ) ;
TextSize ( TextFont ( TextColor ( Extend ( RequestedText ) ; RequestedTextColor ) ; RequestedTextFont ) RequestedTextSize ) 
)

Is there a reason why it won't work to have a Calculation field called say FormattedzMESSAGE to format the content of zMESSAGE, like this:
TextSize( TextFont( TextColor(zMESSAGE;zTextColor);zTextFont) ;29)

where zMESSAGE is the name of the field on the Layout, zTextColor and zTextFont are fields containing for example RGB(255,255,0) and a valid Font Name, and 29 is a fixed value for the size in points (which I may later replace with a value in a Text or Number field).

I have tried the above calculation, and it doesn't error, but it doesn't seem to apply the formatting!!

But I don't understand how to use your calculation above, in respect of:
"do I create fields called "SelectedRepetition" and "CalculationRepetitionNumber" and what do I put in them if I only want one field to be formatted?

Posted
11 minutes ago, philipcaplan said:

why this needs to be a REPEATING calculation field

It doesn't. I just think it's more convenient than putting multiple instances of the same field on the layout and conditionally hiding all of them except one. I can't think of any other method for placing the text on the selected spot.

As for the rest, here's a bare bones demo showing how I imagined it could work.

DynamicLayout.fmp12

Posted

Thanks, comment.  That is very useful.

One thing though, I don't see an option to change the Font. Could you possibly add that?

Thanks again, Philip

Posted

I've tried!!!!   I added a field RequestedFont, and formatted it as a popup menu with 3 names.  Then I edited cTxtR to be this:
----------------------------------------------------------------
Let ( [

color = Case (
Extend ( RequestedTextColor ) = "Red" ; RGB ( 200 ; 0 ; 0 ) ;
Extend ( RequestedTextColor ) = "Green" ; RGB ( 0 ; 200 ; 0 ) ;
Extend ( RequestedTextColor ) = "Blue" ; RGB ( 0 ; 0 ; 200 )
) ;

fontName = Case (
Extend ( RequestedFont ) = "Beagle Boyz NZ" ; "Beagle Boyz NZ" ;
Extend ( RequestedFont ) = "Candy Dancer NF" ; "Candy Dancer NF" ;
Extend ( RequestedFont ) = "Georgia" ; "Georgia" ;
) ;

formattedText = TextSize ( TextColor ( Extend ( RequestedText ) ; color ) ; Extend ( RequestedTextSize ) ) ;

selectedRepetition = Case (
Extend ( RequestedPosition ) = "Top Left" ; 1 ;
Extend ( RequestedPosition ) = "Mid Left" ; 2 ;
Extend ( RequestedPosition ) = "Bottom Left" ; 3 ;
Extend ( RequestedPosition ) = "Top Right" ; 4 ;
Extend ( RequestedPosition ) = "Mid Right" ; 5 ;
Extend ( RequestedPosition ) = "Bottom Right" ; 6
)

] ;
If ( selectedRepetition = Get ( CalculationRepetitionNumber ) ; formattedText )
)
----------------------------------------------------------------
I added a section fontName = Case(); with some of the fonts from my Format >Font dropdown list,
and I tried adding "fontName" into the section below it in various ways but nothing worked.

Could you kindly tell me what the section of the script beginning "formattedText = " should look like in the above case.

This topic is 1530 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.