Macro Toolworks Products Discussion Forums :: Knowledge Base
Welcome Guest   
 Subject :Undocumented used of %vVar%.. 24-12-2009 07:48:51 
GeoD_MTW
Joined: 10-12-2009 08:07:49
Posts: 15
Location
***Posting Note*** After I posted this, I discovered the new forum needs a bit of tweaking. It seems that including the right and left arrows normally used in MTW macros causes problems, (just like in MTW). I replaced the arrows with '{' & '}'. Until this problem gets fixed, you'll have to do a find and replace to use the code, as it is posted. (I also have to figure out how to turn off the damn automatic smiley faces, as well.)

Hello all, and welcome to the new MTW home,

I thought I'd christen the long-awaited new forum with something I recently discovered: un-documented uses for %vVar% values.

The first usage I discovered was as the 'ItemLabel' of a {form_item} command.

--- Using %vVar% As an 'ItemLabel'

I was creating a macro for someone to use in managing video files used in language tests. There were hundreds of these videos and they needed to be organized by the person's name contained in the video's filename. The users wanted to be able to move the videos to various hard drives, into folders based on the person's name, (ie: x:\first.last). The problem was some of the filenames had just a first name, others had first and last and still others had first, middle and last names.

Here's some examples of the video filenames:

2009-05.15=Sarah.Reynolds.playing.cards.at.long.table.wmv
2008-09.10=Annette.Adams.n.backyard-washing.dog.avi
2009-02.18=Leonard.n.black.hat.-riding.white.horse.avi
2009-11.02=Billy.Bob.James.running.on.track.n.blue.shirt.avi
2008-07.26=Kevin.Allen.n.white.helmet.on.motorcycle.avi

I wanted the process to be only one macro and as few keystrokes as possible - the process couldn't be completely automated, so I wanted to minimize user input.

I needed the macro to do two major tasks: harvest the person's name and move the file. I broke the macro into two parts based on those tasks. The user would select the file, then start the macro. After the person name was harvested, a form would pop up offering destination choices.

I realized I needed some way for the user to validate the accuracy of the harvest process. I started by using a {msg} that popped up before the form. Then I got to wondering if I could use the %vVar% I was using in the {msg} in the {form_item} itself. Here's what I ended up with.

Notes:
The working version has about 20 hard drives and/or hard drive/folder paths to choose from. I had a bit of editorial license with the filenames, as along as I didn't change the data, so I reformatted the date info and inserted the '=' just before the first name. I use that unique character as a reference point for harvesting the person name.

What really makes the macro much less input intensive is that ability to use %vVar% in the {form_item} - otherwise, organizing the files would be quite tedious, (and they receive several hundred new vids each week).

