1 2 3 Previous Next 32 Replies Latest reply on Dec 20, 2016 5:07 PM by romax

    clickable partial text field with bold style

    romax

      Hey All, i’m Max and i am new in this forum.

      I Have “played” with FM since the times of version 8 but i never got too far into functions and scripts if not easy steps and some pre-made or light modified script. so be patient…

       

       

      This is the scenario:

      I have a database with over 1500 movies and for each record i have a text field called CAST in wich we find first and last name of actors and other stuff  like

       

      Cast:

      Name Surname: RoleName RoleSurname

      Name Surname: RoleName RoleSurname

      Name Surname: RoleName RoleSurname

      Name Surname: RoleName RoleSurname

       

       

       

       

       

      My goal

      obtain a clickable actor occurrence (name+surname) with bold partial formatting of a text field (Cast). By clicking the actor occurrence a search starts finding the records of the actor selected.

       

      my idea was to divide the problems in two

       

      PART1)a first script select the keywords using Get ( ActiveSelectionStart ) and Get ( ActiveSelectionStart ) in a script triggered by the field itself. The script should recognise and select the bold text as key text to be found.

       

      PART2) A second script should format actor occurrence as bold when they matched with same occurrence in another table field containing actors name or (maibe better) just format as bold the first two words after any carriage return

       

      ______________________________________________________________

       

      as for the PART1 (selecting script) i found the example of Phil Caulkins  here

      Trigger a script by selecting text

      and here the example i have studied on called Adentures on Filemaking n°1 by same author

      Dropbox - Adventure 1 CVLs.fmp12

       

      In his shared file he uses a script that gave me the idea to follow.. using the get active selection start he found the underlined text inA  text field and uses the selection to compose a URL to open via script.

      I changed some parameter so that sensible text is bolded instead of underlined and I used a carriage return instead of a tab (Char 13) as starting point (if I’m not wrong). then i used the variable in a search step instead of an open url. It work but there some…

       

      Part1 PROBLEMS: select script finds both word and not Name+Surname: eg. if an actor name is John Smith, if i click on Smith it finds also Robert Smith and if i click on John i find with same name but not surnamw.

      So my question is how can i get name+surname as a unique variable even if i click on single word (name or surname)? i think i must use previous word and next word operators but i can’t understand how.

      in this solution i see also another problem which comes out when the actors occurrence has more than two words (e.g. Catherine Zeta Jones).

      A solution could be selecting all the words before the symbol “:” which somehow divides what is interesting for a search from what is not.

       

      I made a DEMO PART1 of the script, you can see it here

      Dropbox - forum_example.fmp12

       

       

      ______________________________________________________________

       

       

      as for PART2 i am a bit more far…

      I tried the first approach (format as bold matched identical words in another field/table)

       

      Again the idea comes from Phil Caulkins as shown in this thread

       

      https://community.filemaker.com/message/272683#272683. 

       

      the script is this

       

      Set Variable [ $I; Value:1 ]

      Loop

             Set Variable [ $Word; Value:$Word + 1 ]

             If [ MiddleWords ( WordHighlighter::Paragraph ; $Word ; 1 ) = WordHighlighter::Word ]

                     Set Variable [ $Paragraph;

                                       Value:$Paragraph & TextStyleAdd ( Middle ( WordHighlighter::Paragraph;

                                       $I ; Position ( WordHighlighter::Paragraph ; WordHighlighter::Word ; $I ; 1 ) + Length ( WordHighlighter::Word ) - $I + 1 ) ; Bold ) ]

             Else

                     Set Variable [ $Paragraph; Value:Let ( word = MiddleWords ( WordHighlighter::Paragraph ; $Word ; 1 ) ; $Paragraph &

                                         Middle ( WordHighlighter::Paragraph; $I ; Position ( WordHighlighter::Paragraph ; word ; $I ; 1 ) + Length ( Word ) - $I + 1 ) ) ]

             End If

             Set Variable [ $I; Value:Let ( word = MiddleWords ( WordHighlighter::Paragraph ; $Word ; 1 ) ;

                                 Position ( WordHighlighter::Paragraph ; Word ; $I ; 1 ) + Length ( Word ) ) + 1 ]

             Exit Loop If [ $Word ≥ WordCount ( WordHighlighter::Paragraph ) ]

      End Loop

      Set Field [ WordHighlighter::Paragraph 2; $Paragraph ]

       

       

      i have changed the statement [ MiddleWords ( WordHighlighter::Paragraph ; $Word ; 1 ) in [ MiddleWords ( WordHighlighter::Paragraph ; $Word ; 2 ) to get 2 words from the starting point but but can’t make it work because two problems i think.

       

      PROBLEMS

      First, i don’t have a single field for any actor but i have a single field containing many actors and names and i can’t focus how i can match them with multiple words, and second i can’t make it work using 2 words or more: if i set a name John Smith as the word to be matched but when i write something similar like John Smithsonian bold style disappear and i can see only John on second paragraph.

      here a test file with matching solution

       

      Dropbox - provecast.fmp12

       

      Maybe also here the solution can come out formatting as bold al the words in the field before the sign ":" but can't find anything i can study on.

       

      so at this point im'asking

      how can i format and search all the word in a field which come before the ":" mark?

       

       

       

      Any suggestion is warmly accepted, sorry for the long text in here but i wanted to give more infos i could.

       

      Many thanks

      Regards

      Max

        • 1. Re: clickable partial text field with bold style
          philmodjunk

          Looks like my adventure file has led you on an adventure--as it was designed to do ;-)

           

          unfortunately, I'm using my iPhone and can't get to my own files right away. I'm just tossing out some general observations:

           

          the tab character is char (9)

          your list of actors and roles might be better displayed using a portal. This would eliminate the need for the first script to search for styled text.

           

          I'll try to get time to look at this in more detail later.

          • 2. Re: clickable partial text field with bold style
            erolst

            romax wrote:

            Hey All, i’m Max and i am new in this forum.

            I Have “played” with FM since the times of version 8 but i never got too far into functions and scripts if not easy steps and some pre-made or light modified script. so be patient…

             

             

            This is the scenario:

            I have a database with over 1500 movies and for each record i have a text field called CAST in wich we find first and last name of actors and other stuff like

             

            Cast:

            Name Surname: RoleName RoleSurname

            Name Surname: RoleName RoleSurname

            Name Surname: RoleName RoleSurname

            Name Surname: RoleName RoleSurname

            Hi Max -

             

            sorry to be blunt, but at that point I stopped reading.

             

            Instead of asingle Movie table, you should employ a relational structure like

             

            Movie --< Cast >-- Actor

             

            which means "one movie can have many actors, one actor can appear in many movies"

             

            Here every line from your textbox is a record in the cast table (where you find fields for role name, credit number etc.) that connects - via 'foreign keys' - an actor with a movie - which is what 'cast member' means.

             

            If you look at a movies's cast list and want to see other movies with a given actor, just go to that person's record and see a list in a portal, or create a summarized listing of cast entries. This can be achieved with a simple script. If you want to see a name in bold, format the (related) name field etc. If you want to sort the cast list by first name, last name, credit# or order of entry, no problem.

             

            Even if you do not want to create a dedicated Actor or Person table, simply storing each line of your Cast field in separate fields in a separate record would be a giant leap.

             

            I'd advise you to spend your energy on converting your existing system into such a setup, instead of wasting it on efforts to remedy the many disadvantages of a bad structure. Just ask if you need assistance; you'd be rewarded with a much more versatile and useful system.

             

            As it happens, I'm maintaining a movie database in FM for about 20 years now; my Cast table is actually an Appearance table; use an additional typeOfAppearance field, and you can store the crew in there, too. Consequently, the Actor table is called People.

            • 3. Re: clickable partial text field with bold style
              romax

              Hey Phil, firts let me thank you for all the scripts you post around the world which are much appriciated

              I used Char 13 instead of 9 cause i wanted to use a carriage return instead of a tab like starting point just for design reasons

               

               

              Thanks also to eroes for the quick response. And you're right...

              I have many portal and relations in my database but never used with long field (some cast entries have more than 20 names...) and ususally i get cast from wikipedia with a unique copy/paste into the field.

              I see what you saying and i will surely implement my database with a specific table containig each actor name in a single record in the future ( need to find some auto enter script cause w'ere talking about 10 names avg for each movies so i'm thinking that cast table should contain something like 10000/15000 records (some cast can reach 30 lines and more). Also Can't see how to pick up rolename wich is different even with same actor...   but will figure out when time comes.

               

              Hower i will need a clickable formatted instance also for other large fields like Critics, Award, Directors Note and so on... in which i have fields with 2000 to 8000 characters where i can search a specific word just formatting it as bold and would be very handy in my eyes.

               

              Max

              • 4. Re: clickable partial text field with bold style
                user19752

                #Find between line break and :

                Set Variable [ $Cursor; Value:Get ( ActiveSelectionStart ) ]

                Set Variable [ $Text; Value:Get ( ActiveFieldContents ) ]

                Set Variable [ $Start; Value:Min ( Position ( $text ; ¶ ; 1 ; 1 ) + 1 ; $Cursor ) ]

                Set Variable [ $End; Value:Max ( Position ( $Text ; ":" ; $cursor ; 1 ) ; 0 ) ]

                If [ $end > $start ]

                Enter Find Mode [ ]

                Set Field [ Movies::Cast; Middle ( $Text ; $Start ; $End - $Start ) ]

                Perform Find [ ]

                Go to Layout [ “MovieList” (Movies) ]

                Else

                Show Custom Dialog [ Message: "Error processing Mouse Click"; Default Button: “OK”, Commit: “Yes” ]

                End If

                Commit Records/Requests

                 

                This search CR before cursor and : after cursor, like "clicking bolded word", but it may be better searching in clicked line.

                • 5. Re: clickable partial text field with bold style
                  user19752

                  I made a custom function

                   

                  GetBoldTextAroundCursor ( text ; start ; end )

                  /*

                  parameters

                  text: Get ( ActiveFieldContents )

                  start: Get ( ActiveSelectionStart )

                  end: Get ( ActiveSelectionStart )

                  All parameter values can be get internally, so it would be better to define wrapper function

                  */

                   

                  Case ( start = 0 ; "" ;

                    Let ( [ newstart = Max ( 1 ; start - ( PatternCount ( GetAsCSS ( Middle ( text ; start - 1 ; 1 ) ) ; "bold" ) > 0 ) ) ;

                        newend = end + ( PatternCount ( GetAsCSS ( Middle ( text ; end ; 1 ) ) ; "bold" ) > 0 ) ] ;

                      Case ( newstart = start and newend = end ; Middle ( text ; start ; end - start ) ;

                        GetBoldTextAroundCursor ( text ; newstart ; newend )

                      )

                    )

                  )

                  2 of 2 people found this helpful
                  • 6. Re: clickable partial text field with bold style
                    romax

                    hi user19752

                     

                    Thanks for your time and examples, much appriciated!!!

                     

                    I was testing your first script while you posted the Custom Function that i will try to study and use later on.

                     

                     

                    About the script it works but only on the first line:

                     

                     

                     

                    i made a demo to better explain the problem:

                     

                    e.g. i have Autore Name1 which appears in 7 movies. On record 1 clicking on autor name1 correctly gives 7 movies in the list while if you click on second word Autor Name2 show only 1 record while the correct search shoud give 2. In othere words: all the researches below the first instance are wrong.

                     

                    About the function... im still studing it but i don't know what you mean with "define wrapper function" Also can't figure out how to call the function with correct parameters in my fields...

                     

                    Again thanks for your time

                    Max

                     

                     

                     

                     

                     

                    • 7. Re: clickable partial text field with bold style
                      erolst

                      romax wrote:

                      e.g. i have Autore Name1 which appears in 7 movies. On record 1 clicking on autor name1 correctly gives 7 movies in the list while if you click on second word Autor Name2 show only 1 record while the correct search shoud give 2. In othere words: all the researches below the first instance are wrong.

                       

                      What if there is another person with that name?

                       

                      This seems to be an elaborate wild goose chase. I again advise you to normalize your database; if importing from IMDb is so important to you, write scripts that create new cast, crew and people records based on the name lists you throw at them. If I did it, so can you ...

                      • 8. Re: clickable partial text field with bold style
                        romax

                        hey erolst,

                        im working on your suggestion on making a separated table called People. I made a lil script which devides the full name and surname in two gettin each one as a sperate field. I'm supposing I have to relate Cast  table actor table and Titles.

                         

                        The problem i have is how to figure out the role part relations. Also I dont like much the fact that for every record i have to fill so many separate field. In a movie with 30 players it means 120 entries (name, surname, rolename role surname)... it would be a huge data entry work.

                         

                        So i was thinking to use this approach for directors wich are way less and dont't have a playrole to attach.

                        I think i will open another discussion to about relations and foreing key that now im watching closely.

                         

                        This clickable instance instead is used in note field where are collected movies reviews and where each autor has a bold text joined by a ":" There are no movie critics with same name and even in that case Name+LastName give the exact match i think.

                         

                         

                        Thanks

                        Max

                        • 9. Re: clickable partial text field with bold style
                          David Moyer

                          Hi,

                          I apologize for not poring over this entire post ... but I think I saw a typo above and it compelled me to present, for possible utility, a function that returns the "Active Selection" (i.e. the user-selected text in a text field) ...

                          Middle(

                            Get(ActiveFieldContents);

                            Get(ActiveSelectionStart);

                            Get(ActiveSelectionSize)

                          )

                          • 10. Re: clickable partial text field with bold style
                            erolst

                            romax wrote:

                            Also I dont like much the fact that for every record i have to fill so many separate field. In a movie with 30 players it means 120 entries (name, surname, rolename role surname)... it would be a huge data entry work.

                            I wouldn't much like the fact that I had to painstakingly take care of how I must format the text input in these lists of yours.

                             

                            If your main import source is IMDb, you can write a script that parses imported/pasted text chunks, adds records for any missing people, then creates the join tables records, setting the correct foreign keys and the role name.

                             

                            Its actually easier for a cast list, because their type *is* just cast, but for crew members you have to parse the surrounding text for keywords.

                             

                            If I'm not mistaken, you can access the raw data that IMDb uses to build the html in a pure text format, which may make such parsing tasks easier.

                             

                            btw, I'm not sure it is worthwhile to store a rolename as first and last name, or lavish any attention on them that goes beyond correct spelling. It's a different story with the names of real people.

                            • 11. Re: clickable partial text field with bold style
                              user19752

                              This is not reply for my post, but seems "typo" about me.

                              It is not typo. The custom function intend to be used in onObjectEnter trigger script that the demo file use. There is no selection of text when entering a field.

                               

                              "Wrapper" mean defining a custom function without parameter

                              GetBold

                              as

                              GetBoldTextAroundCursor ( Get ( ActiveFieldContents ) ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionStart ) )

                              1 of 1 people found this helpful
                              • 13. Re: clickable partial text field with bold style
                                romax

                                user19752 wrote:

                                 

                                This is not reply for my post, but seems "typo" about me.

                                It is not typo. The custom function intend to be used in onObjectEnter trigger script that the demo file use. There is no selection of text when entering a field.

                                 

                                "Wrapper" mean defining a custom function without parameter

                                GetBold

                                as

                                GetBoldTextAroundCursor ( Get ( ActiveFieldContents ) ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionStart ) )

                                thank you, will try it ASAP

                                • 14. Re: clickable partial text field with bold style
                                  romax

                                  I wouldn't much like the fact that I had to painstakingly take care of how I must format the text input in these lists of yours.

                                  Uhm... maybe i don't get it (english its not my mother tongue).

                                  As for me, looks like i'm not asking someone to painstakingly do something... or did I?

                                  I'm here to learn as a simple enthusiast of filemaker, i saw many similar question like this before posting and i supposed that the partial formatting of a text via script was a common problem and a useful thing to do/learn.

                                   

                                  I made a script roughly do the same thing using

                                   

                                  Middle( CAST ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionSize ))

                                   

                                  find the clicked word and passes as a variable to be find and thought it would have been a good implement associate this with a text stylisation to enlighten this possibility.

                                  As i said at the beginning I don't do this for work, i just play with my personal movie collection since filemaker 8... the pain is away from here

                                   

                                  If your main import source is IMDb, you can write a script that parses imported/pasted text chunks, adds records for any missing people, then creates the join tables records, setting the correct foreign keys and the role name.

                                  As mentioned before i just copy and paste text from wikipedia I'm not learnt to these kind of automated tasks... but i would like to learn. Right now not able to parse anything here... i just cmd+c cmd+v 

                                   

                                  If I'm not mistaken, you can access the raw data that IMDb uses to build the html in a pure text format, which may make such parsing tasks easier.

                                  very interesting indeed but i'm billion miles far to be able to do such stuff. Can you tell me where i can start reading something about or where i can find something to study on?

                                   

                                  btw, I'm not sure it is worthwhile to store a rolename as first and last name, or lavish any attention on them that goes beyond correct spelling. It's a different story with the names of real people.

                                  True. Very true. I just stumble from an excess to another.. a unique field and string would be enough.

                                   

                                  Thanks

                                  Max

                                  1 2 3 Previous Next