How to get the path of a drag & dropped file in Maya's MEL - maya

Drag & drop a Maya MEL file into Maya and the contents of the MEL file will be executed.
Is there a way to get the absolute path of the file when dragging and dropping?

Hopefully this can get you started
test.mel:
global proc FindMe() {}
print("whatIs result -> " + `whatIs "FindMe"`);
Drag-dropping the file into Maya produces the following output:
> source "C:/Users/itypewithmyhands/Desktop/test.mel";
> whatIs result -> Mel procedure found in: C:/Users/itypewithmyhands/Desktop/test.mel
Interesting points to note:
Drag-drop seems to simply produce a source <file> statement, which means you'll have to do some internal magic unknown to me in order to know if the file was actually dropped, or simply sourced
The proc you search for has to be marked global
You need to regex (or similar) the result of the whatIs command to get the path you're after. Something like .*found in: (.+?\.mel) seems to work well enough. Example

Related

What is the format for the Elements_with_Changed_Element_Type report in ClearCase from the command line?

I cannot seem to find any DOCs on running this report. Here us what I typed in and nothing returns. The report returns 2000+ lines when run through the gui however it takes ten minutes to pull up all of the labels.
C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\reports\scripts\Elements>ccperl Elements_with_Changed_Element_Type.prl LOOKIN="J:\nfloyd_jup6\jupnms\" LABEL="
labelabc" LABEL="labeldef"
Without the sources of "C:\Program Files\Rational\ClearCase\reports\scripts\Elements\Elements_with_Changed_Element_Type.prl", it is hard to say.
Looking at "Additional examples of the cleartool find command", it could find changed elements between labels and apply other criteria.
This 2008 thread does mention:
the scripts are written in perl and are located in %CLEARCASEHOME%\reports\scripts...
Just run 'ccperl %CLEARCASEHOME%\reports\scripts\...\script-name.prl' arg-list. You'll need to take a look at the script itself to identify / check syntax for arg-list; for paths it is something like "LOOKIN=path" (from memory). Also, specify an absolute path (and in lowercase again from memory) as the scripts searches $0 for '/scripts/' to find the common include files.
For instance:
apparently it doesn't like a space between the various arguments... here is the command I used.
C:\Program Files\Rational\ClearCase\reports\scripts>
ccperl "c:\program files\rational\clearcase\reports\scripts\Elements\labels\versions_with_labels.prl" LOOKIN=\"m:\cfdcnn_int\MAESTRO_SYS\cfdcnn\\\";LABEL=\"cfdcnn_cfdcnn_integratoin_9_24_07_Dev_01\"
This script is pretty straightforward. It does a cleartool find -type f, and for every file that exists (since you can run this in a snapshot view containing unloaded elements), compares the current element type with the type that would be assigned by the current magic file.
The label options aren't needed, only LOOKIN:
C:\Users\bcowan>ccperl "\Program Files (x86)\IBM\RationalSDLC\ClearCase\reports\scripts\Elements\Elements_with_Changed_Element_Type.prl" -i
description : "Elements with Changed Element Type"
id : 2021
helpfile :
parameters : LOOKIN
rightclick : Properties_of_Element(single) sep Version_Tree(single) History(single) sep Change_Element_Type
fields : "Element Path"(element_pn, sort 3, rightclick) "Element Type"(eltype) "Element's default.magic Type"(eltype, sort 2) "Element Types Different"(yes_no, sort 1)
So, when I run the command:
C:\Users\bcowan>ccperl "\Program Files (x86)\IBM\RationalSDLC\ClearCase\reports\scripts\Elements\Elements_with_Changed_Element_Type.prl" LOOKIN=\"v:\uncview\mkvobtest\p7zip\";
I get this:
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\Asm\x64\7zCrcT8U.asm;text_file;text_file;no
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\Asm\x86\7zCrcT8U.asm;text_file;text_file;no
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\C\7zBuf.h;text_file;text_file;no
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\C\7zBuf2.c;text_file;text_file;no
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\C\7zCrc.c;text_file;text_file;no
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\C\7zCrc.h;text_file;text_file;no
v:\uncview\mkvobtest\p7zip\p7zip_9.20.1\C\7zCrcOpt.c;text_file;text_file;no
...

Automatisation, Load .prg file, run it with pre-defined variable

