MAXScript には多くの組み込み関数があり、3ds Max でアクセスできるクラスについての情報を表示することができます。これらの関数は、3ds Max の中心的なクラスをオンラインで参照する場合に便利です。また、サード パーティ製のプラグイン クラス内でアクセス可能なプロパティを確認するには、これらの関数を使用する必要があります。
{toc}
apropos()
、showClass()
、showProperties()
の各メソッドは、入力としてパターン文字列を取ります。パターン文字列には、次を含めることができます。
*
: 任意の文字シーケンスに一致(0 以上)?
: 任意の 1 文字に一致[SET]
: セット内の任意の文字に一致[!SET]
または [^SET]
: セット内に存在しない文字に一致セットは、文字、またはハイフンで繋がれた範囲の文字(「0-9」や「A-D」など)で構成されます。セットは大文字と小文字が区別されます。また、「A-z」は有効ですが、「a-Z」(大文字が小文字より小さい)は無効です。
特殊文字は、バックスラッシュ「\
」を前に置くことでエスケープできます(リテラル文字として扱われます)。「特殊文字」には次の文字があります: []*?!^-\
apropos()
関数は、名前のパターンと内容のクラスでグローバル変数に関する情報を検索し、出力します。
この関数の形式は次のとおりです。
apropos <pattern_string> [ implicitWild:true ] [ to:<stream> ]
<pattern_string>
引数は、グローバル変数の検索に使用するワイルド カードを含む文字列です。
形式は次のとおりです。
<variable_name_pattern_string[:class_name_pattern_string]>
グローバル変数名のパターンは、オプションの「:」にクラス名パターンを続けます。
オプションのクラス名パターンを指定すると、指定されたクラスの値を含むグローバル変数だけが出力されます。
apropos()
関数は、パターンの最初と最後にワイルドカード「*」があるとみなします。つまり、指定されたパターンを「含む」マッチングを実行します。ただし、implicitWild:false
が指定されている場合は「*」があるとはみなされません。詳細については、上記の「パターン文字列」を参照してください。
出力結果は、グローバル変数名、その後にシステム変数または const (変更不可)変数の区別と現在の値のクラスが()内に示され、最後に値が表示されます。
例:
apropos "light" -- any variables with 'light' in the variable name
apropos ":float" -- any variables containing float values
apropos "" to:f -- dump all variables to the stream f
apropos "controller:super" -- the list of controller superclasses
apropos "foo:control" -- any variables whose name contains 'foo'
-- and that contain controller classes
> apropos "[x-z]*" implicitWild:false -- any classes or functions that start with x, y, or z
最初の例の出力例を次に示します。
lights (const ObjectSet): $lights
lightLevel (system Float): 1.0
Sunlight (const MAXClass): Sunlight
Directionallight (const MAXClass): Directionallight
lightLevelController (system Control): Controller:Bezier_Float
light (const MAXSuperClass): light
NewLight (const Primitive): NewLight()
lightTintColor (system Color): (color 255 255 255)
Volume_Light (const MAXClass): Volume_Light
lightTintColorController (system Control): Controller:Bezier_Color
gw.getMaxLights (Primitive): getMaxLights()
gw.setLight (Primitive): setLight()
スクリプトを簡単に記述および使用できるようにするために、ScriptTool 関数の Help が追加されました。apropos のエイリアスです。
Help "Box" と入力すると、BOX という名前の付いたすべてのコマンドが表示されます。
showClass()
関数は、指定された 1 つまたは複数の 3ds Max クラスについての情報を出力します。この関数の形式は次のとおりです。
showClass <pattern_string> [ to:<stream> ]
<pattern_string>
は、3ds Max クラス名、スーパークラス名およびプロパティ名にあてはまるワイルド カード パターンを含む文字列です。 オプションの to:<stream>
キーワードの引数には、表示内容を出力するストリーム値を指定します。
このパターン文字列の形式は次のとおりです。
"<class_name>[:<superclass_name>][.<property_name>]"
パターン文字列で使用できる特殊文字の詳細については、上記の「パターン文字列」を参照してください。
例:
showClass "path*" -- all 3ds Max classes starting 'path'
showClass "noise.*" -- all the accessible properties on the
-- Noise texture map
showClass "*:mod*" -- all the modifier classes
showClass "*.*rad*" -- all the classes with a property name
-- containing 'rad'
showClass "*.*" to:f -- everything, out to a file
showClass "*:*controller*" -- all the classes that have
-- "controller" in their superclass
-- name
> showClass "[X-Z]*" -- all classes that start with X, Y, or Z
最後の例の出力結果には、3ds Max の重要なコントローラおよびサード パーティ製のプラグイン コントローラが含まれます。複雑なプラグインの埋め込みコントローラ(Character Studio Biped など)も showClass()
一覧に表示されることがあります。これらのコントローラを個別に作成したり使用しないでください。システム例外となります。
スーパークラス パターン(':'
の部分)を省略すれば、これはすべてのスーパークラスに一致します。プロパティ パターン('.'
の部分)を省略すれば、クラス名のみが出力されます。
次に showClass()
の出力例を示します。
スクリプト:
showclass "box*" -- show all classes whose name starts with "box"
showclass "box.*" -- show all properties for class box
出力:
Box : GeometryClass {10,0} -- start of output from line 1
BoxGizmo : helper {3bc31904,67d74ec9}
OK -- result returned from line 1
Box : GeometryClass {10,0} -- start of output from line 2
.height : float
.length : float
.lengthsegs : integer
.width : float
.widthsegs : integer
.mapCoords : boolean
.heightsegs : integer
OK -- result returned from line 2
getObjectName 関数は、履歴ブラウザまたはモディファイヤ スタックに表示される場合と同様に、オブジェクトのクラス名を返します。渡されたオブジェクトがオブジェクトまたはモディファイヤでない場合、この関数は undefined を返します。この関数の構文は、次のとおりです。
getObjectName <object> [localizedName:<bool>]
3ds Max 2022 の新機能:
localizedName
キーワード パラメータが true
(既定値)の場合、UI に表示されるローカライズされた名前が返されます。それ以外の場合は、ローカライズされていない名前が返されます。
たとえば、次のように使用されます。
スクリプト:
myBox = Box name:"myBox"
myBend = Bend()
myCompass = Compass()
getObjectName myBox
--> "Box"
getObjectName myBend
--> "Bend"
getObjectName myCompass
--> "Compass"
showProperties()
関数を使用すると、MAXWrapper クラスのインスタンスである特定のオブジェクトのプロパティを表示できます。この関数は、実際のオブジェクトを取得できる場合に showClass()
の代わりに使われますが、showClass()
とは異なり、ダイナミック プロパティを表示できます。これは、シーン内でオブジェクトを操作すると、各オブジェクト内に現れます。リスト コントローラ内のサブ コントローラや、FFD モディファイヤ内のアニメートされたコントロール ポイントなどがその例です。
showProperties()
関数の形式は次のとおりです。
showProperties <maxwrapper_object> [ <property_pattern> ] [ to :<stream> ]
<maxwrapper_object>
は、調査される 3ds Max 図形です。オプションの <property_pattern>
は、調査されるプロパティを指定するワイルド カード パターンです。オプションの to:<stream>
キーワードの引数には、表示内容を出力するストリーム値を指定します。
<property_pattern>
はパターン文字列です。パターン文字列に含めることができる特殊文字の詳細については、上記の「パターン文字列」を参照してください。
プロパティ名パターンが与えられない場合は、すべてのプロパティが一覧されます。
スクリプト:
showProperties $foo.bend -- show properties of the Bend modifier on object foo
ffdmod = $baz.'FFD_box__4x4x4' -- point to the FFD modifier on object baz
showProperties ffdmod "disp*" to:log -- show properties starting with "disp" in the FFD modifier
showProperties $foo.pos.controller -- sub controllers in a position list controller
> showProperties $foo "[t-z]*" -- show properties starting with t to z on object foo
指定された 3ds Max の図形がノード($box01 など)の場合、この関数は基本オブジェクトのプロパティ だけを表示します。オブジェクトに適用される変換コントローラ、モディファイヤ、あるいはマテリアルのプロパティは表示しません。これらのオブジェクトのプロパティを表示するには、上記の例で示したように、オブジェクトが 3ds Max の図形として指定されている必要があります。
3ds Max 8 以降、showProperties には、FPS インタフェースで定義されるプロパティが含まれています。
次に showProperties の出力例を示します。
スクリプト:
b = box() -- create a box
ffd_mod = ffdBox() -- create a ffdBox modifier
addmodifier b ffd_mod -- apply ffdBox modifier to the box
showproperties b -- show all properties for the box
showproperties ffd_mod -- show all properties for the ffdBox modifier
出力:
$Box:Box07 @ [0.0000,0.0000,0.0000] -- result from line 1
FFD_box__4x4x4:FFD(box) 4x4x4 -- result from line 2
OK -- result from line 3
.height : float -- start of output from line 4
.length : float
.lengthsegs : integer
.width : float
.widthsegs : integer
.mapCoords : boolean
.heightsegs : integer
OK -- result from line 4
.dispLattice (Lattice) : boolean -- start of output from line 5
.dispSource (Source Volume) : boolean
.deformType (<unknown>) : integer
.falloff : float
.tension : float
.continuity : float
.inPoints (Inside Points) : boolean
.outPoints (Outside Points) : boolean
.offset : float
.lattice_transform : transform
OK -- result from line 5
スクリプトを簡単に記述および使用できるようにするために、ScriptTool 関数の「Show」が追加されました。
Show は、ShowProperties の入力を簡単にするための関数です。
例:
Show $ --will show you the properties of the selected object
getPropNames()
関数は、特定のオブジェクトのプロパティ名を配列として返す点を除けば、showProperties()
関数に似ています。この関数は、showProperties()
とは異なり、オブジェクトのダイナミック プロパティの名前だけを返すかどうかを指定できます。
getPropNames
関数の形式は次のとおりです。
getPropNames <maxwrapper_obj> [ #dynamicOnly]
getPropNames()
関数は、オブジェクトでアクセス可能なプロパティ名の配列を返します。
例:
次のようにアニメートされたコントロール ポイントを持つ FFD(Box)モディファイヤを球に適用する場合、
getPropNames $sphere01.'FFD(box) 4x4x4'
結果は次のようになります。
#(#dispLattice, #dispSource, #deformType, #falloff, #tension, #continuity, #inPoints, #outPoints, #offset, #Lattice_Transform, #Control_Point_49, #Control_Point_50, #Control_Point_51, #Control_Point_52, #Control_Point_53)
指定された 3ds Max の図形がノード($box01 など)の場合、この関数は基本オブジェクトのプロパティ だけを返します。オブジェクトに適用される変換コントローラ、モディファイヤ、あるいはマテリアルのプロパティは返しません。これらのオブジェクトのプロパティを返すには、上記の例で示したように、オブジェクトが 3ds Max の図形として指定されている必要があります。
3ds Max 8 以降、getPropNames には、FPS インタフェースで定義されるプロパティが含まれています。
ボックス、ライン、またはベンドなどの MAXWrapper クラスで getPropNames()
を呼び出すと、そのクラスのすべてのインスタンスに共通するプロパティを返します。3ds Max の図形で getPropNames()
を呼び出すと、その図形に対して定義されているプロパティを返します。 オプションのキーワード #dynamicOnly
を図形に対する getPropNames()
呼び出しに追加した場合は、そのインスタンスに固有のダイナミック プロパティを返します。
例:
次のようにアニメートされたコントロール ポイントを持つ FFD(Box)モディファイヤを球に適用する場合、
getPropNames $sphere01.'FFD(box) 4x4x4' #dynamicOnly
結果は次のようになります。
#(#Lattice_Transform, #Control_Point_49, #Control_Point_50, #Control_Point_51, #Control_Point_52, #Control_Point_53)
#dynamicOnly
が指定された場合は返されません。これらのプロパティは、特定の FFD モディファイヤに固有です。特別な場合として、スーパークラス「ノード」上で getPropNames()
を呼び出して、.position
、.name
、または .wireColor
などのすべてのシーン ノードに共通するプロパティの一覧を取得できます。
例:
getPropNames node
getPropNames
メソッドは、さまざまなインタフェース値を扱うために拡張されました。このメソッドは、インタフェースに表示されたプロパティの名前を返します。
例:
getpropnames s.inode
#(#boneEnable, #posTaskWeight, #rotTaskWeight, #boneAutoAlign, #boneFreezeLength, #boneScaleType, #stretchTM, #boneAxis, #boneAxisFlip, #primaryVisibility, #secondaryVisibility, #applyAtmospherics, #vertexColorType, #showVertexColors, #shadeVertexColors, #handle, #posInParent, #rotInParent, #scaleInParent, #scaleOrientInParent)
getProperty()
および setProperty()
関数により、計算されたプロパティ名を使用してプロパティにアクセスし、そのプロパティを設定できます。
各関数の形式は次のとおりです。
getProperty <obj> <property_name> [removeUIScaling:<boolean>]
setProperty <obj> <property_name> <value> [applyUIScalling:<boolean>]
プロパティ名は、#length
、または文字列 "length"
などの名前になります。プロパティ名は文字列演算子で構成することができます。
removeUIScaling
/applyUIScaling
パラメータの既定値は true です。false の場合、スクリーンの値に関連するプロパティ(UI コントロール用の #pos など)の値は高 DPI ディスプレイのスケール係数の影響を受けます。 3ds Max 2017 以降で使用可能です。
例:
getProperty foo #x -- equiv. to foo.x
setProperty $foo "radius" 23 -- equiv. to $foo.radius = 23
getProperty $foo.ffd_2x2x2 ("control_point_" + n as string)
getPropNames()
関数を getProperty()
関数とともに使用すると、任意オブジェクトのすべてのプロパティを反復し、必要に応じてそれらを出力できるオブジェクトの「ダンプ」ツールを作成することができます。
例:
for p in getPropNames $foo do
format "% = %\n" p (getProperty $foo p)
プロパティが割り当てられたコントローラ値へのアクセスおよび設定を行う場合も、同じ関数を使用します。
getPropertyController <value> <string_or_name>
setPropertyController <value> <string_or_name> <controller>
値の指定したプロパティに割り当てられたコントローラを取得および設定します。コントローラがプロパティに割り当てられていない場合、undefined 値が返されます。
hasProperty()
関数を使用すると、オブジェクトに指定のプロパティ名があるかどうかをテストできます。isProperty(),
とは異なり、プロパティ名文字列ではワイルドカード パターンがサポートされます。
hasProperty <obj> <prop_name_or_pattern_string>
オブジェクトに指定したプロパティがある場合、または文字列パターンに一致するプロパティがある場合は、true
を返します。
例:
hasProperty $Box01 "height" --test for height in a Box
--> true
hasProperty $Box01 "radius" --test for radius in a Box
--> false
hasProperty $Sphere01 "radius" --test for radius in a Sphere
--> true
hasProperty $Sphere01 "rad*" --test for any property name
--> true --starting with "rad" in a Sphere
isProperty()
関数を使用すると、オブジェクトに指定のプロパティがあるかどうかをテストできます。
isProperty <MAXWrapper_object> <property_name_or_string>
isProperty()
は、指定のプロパティが MAXWrapper オブジェクトのプロパティである場合は true
を、それ以外の場合は false
を返します。プロパティ名は、#length
、または文字列 "length"
などの名前になります。プロパティ名は文字列演算子で構成することができます。
例:
b=box()
s=sphere()
isProperty $Box001 #height --test for height in a Box
--> true
isProperty $Box001 #radius --test for radius in a Box
--> false
isProperty $Sphere001 #radius --test for radius in a Sphere
--> true
hasProperty と isProperty は、まったく異なった動作をします。
例:
hasProperty $Box01 "name"
--> false
isProperty $Box01 "name"
--> true
hasProperty は、showPropeties()
と同じコードを使用しますが、検出されたプロパティのリストを返さずに、指定したパターンと一致する最初のプロパティ名で true を返します。** showProperties** は、ボックスのベース オブジェクトおよび MAXClass 定義を調べます。上位レベルのプロパティは調査しません(3ds Max 8 より前のバージョンでは、FPS インタフェースで公開されているプロパティは調査されません)。
それに対し、isProperty は、指定された名前を含む指定のオブジェクトに実際にアクセスし、アクセスが正常に行われたかエラーになったかを検出しようとします。
isPropertyAnimatable <obj> <string_or_name>
プロパティが見つかり、それがアニメート可能である場合は true
を返します。プロパティが見つからない場合、またはアニメート可能でない場合は false
を返します。
例:
s = Sphere() --create a sphere
--> $Sphere:Sphere01 @ [0.000000,0.000000,0.000000]
isPropertyAnimatable s #radius --check if radius is animatable
--> true
isPropertyAnimatable s #mapCoords --check if UV coords are
--> false
別の例:
s = Sphere() --create a sphere
--Print a list of all properties of the sphere and whether
--they are animatable or not:
for i in getPropNames s do
format "% Property: % - Animatable: %\n"s.name i (isPropertyAnimatable s i)
結果:
$Sphere:Sphere003 @ [0.000000,0.000000,0.000000]
Sphere003 Property: #smooth - Animatable: true
Sphere003 Property: #radius - Animatable: true
Sphere003 Property: #segs - Animatable: true
Sphere003 Property: #mapcoords - Animatable: false
Sphere003 Property: #slice - Animatable: false
Sphere003 Property: #hemisphere - Animatable: true
Sphere003 Property: #sliceFrom - Animatable: true
Sphere003 Property: #sliceTo - Animatable: true
Sphere003 Property: #chop - Animatable: false
Sphere003 Property: #recenter - Animatable: false
Sphere003 Property: #realWorldMapSize - Animatable: false
OK
3ds Max は、subAnims と呼ばれる構造体のオブジェクトのプロパティをすべて保存します。subAnim は、別のネストされた subAnim を含むこともあり、標準マテリアルで使用されることがあります。標準マテリアルを 3ds Max オブジェクトに適用し、マテリアルを表示するためにトラック ビュー内でオブジェクトのトラックを展開した場合、3 つのトラック ビュー ノードが表示されます。これらのトラック ビュー ノードは Parameters、Maps、Shader であり、各ノードは標準マテリアルのクラスで定義された subAnim です。これらの 3 つのノードを展開すると、さまざまなプロパティが一覧で表示されます。これらのプロパティは、ParamBlock という構造体内でネストされた subAnims ごとに定義されます。
MAXScript は、オブジェクトに関連する ParamBlock 内でアニメート可能プロパティを自動的に検索します。これらのプロパティにアクセスするには、MAXScript のプロパティの参照時にトラック ビューに表示されているのと同じネスト構造を使用します。
例:
MAXScript の標準マテリアル内の Ambient Color プロパティにアクセスするには、次のようにします。
$box01.material.shader.diffuse_color
MAXScript でのアニメート可能なプロパティへのアクセスの詳細については、「3ds Max オブジェクトでのアニメート可能なプロパティへのアクセス」を参照してください。
さまざまな種類の値におけるアクセス可能なプロパティが各クラスごとに説明されています。MAXScript のほとんどの基本クラス(Point3、カラーなど)は、特殊な種類のネストされたプロパティの割り当てをサポートします。これにより、ノードの .position
プロパティの .x
、.y
、.z
座標のようなオブジェクト プロパティ上のサブプロパティを、個別にまたは直接設定することができます。詳細は、「ネストされたオブジェクトのプロパティ」を参照してください。