横並びボタンのウインドウ作成方法です。
//ウインドウを作成。
window -title "ウインドウ名" -rtf 1;
columnLayout -adjustableColumn true;
//幅100高さ20のボタンを3つ横並びにする。
gridLayout -numberOfColumns 3 -cellWidth 100 -cellHeight 20;
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
setParent..;
showWindow;
ボタンで実行するスクリプトが複数行の為使用できない場合、そのスクリプトをシェルフにドラッグし、その後に以下の場所にあるshelfのmelファイルをワードパットで開くと1行で使用できるスクリプトが確認できるのでそのスクリプトを使用します。
PC>ドキュメント>maya>バージョン数>ja_JP>prefs>shelves(日本語版の場合)
PC>ドキュメント>maya>バージョン数>prefs>shelves(英語版の場合)
window -title "ウインドウ名" -rtf 1;
columnLayout -adjustableColumn true;
gridLayout -numberOfColumns 8 -cellWidth 50 -cellHeight 20;
button -label "cam" -command "//カメラおよびエイム(注視点)作成\ncamera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 \"\";\n //cameraに名前を変更\nrename camera;\n //同階層のエイム(注視点)をcamera_aimに名前を変更\npickWalk -d right;rename camera_aim;\n//上階層を選択しcamera_groupに名前を変更\npickWalk -d up;rename camera_group;";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
button -label "ボタン名" -command "実行するスクリプト";
setParent..;
showWindow;
他のボタンも同じように作成します。
window -title "Softimage_View" -rtf 1;
columnLayout -adjustableColumn true;
gridLayout -numberOfColumns 8 -cellWidth 50 -cellHeight 20;
button -label "cam" -command "//カメラおよびエイム(注視点)作成\ncamera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 \"\";\n //cameraに名前を変更\nrename camera;\n //同階層のエイム(注視点)をcamera_aimに名前を変更\npickWalk -d right;rename camera_aim;\n//上階層を選択しcamera_groupに名前を変更\npickWalk -d up;rename camera_group;";
button -label "viewC" -command "//選択頂点ピボットを登録(複数選択頂点の中心を登録)\nstring $selVEX1[]= `ls -sl`;\nSelectToggleMode;changeSelectMode -object;\nstring $selOBJ1[]= `ls -sl`;\nSelectToggleMode;\nselect -r $selVEX1;\nCreateCluster;\nrename \"CSo_\";\nfloat $C_X = `getAttr CSo_Shape.originX`;\nfloat $C_Y = `getAttr CSo_Shape.originY`;\nfloat $C_Z = `getAttr CSo_Shape.originZ`;\nselect -r CSo_;\ndoDelete;\ndoDelete;\n//頂点位置にcamera_aim(親の名前はcamera_group)を移動します。\nselect -r camera_group|camera_aim ;\nmove -a $C_X $C_Y $C_Z ;\nselect -cl ;";
button -label "SI_v" -command "//プレーンの大きさは1000にします。使用する大きさに合わせて変更してください。\npolyPlane -w 1000 -h 1000 -sx 1 -sy 1 -ax 0 1 0 -cuv 2 -ch 1;\nrename ViewPlane_;\nselect -r camera_group|camera_aim ;\nselect -tgl ViewPlane_ ;\npointConstraint -offset 0 0 0 -weight 1;\nselect -r camera_group|camera ;\nselect -tgl ViewPlane_ ;\naimConstraint -offset 0 0 0 -weight 1 -aimVector 0 1 0 -upVector 0 1 0 -worldUpType \"scene\";\nselect -r ViewPlane_ ;makeLive;\n//ViewPlane_をテンプレート化します。レンダリングとビューからの選択ができなくなります。テンプレート化したオブジェクトを選択する場合はアウトライナを使用します。\nsetAttr \"ViewPlane_Shape.template\" 1;";
button -label "camV" -command "lookThroughModelPanel camera_group|camera modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
button -label "SIon" -command "//ViewPlane_をライブにするスクリプト\nselect -r ViewPlane_ ;makeLive;" ;
button -label "SIoff" -command "select -cl ;makeLive;" ;
button -label "SI_d" -command "//ViewPlane_ を削除し、ライブオブジェクトオフにするスクリプト\n//解除する場合、オブジェクトのライブを解除します。\nselect -r ViewPlane_ ;doDelete; \nselect -cl ;makeLive;" ;
button -label "persp" -command "//ビューパネルをperspビューに戻すスクリプト\nlookThroughModelPanel persp modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
setParent..;
showWindow;
ボタン説明
cam
camera作成、エイム(注視点名)camera_aim(親の名前はcamera_group)
★2回以上クリックするとcamera_group1以降追加で作成されますがcamera_group以外は使用しませんので
削除してください。
viewC
選択頂点中心位置にカメラのエイム(注視点)に移動
SI_v
ポリゴン作成、追加時にSoftimageの様に作成します。camera方向に向けたポリゴン板を作成、それをライブにし、スナップさせる。★不必要なポリゴン板が作成されることがあります。その場合は選択し、削除してください。
camV
cameraにビューパネルを切り替える。
SIon
ポリゴン板をライブにし、スナップさせる。
SIoff
ライブを解除する。
SI_d
ポリゴン板を削除、ライブを解除する。
persp
perspにビューパネルを切り替える。
以下のスクリプトは、SI_vチェックボックスを付けて、SIon、SIoff、SI_dの3つのボタンを削除しました。
checkBox -label "SI_v" -onCommand "チェック ボックスがオン時に実行されるコマンド" -offCommand "チェック ボックスがオフ時に実行されるコマンド"
SI_vのチェックオンは
ポリゴン作成、追加時にSoftimageの様に作成します。camera方向に向けたポリゴン板を作成、それをライブにし、スナップさせる。
チェックオフはポリゴン板を削除、ライブを解除する。※ポリゴン作成中にチェックをオフにすると作成中のポリゴンが消えます。
Yキーを押した後であればオフにしても問題ありません。
作成中戻す(Undo)キーはBackSpaceキー、一旦完了、連続ツール使用にキーはYキー、ツールの解除はQキー
window -title "Softimage_View" -rtf 1;
columnLayout -adjustableColumn true;
gridLayout -numberOfColumns 5 -cellWidth 50 -cellHeight 20;
button -label "cam" -command "//カメラおよびエイム(注視点)作成\ncamera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 \"\";\n //cameraに名前を変更\nrename camera;\n //同階層のエイム(注視点)をcamera_aimに名前を変更\npickWalk -d right;rename camera_aim;\n//上階層を選択しcamera_groupに名前を変更\npickWalk -d up;rename camera_group;";
button -label "viewC" -command "//選択頂点ピボットを登録(複数選択頂点の中心を登録)\nstring $selVEX1[]= `ls -sl`;\nSelectToggleMode;changeSelectMode -object;\nstring $selOBJ1[]= `ls -sl`;\nSelectToggleMode;\nselect -r $selVEX1;\nCreateCluster;\nrename \"CSo_\";\nfloat $C_X = `getAttr CSo_Shape.originX`;\nfloat $C_Y = `getAttr CSo_Shape.originY`;\nfloat $C_Z = `getAttr CSo_Shape.originZ`;\nselect -r CSo_;\ndoDelete;\ndoDelete;\n//頂点位置にcamera_aim(親の名前はcamera_group)を移動します。\nselect -r camera_group|camera_aim ;\nmove -a $C_X $C_Y $C_Z ;\nselect -cl ;";
checkBox -label "SI_v" -onCommand "//プレーンの大きさは1000にします。使用する大きさに合わせて変更してください。\npolyPlane -w 1000 -h 1000 -sx 1 -sy 1 -ax 0 1 0 -cuv 2 -ch 1;\nrename ViewPlane_;\nselect -r camera_group|camera_aim ;\nselect -tgl ViewPlane_ ;\npointConstraint -offset 0 0 0 -weight 1;\nselect -r camera_group|camera ;\nselect -tgl ViewPlane_ ;\naimConstraint -offset 0 0 0 -weight 1 -aimVector 0 1 0 -upVector 0 1 0 -worldUpType \"scene\";\nselect -r ViewPlane_ ;makeLive;\n//ViewPlane_をテンプレート化します。レンダリングとビューからの選択ができなくなります。テンプレート化したオブジェクトを選択する場合はアウトライナを使用します。\nsetAttr \"ViewPlane_Shape.template\" 1;" -offCommand "//ViewPlane_ を削除し、ライブオブジェクトオフにするスクリプト\n//解除する場合、オブジェクトのライブを解除します。\nselect -r ViewPlane_ ;doDelete; \nselect -cl ;makeLive;" ;
button -label "camV" -command "lookThroughModelPanel camera_group|camera modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
button -label "persp" -command "//ビューパネルをperspビューに戻すスクリプト\nlookThroughModelPanel persp modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
setParent..;
showWindow;
更に修正しました。
ポリゴン作成、追加のみで使用するので
SI_vをSI_Nに修正
SI_Nをチェックすると
camera方向に向けたポリゴン板を作成、それをライブにし、スナップさせてポリゴン作成ツールが起動します。
★不必要なポリゴン板が作成されることがあります。その場合は選択し、削除してください。
チェックオフにすると、ポリゴン板を削除、ライブを解除する。
ADDpolyボタン追加
ADDpolyをクリックするとポリゴン追加ツールが起動します。
perspVにperspをボタン名を変更
perspにビューパネルを切り替える。
以下スクリプト
window -title "Softimage_View" -rtf 1;
columnLayout -adjustableColumn true;
gridLayout -numberOfColumns 6 -cellWidth 50 -cellHeight 20;
button -label "cam" -command "//カメラおよびエイム(注視点)作成\ncamera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 \"\";\n //cameraに名前を変更\nrename camera;\n //同階層のエイム(注視点)をcamera_aimに名前を変更\npickWalk -d right;rename camera_aim;\n//上階層を選択しcamera_groupに名前を変更\npickWalk -d up;rename camera_group;";
button -label "viewC" -command "//選択頂点ピボットを登録(複数選択頂点の中心を登録)\nstring $selVEX1[]= `ls -sl`;\nSelectToggleMode;changeSelectMode -object;\nstring $selOBJ1[]= `ls -sl`;\nSelectToggleMode;\nselect -r $selVEX1;\nCreateCluster;\nrename \"CSo_\";\nfloat $C_X = `getAttr CSo_Shape.originX`;\nfloat $C_Y = `getAttr CSo_Shape.originY`;\nfloat $C_Z = `getAttr CSo_Shape.originZ`;\nselect -r CSo_;\ndoDelete;\ndoDelete;\n//頂点位置にcamera_aim(親の名前はcamera_group)を移動します。\nselect -r camera_group|camera_aim ;\nmove -a $C_X $C_Y $C_Z ;\nselect -cl ;";
checkBox -label "SI_N" -onCommand "//プレーンの大きさは1000にします。使用する大きさに合わせて変更してください。\npolyPlane -w 1000 -h 1000 -sx 1 -sy 1 -ax 0 1 0 -cuv 2 -ch 1;\nrename ViewPlane_;\nselect -r camera_group|camera_aim ;\nselect -tgl ViewPlane_ ;\npointConstraint -offset 0 0 0 -weight 1;\nselect -r camera_group|camera ;\nselect -tgl ViewPlane_ ;\naimConstraint -offset 0 0 0 -weight 1 -aimVector 0 1 0 -upVector 0 1 0 -worldUpType \"scene\";\nselect -r ViewPlane_ ;makeLive;\n//ViewPlane_をテンプレート化します。レンダリングとビューからの選択ができなくなります。テンプレート化したオブジェクトを選択する場合はアウトライナを使用します。\nsetAttr \"ViewPlane_Shape.template\" 1;\nsetToolTo polyCreateFacetContext ; polyCreateFacetCtx -e -pc `optionVar -q polyKeepFacetsPlanar` polyCreateFacetContext;\n" -offCommand "//解除する場合、オブジェクトのライブを解除します。\nselect -r ViewPlane_ ;doDelete; \nselect -cl ;makeLive;\nSelectToolOptionsMarkingMenu;\ndR_SelectToolMarkingMenuPopDown;";
button -label "ADDpoly" -command "setToolTo polyAppendFacetContext ; polyAppendFacetCtx -e -pc `optionVar -q polyKeepFacetsPlanar` polyAppendFacetContext" ;
button -label "camV" -command "lookThroughModelPanel camera_group|camera modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
button -label "perspV" -command "//ビューパネルをperspビューに戻すスクリプト\nlookThroughModelPanel persp modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
setParent..;
showWindow;
更にIF文を入れて修正した以下のスクリプト
window -title "Softimage_View" -rtf 1;
columnLayout -adjustableColumn true;
gridLayout -numberOfColumns 6 -cellWidth 50 -cellHeight 20;
button -label "cam" -command "//もしcamera_groupがなかった場合、太字スクリプトを実行する。\nint $OBJ_=`objExists \"camera_group\"`;\nif($OBJ_== 0)\n{\n//カメラおよびエイム(注視点)作成\ncamera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 \"\";\n //cameraに名前を変更\nrename camera;\n //同階層のエイム(注視点)をcamera_aimに名前を変更\npickWalk -d right;rename camera_aim;\n//上階層を選択しcamera_groupに名前を変更\npickWalk -d up;rename camera_group;\n}";
button -label "viewC" -command "//選択頂点ピボットを登録(複数選択頂点の中心を登録)\nstring $selVEX1[]= `ls -sl`;\nSelectToggleMode;changeSelectMode -object;\nstring $selOBJ1[]= `ls -sl`;\nSelectToggleMode;\nselect -r $selVEX1;\nCreateCluster;\nrename \"CSo_\";\nfloat $C_X = `getAttr CSo_Shape.originX`;\nfloat $C_Y = `getAttr CSo_Shape.originY`;\nfloat $C_Z = `getAttr CSo_Shape.originZ`;\nselect -r CSo_;\ndoDelete;\ndoDelete;\n//頂点位置にcamera_aim(親の名前はcamera_group)を移動します。\nselect -r camera_group|camera_aim ;\nmove -a $C_X $C_Y $C_Z ;\nselect -cl ;";
checkBox -label "SI_N" -onCommand "int $OBJ_=`objExists \"ViewPlane_\"`;\nif($OBJ_== 0)\n{\n//プレーンの大きさは1000にします。使用する大きさに合わせて変更してください。\npolyPlane -w 1000 -h 1000 -sx 1 -sy 1 -ax 0 1 0 -cuv 2 -ch 1;\nrename ViewPlane_;\nselect -r camera_group|camera_aim ;\nselect -tgl ViewPlane_ ;\npointConstraint -offset 0 0 0 -weight 1;\nselect -r camera_group|camera ;\nselect -tgl ViewPlane_ ;\naimConstraint -offset 0 0 0 -weight 1 -aimVector 0 1 0 -upVector 0 1 0 -worldUpType \"scene\";\nselect -r ViewPlane_ ;makeLive;\n//ViewPlane_をテンプレート化します。レンダリングとビューからの選択ができなくなります。テンプレート化したオブジェクトを選択する場合はアウトライナを使用します。\n//選択ツール起動によるツールの解除\nSelectToolOptionsMarkingMenuPopDown;\nMarkingMenuPopDown;\nsetAttr \"ViewPlane_Shape.template\" 1;\n//ポリゴン作成ツールを起動します。\nsetToolTo polyCreateFacetContext ; polyCreateFacetCtx -e -pc `optionVar -q polyKeepFacetsPlanar` polyCreateFacetContext;\n}" -offCommand "//解除する場合、オブジェクトのライブを解除します。\nselect -r ViewPlane_ ;doDelete; \nselect -cl ;makeLive;\nSelectToolOptionsMarkingMenu;\ndR_SelectToolMarkingMenuPopDown;";
button -label "ADDpoly" -command "setToolTo polyAppendFacetContext ; polyAppendFacetCtx -e -pc `optionVar -q polyKeepFacetsPlanar` polyAppendFacetContext" ;
button -label "camV" -command "lookThroughModelPanel camera_group|camera modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
button -label "perspV" -command "//ビューパネルをperspビューに戻すスクリプト\nlookThroughModelPanel persp modelPanel4;\neditMenuUpdate MayaWindow|mainEditMenu;";
setParent..;
showWindow;
★記述時のスクリプトとshelfデータのスクリプトの違い
▼記述時のスクリプト
//もしcamera_groupがなかった場合、太字スクリプトを実行する。
int $OBJ_=`objExists "camera_group"`;
if($OBJ_== 0)
{
//カメラおよびエイム(注視点)作成
camera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 "";
//cameraに名前を変更
rename camera;
//同階層のエイム(注視点)をcamera_aimに名前を変更
pickWalk -d right;rename camera_aim;
//上階層を選択しcamera_groupに名前を変更
pickWalk -d up;rename camera_group;
}
▼shelfデータ
"//もしcamera_groupがなかった場合、太字スクリプトを実行する。\nint $OBJ_=`objExists \"camera_group\"`;\nif($OBJ_== 0)\n{\n//カメラおよびエイム(注視点)作成\ncamera -centerOfInterest 5 -focalLength 35 -lensSqueezeRatio 1 -cameraScale 1 -horizontalFilmAperture 1.41732 -horizontalFilmOffset 0 -verticalFilmAperture 0.94488 -verticalFilmOffset 0 -filmFit Fill -overscan 1 -motionBlur 0 -shutterAngle 144 -nearClipPlane 0.1 -farClipPlane 10000 -orthographic 0 -orthographicWidth 30 -panZoomEnabled 0 -horizontalPan 0 -verticalPan 0 -zoom 1; objectMoveCommand; cameraMakeNode 2 \"\";\n //cameraに名前を変更\nrename camera;\n //同階層のエイム(注視点)をcamera_aimに名前を変更\npickWalk -d right;rename camera_aim;\n//上階層を選択しcamera_groupに名前を変更\npickWalk -d up;rename camera_group;\n}";
違い
\n ←行変更
\"camera_group\" ←"camera_group"