The idea is that in one folder there are two files
test.csv
test.prg
I would like to run with .bat file (or .vbs) the file test.prg with variable "2510".
It will automatically load in Visual Fox Pro (here I do not know how to run script automatically with out physically click the exclamation mark) and visual fox pro should use variable from .bat/.vbs file as 2510.
1) Open test.prg
2) Load VFP
3) Use pre defined variable from .bat/.vbs
4) Run script (automatically)
5) close VFP
Because this is daily jobs, and I'm trying to simplify as much as possible (currently I know only how to simplify by using cmd/.bat and vbs)
If I understood you right, you want to run a prg file with changing parameters and you want to change the parameter in the calling .bat or .vbs file. If it is what you wanted to do, then you could simply have the bat file content like:
cd "c:\My Folder"
"c:\Program Files (x86)\Microsoft Visual Foxpro 9\vfp9.exe" test.prg 2510
and your prg would be run with that parameter. Keep in mind that parameters passed from command line is always of character data type.
However, there is an easier way. The way you do it, you would edit the .BAT file, save it and then doubleclick to execute. You might create a VFP executable instead, in command window (assuming test.prg is in c:\My Folder'):
set default to ('c:\My Folder')
build project MyTest from 'test.prg'
build exe MyTest from 'MyTest.pjx'
and you would have MyTest.exe in that folder. Your BAT file content would then be:
cd "c:\My Folder"
MyTest 2510
It is still to cumbersome. You need to edit the .BAT file, change parameter, save and doubleclick it. Make it much simpler:
In your test.prg, instead of getting a parameter from command line, ask the parameter value and do the process! That totally removes the need for a BAT file. Then you simply create a shortcut on your desktop. Whenever you doubleclick that shortcut, it would ask for the parameter and then do processing with that parameter value and quit. The content of such a test.prg would look like:
_screen.Visible = .T.
LOCAL cInput
cInput = INPUTBOX("What is parameter value?", "Get parameter value", "2510", 5000, '', 'Cancelled')
DO case
CASE m.cInput == ''
? 'Input timed out'
CASE m.cInput == 'Cancelled'
? 'Cancelled'
CASE m.cInput == '0' Or VAL(m.cInput) != 0
Process( VAL(m.cInput) )
OTHERWISE
? 'Parameter is not numeric'
ENDCASE
QUIT
PROCEDURE Process(tnparameter)
? 'Processing with parameter =', m.tnParameter
Endproc
Also, instead of an inputbox() which returns a character value as command line parameters do, you might get the value(s) via a form with their intended types (ie: A datetimepicker on a form getting date).
It is really unclear what you are trying to do. However, from VFP, I created a simple project and program that might help you.
Start VFP. In the command window type
create project MyTest [enter]
click on the Code tab and then click new. Paste the following code snippet
LPARAMETERS DOSParm1, DOSParm2, DOSParm3, DOSParm4
MESSAGEBOX( "Parm1: " + TRANSFORM( DOSParm1 ) + CHR(13)+CHR(10);
+ "Parm2: " + TRANSFORM( DOSParm2 ) + CHR(13)+CHR(10);
+ "Parm3: " + TRANSFORM( DOSParm3 ) + CHR(13)+CHR(10);
+ "Parm4: " + TRANSFORM( DOSParm4 ) + CHR(13)+CHR(10) )
RETURN
Save the program as MyTest.prg, then click on build for the project to create an executable. Now you have a simple EXE file that accepts up to 4 parameters from the dos command or other methods (vbs). You can change the actual VFP to act on whatever variables you need, but I just have them as messagebox output display. If no parameters are provided, the default values would be logical .F. (false)
To test from a DOS prompt, you can do something like
MyTest oneParm anotherParm 3rd last
and you will get the message box displaying these 4 parameter strings.
If you skip parameters, no problem.
MyTest Only TwoParms
Again, the code can be changed to do whatever you need with your "2510" variable reference and act accordingly.

The system cannot find the file specified

The file is inside the directory where the software is. I am trying to add the text file to the memo box.
procedure TForm4.FormCreate(Sender: TObject);
var
dir : string;
begin
Form4.Caption:='Abateri instrumente';
dir := GetCurrentDir;
Memo1.Lines.LoadFromFile(dir+'\abateri.txt');
end;
In your specific situation, you should load the file with the code
Memo1.Lines.LoadFromFile(dir+'\abateri.txt.txt');
This is because in the below screenshot that you provided, the extension of the Project3 file is hidden, which loads to the conclusion that the option to hide known file extensions is enabled. Yet the one for the abateri.txt file is shown, which can only lead to the often seen double extension mistake.
Either rename your file and remove the redundant part (the first .txt, which is preferred) or use the double extension in your code.
I would also suggest disabling that option in Windows Explorer:
Tools > Folder Options > View > Uncheck the "Hide extensions of known file types"
In addition to the above, you should always build up paths with the TPath.Combine function call to ensure that they are correct.
You can see the documentation of it here
The file is inside the directory where the software is.
In that case, looking in the working directory is the wrong approach. There's no reason why the working directory should be directory where your executable resides. You need to use:
Dir := ExtractFilePath(ParamStr(0)); // the directory where the executable resides
TPath.Combine(Dir, FileName); // TPath is from the System.IOUtils unit
Of course, your other problem is that you got your file name wrong. The file is actually named abateri.txt.txt.

How do I reference a bibtex file from directory other than current project?

What I am trying to do is create a "Master" bibtex bibliography (organized via JabRef) in a convenient directory so that I do not need to copy new references from every project I work on into my master database. The issue I am coming up against is that while I can reference another file easily enough (e.g. for STATA regression table output), even if it is not in the same directory, the bibliography does not want to cooperate.
For the purposes of this example I have created a dummy directory in
My Documents/Course/Paper.
The Tex file in under
My Documents/Course/Paper/MasterTexFile.tex
and the example Tex file referenced in the code (simply called Text) is under
My Documents/Course/Text.tex.
My ideal is to have the bibliography in a more general directory altogether, but I have placed it just above the working tex file for illustrative purposes. Document code is as follows:
\documentclass[12pt,titlepage]{article}
\usepackage[round,longnamesfirst]{natbib}
\usepackage{setspace}
\doublespacing
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{
pdftitle={TITLE},
pdfauthor={AUTHOR},
pdfsubject={SUBJECT},
pdfkeywords={KEYWORD} {KEYWORD} {KEYWORD},
colorlinks=true,
linkcolor=blue,
citecolor=blue,
filecolor=magenta,
urlcolor=blue
}
\begin{document}
\title{TITLE}
\date{\today}
\author{AUTHOR\\STUDENT NUMBER}
\maketitle
%Begin Document Text
\pagestyle{headings}
\section{Introduction}
\cite{Shapiro2015} %Example citation from my database
\input{../Text} %this comes from the directory ABOVE that of the current file.
%\input{../00 Master Bibliography} %This was inputted using the user interface (Texmaker). I have it here just to demonstrate that it is truly in the directory.
%References
\newpage
\bibliographystyle{plainnat}
\bibliography{../00 Master Bibliography}
%\bibliography{00_Master_Bibliography} %If the database is in the directory, everything works fine.
\end{document}
The document compiles (I use PdfLatex, BibTex, PdfLatex x2, sequentially), and properly references the Text document (which just contains the word "Text"), but I get the following errors:
Package natbib Warning: Citation `Shapiro2015' on page 1 undefined on input line 40.
Package natbib Warning: Empty `thebibliography' environment on input line 8.
Package natbib Warning: There were undefined citations.
Note: I have removed some lines of comments for brevity, so if you copy this into your editor the line numbers will be different.
These are to be expected if the database wasn't found, but I have no idea why it wouldn't be found. Does it have anything to do with natbib? Is it a feature of the natbib package that it cannot reference a database from any directory other than that of the current file? This seems unlikely.
Any help would be greatly appreciated!
Well, turns our there was a simple solution. I am not sure whether it is the '00' I had before the bibliography name (I added '00' to make sure it was at the top of the list of files in its folder), or the space between these and the word 'Bibliography', but changing the name of the file to simply `Bibliography' worked.

How can I load a Maya .MA file from MEL when it has an unresolved reference?

I am trying to use a MEL script to load ANIMATION.MA file that references CHARACTER_RIG.MA. The CHARACTER_RIG.MA and ANIMATION.MA files are produced by someone else and supplied to me. The ANIMATION.MA is looking for N:/Project/Maya//char/character/CHARACTER_RIG.MA
If I open ANIMATION.MA from Maya, or use the equivalent MEL command I always get prompted with:
"Reference File Not Found"
Reference File Not Found: N:/Project/Maya//char/character/CHARACTER_RIG.MA.
[Abort File Read] [Skip] [Browse...] [Retry]
If I tap browse, and select the CHARACTER_RIG.MA then it opens perfectly. I can see it created a reference in the Reference Editor that has the Unresolved Path (N:/...) , the Resolved Path (/my/path) and the namespace and the namespaceRN.
My question is, how do I do the equivalent of the "Browse..." from MEL? I tried pre-creating a reference, but it doesn't let me set the unresolved path, so when I load the ANIMATION.MA it keeps prompting in MAYA.
file -f -options "v=0" -typ "mayaAscii" -o "/Source/project/assets/anims/ANIMATION.MA"
If you know the directory where the file is, then you can use the dirmap command. The command dirmap allows you to remap directory structures if your disk configuration changes. So in this case it would look like:
dirmap -en true;
dirmap -m "N:/Project/Maya//char/character" "/my/path";
Possibly more manageable if you have lots of mappings to do especially when moving form a windows machine to a *nix one. However it is much more useful to define your project structure because then things just work when you move, tough this may not be the best of choice for shared assets.
I ended up finding several solutions:
Rename the RIG.MA file to match the filename in ANIM.MA (they were different in my case) and put it in one of the search or project folders that MAYA uses and it will automatically find it.
or
Programatically through code (or manually) edit the ANIM.MA file to remap the file/folder of the RIG.MA to where you want to load it from. Note: You
also need to remap any other files, such as textures. I did this with
perl -pi -e 's/\Qold-path\E/\Qnew-path\E/g' ANIMATION.MA
HTH someone else.
Quick and easy, File, Project, Set and select the folder where meshes or whatever it is.

Resources