View Full Version : storing textfieldgrp
mikefeil 01-18-2005, 05:00 AM Hi,
I'm currently doing a project in mel at college, and I'm having a bit of trouble trying to store something (using the textfieldgrp) then taking what is stored and using it in a procedure. Sorry we only got a week's worth of lessons on Mel, so I have been trying really hard to get my head around it.
Anyway, this the basic jist of what I want to do.
global proc ptools ()
{
global string $inputName =""
window;
columnLayout -w 354 -adjustableColumn true -bgc 1 1 1;
$inputName = `textFieldGrp -w 354 -adj 1 -cal 1 left -bgc 1 1 1 -label "Name"`;
button -l "Make HUD" -c nameHud;
}
global proc nameHud ()
{
headsUpDisplay
-section 8
-block 0
-blockSize "medium"
-dfs "large"
-command "print $InputName"
-atr
HUDFrameCount;
}
everything could be totaly stuffed here, but yeah. I hope you guys can kinda understand what I want to do here.
thanx
|
|
Blue Bird
01-18-2005, 10:13 AM
I took some time and rewrote your script. If there is any problem or anything you wish to know more about this script, let me know.
Bird
P.S. Trying to learn MEL in just one week is just crazy.
global proc ptools ()
{
global string $ctrl;
window;
columnLayout -w 354 -adjustableColumn true -bgc 1 1 1;
$ctrl = `textFieldGrp -w 354 -adj 1 -cal 1 left -bgc 1 1 1 -label "Name"`;
button -l "Make HUD" -c "nameHud ($ctrl)";
showWindow;
}
global proc nameHud (string $ctrl)
{
if (`headsUpDisplay -exists HUDFrameCount`)
headsUpDisplay -remove HUDFrameCount;
headsUpDisplay
-section 8
-block 0
-blockSize "medium"
-lfs "large"
-label `textFieldGrp -q -text $ctrl`
HUDFrameCount;
}
mikefeil
01-18-2005, 12:08 PM
thankyou so much. That worked great for what I want to do. I will probably have some more questions soon about some stuff, but yeah thanks heaps.
all I can say is thank god for the f1 key for all of this.
mikefeil
01-18-2005, 01:42 PM
next (probably simple) question
why do I get an error when I try to do something like this
global proc nameHud (string $inputName)
{
if (`headsUpDisplay -exists HUDArtistName`)
headsUpDisplay -remove HUDArtistName;
headsUpDisplay
-section 5
-block 5
-blockSize "small"
-label "Name"
-command `textFieldGrp -q -text $inputName`
-atr
HUDArtistName;
}
i get an error of
// Error: Cannot find procedure "whatever I typed in the textfieldGrp". //
and the hud says Name (No Data)
I have probably not done it right or something
ps. I relise that when that -command is executed it will result in what will look like a procedure since we are using -command instead of -label. So I think the solution is putting something like
-command print (`textFieldGrp -q -text $inputName`)
but yeah that didnt work. I guess its down to my poor knowledge.
goleafsgo
01-18-2005, 02:04 PM
Your problem is that the $inputName variable which you use in the -command field is only visible within a proc that you have declared it in. What you need to do is instead call a proc which then declares the global string and then uses it.
So call something like this in the -command field...
global proc PrintMyText()
{
// So in the proc that creates the textFieldGrp you stuff the name of the control
// in this variable so that later on you can edit/query it.
global string $inputName;
print (`textFieldGrp -q -text $inputName`);
}
mikefeil
01-18-2005, 03:02 PM
okay so I now have this
global proc PrintInputName()
{
global string $inputName;
print (`textFieldGrp -q -text $inputName`);
}
which ultimately plugs into this
headsUpDisplay
-section 5
-block 7
-blockSize "small"
-dfs "small"
-label "Name"
-command PrintInputName
-atr
HUDArtistName;
so I type what I want into textfieldGrp e.g. mike then click a button which turns on the heads up display procedure above, however it prints the name to my scipt editor and not to the HUD?
i dont get it.
Blue Bird
01-18-2005, 10:37 PM
global proc ptools ()
{
global string $ctrl;
window;
columnLayout -w 354 -adjustableColumn true -bgc 1 1 1;
$ctrl = `textFieldGrp -w 354 -adj 1 -cal 1 left -bgc 1 1 1 -label "Name"`;
button -l "Make HUD" -c "nameHud ($ctrl)";
showWindow;
}
global proc nameHud (string $ctrl)
{
if (`headsUpDisplay -exists HUDFrameCount`)
headsUpDisplay -remove HUDFrameCount;
global string $inputName;
$inputName = `textFieldGrp -q -text $ctrl`;
headsUpDisplay
-section 8
-block 0
-label "Name:"
-dataFontSize "large"
-command getArtistName
-attachToRefresh
HUDFrameCount;
}
global proc string getArtistName ()
{
global string $inputName;
return $inputName;
}
The -command flag will attempt to continuously update the HUD by calling (in this case) getArtistName, so getArtistName needs to return the value of $inputName everytime it is called, hence getArtistName is declared to return a string. Generally I like to be efficient, that's why I changed your original script from using the -command flag to the -label flag so I don't have to write an extra global proc (in this case getArtistName) just to get the value of a string and then return it. The other advantage of using the -label flag is that I've manage to avoid using an extra global variable (together with an extra global proc), in this case $inputName, that I need to keep track of, and this is a real advantage because global variables gives me headaches when they conflict with existing names, get overwritten or changed elsewhere. Make sense?
But anyway, I updated the script to reflect some of your new ideas so that you can compare and contrast with my original script and see how I've made the changes.
Bird
mikefeil
01-19-2005, 02:14 PM
Well guys I managed to get my little script done. I have taken a list screen shot of it in use. There are a couple of little things that are weird (like the square things on the date, and also the date not showing up on osx?)
Anyway,
I think its a little nifty tool so I'll probably throw it on highend after monday (due date of project)
Thanx for all your help
brubin
01-19-2005, 02:58 PM
Well guys I managed to get my little script done. I have taken a list screen shot of it in use. There are a couple of little things that are weird (like the square things on the date, and also the date not showing up on osx?)
the "thingi" on the date is probably a whitespace, LF or CR character, so i gather you use a string $currDate = `system( "date /t")`; under windows?
if so, try
string $currDate = $currDate = `match "^[^(\r\n)]*" $currDate`;
as the next line.
on osx that code will probably be different, and to my dismay i know close to nothing about it, sorry!
anyway, HIH
s.
mikefeil
01-29-2005, 11:36 PM
Well guys, I finally managed to find some time to upload the script to highend. I gave a shout too all that helped.
http://www.highend3d.com/maya/mel/?section=project&sort=dt_modified+desc
Thankyou all :D
btw its the Ptools v.10 script.
CGTalk Moderation
01-30-2006, 12:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.