Loading ...
Sorry, an error occurred while loading the content.
 

Re: [Clip] Regex and functions again

Expand Messages
  • Don - HtmlFixIt.com
    I think that is the logic I would use. By assigning it a variable ... we can then work with it.
    Message 1 of 14 , Feb 3, 2010
      I think that is the logic I would use. By assigning it a variable ...
      we can then work with it.
      > Find the bracket
      > Put selection in variable
      > Select whole line
      > InsertHtml long string using the variable
      > Loop
      >
      > Would this be the easiest one?
    • Axel Berger
      ... Sorry for having misused you all as sounding board, thinking aloud while typing. Unfortunately it didn t solve the problem: ^!Continue B^%varNAM%.jpg
      Message 2 of 14 , Feb 3, 2010
        "Don - HtmlFixIt.com" wrote:
        > I think that is the logic I would use.

        Sorry for having misused you all as sounding board, thinking aloud while
        typing. Unfortunately it didn't solve the problem:

        ^!Continue B^%varNAM%.jpg
        ^!InsertHtml ... WIDTH="^$GetImgWidth("B^%varNAM%.jpg")$"

        The continue confirms the correct file name. I tried with and without
        quotes in the parentheses. The graphics are in the same directory as the
        index.htm I'm working on and the latter was opened from there, so the
        path is correct. Apart from that the loop worked fine and provided the
        same result as the Replace did before.

        What am I missing?

        Danke
        Axel (off to bed soon, sun's coming up)
      • Hugo Paulissen
        Hi Alex (good morning;-), ...   I guess your problem has to do with the parsing sequence (look at B3). This comes from the introduction of the Clip Script
        Message 3 of 14 , Feb 4, 2010
          Hi Alex (good morning;-),

          > What am I missing?
           
          I guess your problem has to do with the parsing sequence (look at B3). This comes from the introduction of the Clip Script Help.
           
          Hugo
           
          ------
           
          Parsing and evaluation sequence
           
          A. Whole Clip
           
          1. Comments removed
          2. Date fields evaluated ^[...^] (old format)
          3. Text selection inserted if ^& found
          4. ^!CONTINUE command executed if on first line
          5. Clip wizard based on ^?[...] fields displayed
          6. Mathematical fields evaluated ^$[...] (old format)
           
          B. Line by line
           
          1. Variables resolved (from right to left)
          2. Document name using ^*, ^**, ^#, ^## codes resolved
          3. Functions resolved (from right to left)
          4. Clip wizard based on ^?{...} fields in line displayed
          5. Clip Command executed
           
          ------





          [Non-text portions of this message have been removed]
        • Sheri
          ... I think I would do the replace-all, then save the document to a NoteTab template (would need a special header at the top, and a file name ending with
          Message 4 of 14 , Feb 4, 2010
            --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
            >
            > On a folder of images I do a DIR and get a list like:
            >
            > B01-1.jpg
            > B01-2.jpg
            > B02-1.jpg
            > B02-2.jpg
            >
            > On that I run a clip of which this is a highly truncated part (extra
            > line feeds added for clarity:
            >
            > ^!Replace "B(.+)\.jpg\R" >> "
            > <IMG SRC="B$1.jpg"
            > WIDTH="^$GetImgWidth(B$1.jpg)$"
            > HEIGHT="^$GetImgHeight(B$1.jpg)$">
            > " WRASI
            >
            > For this to work the clip would have to first insert the $1, second
            > evaluate the function and third write the replace string. It doesn't
            > work that way.
            >
            > In my real replace string there's much more and $1 gets used in many
            > places. One solution could work like:
            >
            > Find the bracket
            > Put selection in variable
            > Select whole line
            > InsertHtml long string using the variable
            > Loop
            >
            > Would this be the easiest one?
            >

            I think I would do the replace-all, then save the document to a NoteTab template (would need a special header at the top, and a file name ending with .tpl), then close the document, then open the template. Upon opening the template, all embedded NoteTab functions previously written by the replace-all will be evaluated. If this is something to done more than once, the processing (saving and opening, etc.) could be incorporated into the main clip.

            Regards,
            Sheri
          • diodeom
            ... I d reach for images directly: ^!Set %path%=^?{(T=D)Select Folder:} ^!Set %img%=^$GetFileFirst(^%path%;*.jpg)$ ;long line begins
            Message 5 of 14 , Feb 4, 2010
              --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
              >
              > On a folder of images I do a DIR and get a list like:
              >
              > B01-1.jpg
              > B01-2.jpg
              > B02-1.jpg
              > B02-2.jpg
              >
              > On that I run a clip of which this is a highly truncated part (extra
              > line feeds added for clarity:
              >
              > ^!Replace "B(.+)\.jpg\R" >> "
              > <IMG SRC="B$1.jpg"
              > WIDTH="^$GetImgWidth(B$1.jpg)$"
              > HEIGHT="^$GetImgHeight(B$1.jpg)$">
              > " WRASI
              >
              > For this to work the clip would have to first insert the $1, second
              > evaluate the function and third write the replace string. It doesn't
              > work that way.
              >
              > In my real replace string there's much more and $1 gets used in many
              > places. One solution could work like:
              >
              > Find the bracket
              > Put selection in variable
              > Select whole line
              > InsertHtml long string using the variable
              > Loop
              >
              > Would this be the easiest one?
              >
              > Thanks
              > Axel
              >

              I'd reach for images directly:

              ^!Set %path%=^?{(T=D)Select Folder:}
              ^!Set %img%=^$GetFileFirst(^%path%;*.jpg)$
              ;long line begins
              <img src="^$GetName(^%img%)$.jpg" width="^$GetImgWidth(^%img%)$" height="^$GetImgHeight(^%img%)$">^%nl%
              ;long line ends
              :Loop
              ^!Set %img%=^$GetFileNext$
              ^!IfEmpty ^%img% Done
              ;long line begins
              <img src="^$GetName(^%img%)$.jpg" width="^$GetImgWidth(^%img%)$" height="^$GetImgHeight(^%img%)$">^%nl%
              ;long line ends
              ^!Goto Loop
              :Done
              ^!CloseFileFind
              ^!ClearVariable %path%
              ^!ClearVariable %img%

              Dio
            • diodeom
              ... I think it will evaluate just fine once the full path/name is included.
              Message 6 of 14 , Feb 4, 2010
                --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
                >
                > ^!Continue B^%varNAM%.jpg
                > ^!InsertHtml ... WIDTH="^$GetImgWidth("B^%varNAM%.jpg")$"
                >
                > The continue confirms the correct file name. I tried with and without
                > quotes in the parentheses. The graphics are in the same directory as the
                > index.htm I'm working on and the latter was opened from there, so the
                > path is correct. Apart from that the loop worked fine and provided the
                > same result as the Replace did before.
                >
                > What am I missing?
                >
                > Danke
                > Axel (off to bed soon, sun's coming up)
                >

                I think it will evaluate just fine once the full path/name is included.
              • Don - HtmlFixIt.com
                That was my take on it too as I think I have done very similar in the past. I did not have time today to try it so I kept quiet :-)
                Message 7 of 14 , Feb 4, 2010
                  That was my take on it too as I think I have done very similar in the
                  past. I did not have time today to try it so I kept quiet :-)

                  diodeom wrote:
                  > --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
                  >> ^!Continue B^%varNAM%.jpg
                  >> ^!InsertHtml ... WIDTH="^$GetImgWidth("B^%varNAM%.jpg")$"
                  >>
                  >> The continue confirms the correct file name. I tried with and without
                  >> quotes in the parentheses. The graphics are in the same directory as the
                  >> index.htm I'm working on and the latter was opened from there, so the
                  >> path is correct. Apart from that the loop worked fine and provided the
                  >> same result as the Replace did before.
                  >>
                  >> What am I missing?
                  >>
                  >> Danke
                  >> Axel (off to bed soon, sun's coming up)
                  >>
                  >
                  > I think it will evaluate just fine once the full path/name is included.
                • Hugo Paulissen
                  I did try that but it didn t work, hence my suggestion for the parsing sequence. Hugo ________________________________ From: Don - HtmlFixIt.com
                  Message 8 of 14 , Feb 4, 2010
                    I did try that but it didn't work, hence my suggestion for the parsing sequence.


                    Hugo



                    ________________________________
                    From: Don - HtmlFixIt.com <don@...>
                    To: ntb-clips@yahoogroups.com
                    Sent: Thu, February 4, 2010 7:09:15 PM
                    Subject: Re: [Clip] Regex and functions again


                    That was my take on it too as I think I have done very similar in the
                    past. I did not have time today to try it so I kept quiet :-)

                    diodeom wrote:
                    > --- In ntb-clips@yahoogrou ps.com, Axel Berger <Axel-Berger@ ...> wrote:
                    >> ^!Continue B^%varNAM%.jpg
                    >> ^!InsertHtml ... WIDTH="^$GetImgWidt h("B^%varNAM% .jpg")$"
                    >>
                    >> The continue confirms the correct file name. I tried with and without
                    >> quotes in the parentheses. The graphics are in the same directory as the
                    >> index.htm I'm working on and the latter was opened from there, so the
                    >> path is correct. Apart from that the loop worked fine and provided the
                    >> same result as the Replace did before.
                    >>
                    >> What am I missing?
                    >>
                    >> Danke
                    >> Axel (off to bed soon, sun's coming up)
                    >>
                    >
                    > I think it will evaluate just fine once the full path/name is included.






                    [Non-text portions of this message have been removed]
                  • diodeom
                    What I tried is this: If my folder is C: Sample, it contains the referenced files and my current doc happens to be the list of these files: pic_1.jpg pic_2.jpg
                    Message 9 of 14 , Feb 4, 2010
                      What I tried is this:

                      If my folder is C:\Sample, it contains the referenced files and my current doc happens to be the list of these files:

                      pic_1.jpg
                      pic_2.jpg
                      pic_3.jpg

                      This works for me:

                      ^!Set %path%=C:\Sample\
                      ^!SetArray %img%=^$GetDocMatchAll("^(.+?)\.jpg";1)$
                      ^!Set %count%=0
                      ^!Select ALL
                      :Loop
                      ^!Inc %count%
                      ^!If ^%count%>^%img0% Done
                      ;long line begins
                      ^!InsertHtml <img src="^%img^%count%%.jpg" width="^$GetImgWidth("^%path%\^%img^%count%%.jpg")$"^%nl%
                      ;long line ends
                      ^!Goto Loop
                      :Done
                      ^!ClearVariable %path%
                      ^!ClearVariable %img%

                      My outcome:

                      <img src="pic_1.jpg" width="140"
                      <img src="pic_2.jpg" width="75"
                      <img src="pic_3.jpg" width="100"

                      Dio

                      --- In ntb-clips@yahoogroups.com, Hugo Paulissen <hugopaulissen@...> wrote:
                      >
                      >
                      > I did try that but it didn't work, hence my suggestion for the parsing sequence.
                      >
                      >
                      > Hugo
                      >
                      >
                      >
                      > ________________________________
                      > From: Don - HtmlFixIt.com <don@...>
                      > To: ntb-clips@yahoogroups.com
                      > Sent: Thu, February 4, 2010 7:09:15 PM
                      > Subject: Re: [Clip] Regex and functions again
                      >
                      >
                      > That was my take on it too as I think I have done very similar in the
                      > past. I did not have time today to try it so I kept quiet :-)
                      >
                      > diodeom wrote:
                      > > --- In ntb-clips@yahoogrou ps.com, Axel Berger <Axel-Berger@ ...> wrote:
                      > >> ^!Continue B^%varNAM%.jpg
                      > >> ^!InsertHtml ... WIDTH="^$GetImgWidt h("B^%varNAM% .jpg")$"
                      > >>
                      > >> The continue confirms the correct file name. I tried with and without
                      > >> quotes in the parentheses. The graphics are in the same directory as the
                      > >> index.htm I'm working on and the latter was opened from there, so the
                      > >> path is correct. Apart from that the loop worked fine and provided the
                      > >> same result as the Replace did before.
                      > >>
                      > >> What am I missing?
                      > >>
                      > >> Danke
                      > >> Axel (off to bed soon, sun's coming up)
                      > >>
                      > >
                      > > I think it will evaluate just fine once the full path/name is included.
                      >
                      >
                      >
                      >
                      >
                      >
                      > [Non-text portions of this message have been removed]
                      >
                    • Hugo Paulissen
                      Hi, I d do that as well, but I was trying to explain why Axels replace operation didn t work. What you do here is populate the variables before the Replace
                      Message 10 of 14 , Feb 4, 2010
                        Hi,

                        I'd do that as well, but I was trying to explain why Axels replace operation didn't work. What you do here is populate the variables before the Replace line is executed. If the clip is executed it finds that the variables path, img and count are filled, so the GetImgWidth function actually works.

                        In Axels clip the $1 is a Regex -"variable". If the clip is executed the function does not know what the content of $1 actually is, and that's why the GetImgWidth function fails.

                        Well, that's what I assumed...

                        Hugo




                        ________________________________
                        What I tried is this:


                        If my folder is C:\Sample, it contains the referenced files and my current doc happens to be the list of these files:

                        pic_1.jpg
                        pic_2.jpg
                        pic_3.jpg

                        This works for me:

                        ^!Set %path%=C:\Sample\
                        ^!SetArray %img%=^$GetDocMatch All("^(.+ ?)\.jpg"; 1)$
                        ^!Set %count%=0
                        ^!Select ALL
                        :Loop
                        ^!Inc %count%
                        ^!If ^%count%>^%img0% Done
                        ;long line begins
                        ^!InsertHtml <img src="^%img^% count%%.jpg" width="^$GetImgWidt h("^%path% \^%img^%count% %.jpg")$" ^%nl%
                        ;long line ends
                        ^!Goto Loop
                        :Done
                        ^!ClearVariable %path%
                        ^!ClearVariable %img%

                        My outcome:

                        <img src="pic_1.jpg" width="140"
                        <img src="pic_2.jpg" width="75"
                        <img src="pic_3.jpg" width="100"

                        Dio

                        --- In ntb-clips@yahoogrou ps.com, Hugo Paulissen <hugopaulissen@ ...> wrote:
                        >
                        >
                        > I did try that but it didn't work, hence my suggestion for the parsing sequence.
                        >
                        >
                        > Hugo
                        >
                        >
                        >
                        > ____________ _________ _________ __
                        > From: Don - HtmlFixIt.com <don@...>
                        > To: ntb-clips@yahoogrou ps.com
                        > Sent: Thu, February 4, 2010 7:09:15 PM
                        > Subject: Re: [Clip] Regex and functions again
                        >
                        >
                        > That was my take on it too as I think I have done very similar in the
                        > past. I did not have time today to try it so I kept quiet :-)
                        >
                        > diodeom wrote:
                        > > --- In ntb-clips@yahoogrou ps.com, Axel Berger <Axel-Berger@ ...> wrote:
                        > >> ^!Continue B^%varNAM%.jpg
                        > >> ^!InsertHtml ... WIDTH="^$GetImgWidt h("B^%varNAM% .jpg")$"
                        > >>
                        > >> The continue confirms the correct file name. I tried with and without
                        > >> quotes in the parentheses. The graphics are in the same directory as the
                        > >> index.htm I'm working on and the latter was opened from there, so the
                        > >> path is correct. Apart from that the loop worked fine and provided the
                        > >> same result as the Replace did before.
                        > >>
                        > >> What am I missing?
                        > >>
                        > >> Danke
                        > >> Axel (off to bed soon, sun's coming up)
                        > >>
                        > >
                        > > I think it will evaluate just fine once the full path/name is included.
                        >
                        >>







                        [Non-text portions of this message have been removed]
                      • diodeom
                        I suspected you had an earlier point of reference. I pretty much followed Alex s outline of another approach after (I believe) he dismissed ^!Replace with
                        Message 11 of 14 , Feb 4, 2010
                          I suspected you had an earlier point of reference. I pretty much followed Alex's outline of another approach after (I believe) he dismissed ^!Replace with nested functions.

                          --- In ntb-clips@yahoogroups.com, Hugo Paulissen <hugopaulissen@...> wrote:
                          >
                          > Hi,
                          >
                          > I'd do that as well, but I was trying to explain why Axels replace operation didn't work. What you do here is populate the variables before the Replace line is executed. If the clip is executed it finds that the variables path, img and count are filled, so the GetImgWidth function actually works.
                          >
                          > In Axels clip the $1 is a Regex -"variable". If the clip is executed the function does not know what the content of $1 actually is, and that's why the GetImgWidth function fails.
                          >
                          > Well, that's what I assumed...
                          >
                          > Hugo
                          >
                          >
                          >
                          >
                          > ________________________________
                          > What I tried is this:
                          >
                          >
                          > If my folder is C:\Sample, it contains the referenced files and my current doc happens to be the list of these files:
                          >
                          > pic_1.jpg
                          > pic_2.jpg
                          > pic_3.jpg
                          >
                          > This works for me:
                          >
                          > ^!Set %path%=C:\Sample\
                          > ^!SetArray %img%=^$GetDocMatch All("^(.+ ?)\.jpg"; 1)$
                          > ^!Set %count%=0
                          > ^!Select ALL
                          > :Loop
                          > ^!Inc %count%
                          > ^!If ^%count%>^%img0% Done
                          > ;long line begins
                          > ^!InsertHtml <img src="^%img^% count%%.jpg" width="^$GetImgWidt h("^%path% \^%img^%count% %.jpg")$" ^%nl%
                          > ;long line ends
                          > ^!Goto Loop
                          > :Done
                          > ^!ClearVariable %path%
                          > ^!ClearVariable %img%
                          >
                          > My outcome:
                          >
                          > <img src="pic_1.jpg" width="140"
                          > <img src="pic_2.jpg" width="75"
                          > <img src="pic_3.jpg" width="100"
                          >
                          > Dio
                          >
                          > --- In ntb-clips@yahoogrou ps.com, Hugo Paulissen <hugopaulissen@ ...> wrote:
                          > >
                          > >
                          > > I did try that but it didn't work, hence my suggestion for the parsing sequence.
                          > >
                          > >
                          > > Hugo
                          > >
                          > >
                          > >
                          > > ____________ _________ _________ __
                          > > From: Don - HtmlFixIt.com <don@>
                          > > To: ntb-clips@yahoogrou ps.com
                          > > Sent: Thu, February 4, 2010 7:09:15 PM
                          > > Subject: Re: [Clip] Regex and functions again
                          > >
                          > >
                          > > That was my take on it too as I think I have done very similar in the
                          > > past. I did not have time today to try it so I kept quiet :-)
                          > >
                          > > diodeom wrote:
                          > > > --- In ntb-clips@yahoogrou ps.com, Axel Berger <Axel-Berger@ ...> wrote:
                          > > >> ^!Continue B^%varNAM%.jpg
                          > > >> ^!InsertHtml ... WIDTH="^$GetImgWidt h("B^%varNAM% .jpg")$"
                          > > >>
                          > > >> The continue confirms the correct file name. I tried with and without
                          > > >> quotes in the parentheses. The graphics are in the same directory as the
                          > > >> index.htm I'm working on and the latter was opened from there, so the
                          > > >> path is correct. Apart from that the loop worked fine and provided the
                          > > >> same result as the Replace did before.
                          > > >>
                          > > >> What am I missing?
                          > > >>
                          > > >> Danke
                          > > >> Axel (off to bed soon, sun's coming up)
                          > > >>
                          > > >
                          > > > I think it will evaluate just fine once the full path/name is included.
                          > >
                          > >>
                          >
                          >
                          >
                          >
                          >
                          >
                          >
                          > [Non-text portions of this message have been removed]
                          >
                        • Axel Berger
                          The sun s well down, I ve finally got enough coffee in my veins to combat the raging headache the change of weather gave me and things are also looking bright
                          Message 12 of 14 , Feb 4, 2010
                            The sun's well down, I've finally got enough coffee in my veins to
                            combat the raging headache the change of weather gave me and things are
                            also looking bright on the Clips side of things:


                            diodeom wrote:
                            > I think it will evaluate just fine once the full path is included.

                            You're right, that's it. I've now got

                            WIDTH="^$GetImgWidth(^$GetPath(^##)$B^%varNAM%.jpg)$"

                            and it does what I hoped it would. I also tried incorporating this
                            solution into my earlier Replace, but still no luck, so I'll stick with
                            the loop. It is noticeably slower but still only a second or less for
                            any sensible number of files.

                            Thanks to all of you
                            Axel
                          • diodeom
                            ... In comparing execution times I d account here for the fact that while one clip rather idly swaps strings, the other — according to the objectives — has
                            Message 13 of 14 , Feb 4, 2010
                              Axel Berger <Axel-Berger@...> wrote:
                              > (...)
                              > I also tried incorporating this solution into my earlier Replace,
                              > but still no luck, so I'll stick with the loop. It is noticeably
                              > slower but still only a second or less for any sensible number of
                              > files.
                              >

                              In comparing execution times I'd account here for the fact that while one clip rather idly swaps strings, the other — according to the objectives — has some actual work to do, one image at the time, one function at the time.

                              BTW, sorry, Axel, for anagramming your name @ msg # 20326.
                            Your message has been successfully submitted and would be delivered to recipients shortly.