{#} ============== macro.start ==============
{#} transport..send.to.=.star.named.folder
{#}
{#} This macro harvests the person name from the clip title and moves the file to a folder based on the person name.
{#}
{#} harvest name and move file to folder based on name
{cmds}
{#} ============== harvest.=.filename ==============
{keys}{F2}{cmds}
{wx}(300)
{keys}{ctrl}c{ctrl}{cmds}
{wx}(200)
{keys}{enter}{cmds}
{wx}(100)
{var_oper}(vTitle,"",GET_TEXT_FROM_CLIPBOARD,"","","0")
{#} ============== harvest.=.file pathname ==============
{keys}{alt}d{alt}{cmds}
{wx}(250)
{keys}{ctrl}c{ctrl}{cmds}
{wx}(200)
{var_oper}(vPath,"",GET_TEXT_FROM_CLIPBOARD,"","","0")
{begloop}(5)
{keys}{tab}{cmds}
{wx}(50)
{endloop}
{#} ============== find.=.start.of.name ==============
{var_oper}(vCharPoz,"vTitle",STR_FIND,"=","0", "0")
{var_oper}(vNamePoz,"%vCharPoz%+1",CALC_EXPRESSION,"0","","0")
{#} ============== crop.=.characters.before.name ==============
{var_oper}(vCroppedTitle,"vTitle",STR_DELETE,"0","%vNamePoz%", "0")
{#} ============== parse.=.first.name ==============
{var_oper}(vFirstDot,"vCroppedTitle",STR_FIND,".","0", "0")
{var_oper}(vFirstName,"vCroppedTitle",STR_LEFT,"%vFirstDot%","", "0")
{#} ============== crop.=.first.name ==============
{var_oper}(vFirstDot,"%vFirstDot%+1",CALC_EXPRESSION,"0","","0")
{var_oper}(vCroppedFirstSeg,"vCroppedTitle",STR_DELETE,"0","%vFirstDot%", "0")
{#} ============== parse.=.second.name ==============
{var_oper}(vSecondDot,"vCroppedFirstSeg",STR_FIND,".","0", "0")
{var_oper}(vSecondName,"vCroppedFirstSeg",STR_LEFT,"%vSecondDot%","", "0")
{#} ============== crop.=.second.name ==============
{var_oper}(vSecondDot,"%vSecondDot%+1",CALC_EXPRESSION,"0","","0")
{var_oper}(vCroppedSecSeg,"vCroppedFirstSeg",STR_DELETE,"0","%vSecondDot%", "0")
{#} ============== parse.=.third.name ==============
{var_oper}(vThirdDot,"vCroppedSecSeg",STR_FIND,".","0", "0")
{var_oper}(vThirdName,"vCroppedSecSeg",STR_LEFT,"%vThirdDot%","", "0")
{#}
{form_item}("FM1","","LINE","0","")
{form_item}("FM1","","LINE","0","")
{form_item}("FM1","Select name segments to use in the folder name","TEXT","0","")
{form_item}("FM1","%vFirstName%","CHECK","YES","vFirst")
{form_item}("FM1","%vSecondName%","CHECK","YES","vSecond")
{form_item}("FM1","%vThirdName%","CHECK","NO","vThird")
{form_item}("FM1","","LINE","0","")
{form_item}("FM1","Select drive of new location.","TEXT","0","")
{form_item}("FM1"," -::- Drive D -::- ","BUTTON","NO","vDdrive")
{form_item}("FM1"," -::- Drive H -::- ","BUTTON","NO","vHdrive")
{form_item}("FM1"," -::- Drive L -::- ","BUTTON","NO","vLdrive")
{form_item}("FM1","","LINE","0","")
{form_item}("FM1","","LINE","0","")
{form_item}("FM1","","TEXT","0","")
{form_show}("FM1","Video Transporter","S:\icons\#...macro.toolworks\transport..video.transporter.ico",0,500,0,1000,300)
{if}("_vCanceled==1"){exitmacro}{endif}
{#}
{if}("vDdrive==YES")
{varset}("vDrive=d:\","")
{goto}("ACTIVATE")
{endif}
{if}("vHdrive==YES")
{varset}("vDrive=H:\","")
{goto}("ACTIVATE")
{endif}
{if}("vLdrive==YES")
{varset}("vDrive=L:\","")
{endif}
{#}
{label}("ACTIVATE")
{if}("(vFirst==YES)_AND_(vSecond==NO)")
{varset}("vFolderName=%vDrive%%vFirstName%\","")
{endif}
{if}("(vSecond==YES)_AND_(vThird==NO)")
{varset}("vFolderName=%vDrive%%vFirstName%.%vSecondName%\","")
{endif}
{if}("vThird==YES")
{varset}("vFolderName=%vDrive%%vFirstName%.%vSecondName%.%vThirdName%\","")
{endif}
{#}
{varset}("vTitlePathName=%vPath%\%vTitle%","")
{mm}(800,610)
{wx}(250)
{msg}(700,500,"File being moved to:%_vKeyReturn%%vFolderName%","",0,0,0)
{#}
{filemove}("vTitlePathName","%vFolderName%",0,0)
{#} ============== end.macro ==============


--- Using %vVar% As an 'ItemDefValue'

The next undocumented use of the %vVar% value was again in a {form_item}, but this time it is used to create a variable 'ItemDefValue'. Here's the background on the macro(s) that led to this discovery.

The task needed three macros to accomplish it. (The program isn't important and the details of using it will complicate the matter, so I'll use generic terms to describe the function of the macros.) The first macro deleted an old format, then created a new format one size smaller than the previous. The 2nd macro created an item to place in the new format one size smaller than the previous item. The 3rd macro saves the file containing the item in the format using the item type, (vType), the format size, (vFormatSize), and the item size, (vItemSize), in the filename. I originally designed the third macro with a data entry form as the front-end, where the Item Type, Format Size and Item Size were manually entered. A kink in the process is that one or two of the three pieces of data might not change from one file to the next, so re-entering them would be a waste of time.

After discovering the use of the %vVar% in the 'ItemLabel', I thought I'd try using the value in the 'ItemDefValue'. This would allow the user to validate the accuracy of the first two macros, and if accurate, the entire process could be as little as a single button push after starting the macro.

To streamline transition from the 1st to 2nd and 2nd to 3rd macros, I use toolbar buttons to start the macros. I then harvest the cursor location at the start of the 1st macro, then move the cursor to the 2nd macro's toolbar icon on the complation of the 1st macro. I repeat this routine in the 2nd macro.

This technique combined with using the %vVar% in the {form_item} enables the complete three macro process to be as little as four mouse clicks with no manual mouse movement. It cut the total time to create and save a single file by about 50%

Here's the code for harvesting and pre-positioning the mouse cursor:

{#} ============== place.at.top.of.macro ==============
{#} ============== harvest.=.pre-launch.cursor.position ==============
{varset}("vStartX=%_vMousePosX%","")
{varset}("vStartY=%_vMousePosY%","")
{#} ============== end.=.code ==============
{#}
{#} ============== place.at.end.of.macro ==============
{#} ============== position.=.cursor ==============
{var_oper}(vNewY,"%vStartY%+40",CALC_EXPRESSION, "0","","0")
{wx}(150)
{mm}(vStartX,vNewY)
{#} ============== end.=.code ==============


To harvest the three data pieces, I inserted a clipboard copy & {var_oper} command just after the item was defined, formatted, and sized when the data was selected already as part of the process of creating the file. Notice the use of a global application macro variable, (ga_vVar) to allow the variable to be defined in one macro and used in another.


{#} ============== harvest.=.font.size ==============
{keys}{ctrl}c{ctrl}{cmds}
{wx}(100)
{var_oper}(ga_vItemSize,"",GET_TEXT_FROM_CLIPBOARD,"","","0")
{#} ============== end.=.code ==============

Here's how I used the %vVar% as the 'ItemDefValue'. The harvested data shows up as the default value, so if it's accurate, nothing is entered or changed. There are three other options to choose from in this particular process. Those choices have 'BUTTON' {form_item} commands. This combines the final choice with macro activation.

{#} ============== form.segment ==============
{form_item}("FM1","","LINE","0","")
{form_item}("FM1","Enter data if new file, or if harvested data is inaccurate.","TEXT","0","")
{form_item}("FM1","Item Type:","EDIT","%ga_vType%","vTypeInput")
{form_item}("FM1","Format Size:","EDIT","%ga_vFormatSize%","vFormatInput")
{form_item}("FM1","Item Size:","EDIT","%ga_vItemSize%","vItemInput")
{form_item}("FM1","","LINE","0","")
{#} ============== end.=.code ==============


I'll add to this thread as I experiment further with the undocumented use of the %vVar% value. I invite others to add any other undocumented usage to the thread.

Later,

GeoD


Copyright, 2009
IP Logged
Page # 


Powered by ccBoard


Login and share your experience - send messages to forums and add comments to samples, commands and other resources.



Account is free of charge, easy to setup.