Overview:
概観:
In Part II we created a UI dialog that communicates with the Random Replicate function we created in Part I.
一部分私たちが作成したII、ランダムで私たちが一部分作成した折り返した機能を通信するUI対話、私。
In this example we'll create a new menu item in the CX application Scripting Menu for easy access.
この例において、私たちは、容易なアクセス用メニューをスクリプトにするCX適用で新しいメニュー項目を作成するでしょう。
Creating a Scripting Menu Item:
スクリプトを書くメニュー項目の作成:
The CX Scripting Menu is stored in the s3d.ui Lua table by the name scripting_menu:
CXのスクリプトを書くメニューは、名前scripting_menuによってs3d.ui Luaテーブルに格納されます:
print(s3d.ui.scripting_menu)
If you copy/paste the above code in the Console and Evaluate it, you'll see the print out of the contents of this table (unformatted).
印刷(s3d.ui.scripting_menu)場合、あなた、上記のものがコンソールの中でコード化し評価するコピー/ペースト、それ、見るでしょう、このテーブル(unformatted)の内容に印刷します。
You can easily add a new item to this menu by using any method in Lua that allows you to insert an item into a table. The Scripting Menu table requires the following format though when adding new items to the scripting menu.
あなたがテーブルにアイテムを挿入することを可能にするLuaの中でどんな方法も使用することにより、このメニューに容易に新しいアイテムを加えることができます。しかしながら、スクリプトを書くメニューに新しいアイテムを加える場合、スクリプトを書くメニュー・テーブルは次のフォーマットを要求します。
- A Lua table with the first element in the table as the name
- of the menu item and the second element as a function that will
- get called when the item is activated by selecting it
local newMenuItem = { "Menu Title as String",
function (menuItem)
print("menu selected")
end
}
- Insert this menu item into the Scripting Menu
table.insert(s3d.ui.scripting_menu, newMenuItem)
- 名前としてのテーブル中の最初の要素を備えたLuaテーブル-- 機能としてのメニュー項目および第2の要素の-- アイテムがそれの選択により活性化される時、呼ばれます。ローカルのnewMenuItem={「ストリングとしてのメニュータイトル」、関数(menuItem)印刷(「選択されたメニュー」)終了}-- スクリプトを書くメニューtable.insert(s3d.ui.scripting_menu、newMenuItem)にこのメニュー項目を挿入します。
Copy/paste the above code into the Console, select it and press Evaluate. Notice that there is now a new menu item named Menu Title as String in your menu.
コピー/ペースト、コンソールの中への上記のコード、それと圧迫を選択する、評価します。あなたのメニュー中のストリングとして、メニュータイトルという名の新しいメニュー項目が今あることに注目してください。
The Lua table implementation in CX 5 should store entries in a linear fashion, so the last entry in the s3d.ui.scripting_menu should be what we just added. Let's remove that last entry so we're not going to keep filling up the table with useless items.
CX 5の中のLuaテーブル・インプリメンテーションは線形の方法でエントリーを格納するべきです、まさに、s3d.ui.scripting_menuの中の最後のエントリーはそうであるべきです、何、私たちはちょうど付け加えました。私たちが役立たないアイテムでテーブルを満たし続けないように、その最後のエントリーを撤去しましょう。
table.remove ( s3d.ui.scripting_menu )
The table.remove() function takes two arguments normally: the first is the table to remove items from and the second parameter would be the index of the item you want to remove. If you provide no index as in the line of code above, the last item will be removed in the table. Run the above line in the console then check the Scripting menu to see that it was remvoed.
table.remove(s3d.ui.scripting_menu)table.remove()機能は2つの議論を通常とります:1番目はアイテムを取り除くテーブルです。また、第2のパラメーターはあなたが削除したいアイテムのインデックスになるでしょう。あなたが上記の命令行の中でほどインデックスを提供しなければ、最後のアイテムがテーブルの中で削除されるでしょう。コンソール中の上記のラインを実行する、その後、それがremvoedされたことを理解するためにスクリプトを書くメニューをチェックします。
Now that we know how to add a new menu item, let's modify that code so that it will launch our RandomReplicateUI() function from Part II - the function that provides our Random Replication dialog to the user.
私たちが今新しいメニュー項目を加える方法を知っているので、それが部分IIからの私たちのRandomReplicateUI()機能を始めるように、そのコードを修正しましょう-ユーザに私たちの任意の応答対話を供給する機能。
local newMenuItem = { "Random Replicate",
function (menuItem)
RandomReplicateUI()
end
}
table.insert(s3d.ui.scripting_menu, newMenuItem)
ローカルのnewMenuItem={「折り返したランダム」、関数(menuItem)RandomReplicateUI()終了}table.insert(s3d.ui.scripting_menu、newMenuItem)
To run the menu, you have to run the final code from Part II of the tutorials, or copy/paste the following entire chunk of code into the console and run it. This is the entire script up to this point in time.
メニューを実行するために、教本の部分IIからの最終コード、あるいはコピー/ペーストを実行しなければなりません、コンソールの中へのコードの次の塊全体、またそれを実行します。これはこの時までの全スクリプトです。
- A function to replicate a selected object a certain number of times
function Replicate(numCopies)
local c = s3d.database.GetActiveContext() local m = c and c:GetManipulatorManager() local size = m and m:GetSize()
if size > 0 then
local i = m:GetIndexedInstance(1)
for t=1, numCopies do
print("Creating copy ".. t)
local inst = i:Clone()
c:AddInstance(inst)
-- Random translation within 5 inch boundary
local tx = math.random(360) - math.random(360)
local ty = math.random(360) - math.random(360)
local tz = math.random(360) - math.random(360)
local position = s3d.vec.Point3d(tx,ty,tz)
-- Make sure our objects are at least 0.5 inches plus some random deviation
local ns = 36 + math.random(72)
local scale = s3d.vec.Point3d(ns,ns,ns)
local vector = s3d.vec.Dir3d(math.random(), math.random(), math.random()):Normalize()
local angle = math.random()*2*math.pi
local w = math.cos(angle/2)
local qx = vector.x * math.sin(angle/2)
local qy = vector.y * math.sin(angle/2)
local qz = vector.z * math.sin(angle/2)
local rotation = s3d.vec.Quaternion(qx,qy,qz,w)
inst:SetTranslationAt(0,position)
inst:SetScaleAt(0,scale)
inst:SetRotationAt(0, rotation )
end
c:Refresh()
else
s3d.ui.Alert ("You must select an object.")
end
end
function RandomReplicateUI()
local d = s3d.ui.Dialog("Random Replicate")
d:AddStaticText("Number of Copies")
local numCopies = d:AddNumberText(0,0,40)
d:SetLabel(s3d.ui.Dialog.kOkay, "Replicate")
d:SetLabel(s3d.ui.Dialog.kCancel, "Cancel")
local function checkUI(id) if id == s3d.ui.Dialog.kOkay then local num = d:GetValue(numCopies) if num ~= 0 then Replicate(num) end end end d:Present( checkUI )
end
local newMenuItem = { "Random Replicate",
function (menuItem)
RandomReplicateUI()
end
}
table.insert(s3d.ui.scripting_menu, newMenuItem)
Sweet. With that we now have a script that adds a new quick menu item to the Scripting Menu that will randomly replicate a selected object a certain number of times.
- 幾らかの回機能が模写する(numCopies)選択されたオブジェクトを模写する機能ローカルのcの=のs3d.database.GetActiveContextの()のローカルのm=cおよびc:GetManipulatorManagerの()のローカルのサイズ=mおよびm:GetSize()場合、サイズ>その後0ローカルのi=m:GetIndexedInstance(1)t=1については、numCopiesは印刷します。(「作成するコピー「..t)ローカルのinst=i:クローン()c:AddInstance(inst)-- 5インチの境界内の任意の翻訳、ローカルのtx=math.random(-math.random(360)ローカルのtz=math.random(360)-、-math.random(360)ローカルの位置=s3d.vec.Point3d(tx、ty、tz)-)(360)-math.random(360)のローカルのty=math.random(360)- -- 私たちの目的が少なくとも0.5インチプラスであることを確かめる、ある確率差異のローカルのns=36+math.random(72)ローカルの規模=s3d.vec.Point3d(ns、ns、ns) ローカルのベクトル=s3d.vec.Dir3d(math.random()、math.random()(math.randomの()の):Normalizeのローカルの角度=math.random*2*math)。)
パイローカルのw=math.cos(角度/2)ローカルのqx=vector.x* math.sin(角度/2)ローカルのqy=vector.y* math.sin(角度/2)ローカルのqz=vector.z* math.sin(角度/2)ローカルの回転=s3d.vec.Quaternion(qx、qy、qz、w) inst:SetTranslationAt(0と位置)inst:SetScaleAt(0と規模)inst:SetRotationAt(0と回転)終了c:()をリフレッシュしますほかにs3d.ui.Alert(「オブジェクトを選択しなければなりません。。」)終了終了関数RandomReplicateUI()ローカルのdの=のs3d.ui.Dialog(「ランダム、折れ重なる」)のd:AddStaticText(「コピーの数」)のローカルのnumCopies=d:AddNumberText(0、0、40)d:SetLabel(s3d.ui.Dialog.kOkay、「折れ重なってください」)d:SetLabel(s3d.ui.Dialog.kCancel、「取り消してください」) ローカルの関数checkUI(id)場合、id==s3d.ui.Dialog.kOkay、その後、ローカルのnum=d:GetValue(numCopies)場合、num( ̄=)その後、0は折れ重なります(num)。終了終了終了d:現在(checkUI)終了ローカルのnewMenuItem={「折り返したランダム」、関数(menuItem)RandomReplicateUI()終了}table.insert(s3d.ui。)
scripting_menu(newMenuItemスウィート)。それで、私たちは、今任意に折れ重なるスクリプトを書くメニューに新しい迅速なメニュー項目を加えるスクリプトを持っています、1つの、選択された、反対する、幾らかの回。
Load the script on application launch:
適用着手にスクリプトを載せてください:
For Strata CX 5 to recognize a script on startup, it must be located in:
層CX 5が操業開始中のスクリプトを認識するために、それは次のものに位置しなければなりません:
MAC - CX Application Folder / Scripts / Autoload
マック-CXアプリケーション、フォルダー/スクリプト/自動的にロードする
PC - C:\Documents and Settings\USERNAME\Application Data\Strata 3D CX\Scripts\Autoload
PC -C:\Documentsとセッティングの\ユーザー名\アプリケーションデータ\層、3D CX\スクリプト\自動的にロードする
Note that there are additional locations that will load scripts also.
スクリプトをさらにロードする追加の位置があることに注意してください。
edit - added "Autoload" directory path to the PC scripts path.
編集-「自動的にロードしてください」と付け加える、PCスクリプト・パスへのディレクトリ・パス。
Create a new text file in your text editor of choice and copy/paste the code block above into it. At the very beginning of the file, add the following line:
選択のテキストエディターに新しいテキストファイルを作成して、それにコード・ブロックを上にコピーしてくださる/貼ってください。ファイルの一番最初に、次のラインを加えてください:
module("ReplicateModule", package.seeall)
モジュール(「ReplicateModule」(package.seeall))
This special line deifnes all the code that follows it to be part of a module "ReplicateModule". The additional parameter package.seeall is a special switch in Lua that will allow the module you are defining to see and access the global table. Without this line, you will not be able to access anything outside the module unless you define it first.
この特別のラインdeifnes、モジュール「ReplicateModule」の一部であるためにそれに続くすべてのコード。付加的なパラメーターpackage.seeallは、見るために定義しているモジュールを許可し、グローバルなテーブルにアクセスするLuaの中の特別のスイッチです。このラインなしでは、もしそれを最初に定義しなければ、モジュールの外側の何にもアクセスすることができないでしょう。
Save this file in your Autoload directory (as discussed above) and name it "ReplicateModule.lua". Relaunch Strata CX 5 and you should see your "Random Replicate" menu item available to you.
Autoloadディレクトリー(上に議論されたとともに)にこのファイルを保存して、それを「ReplicateModule.lua」と命名してください。再度層CX 5を始めてください。そうすれば、「折り返したランダム」メニュー項目があなたに利用可能なのを見るべきです。
Here's the contents of my final file, ReplicateModule.lua:
ここに、私の最終ファイル、ReplicateModule.luaの内容があります:
module("ReplicateModule", package.seeall)
- A function to replicate a selected object a certain number of times
function Replicate(numCopies)
local c = s3d.database.GetActiveContext() local m = c and c:GetManipulatorManager() local size = m and m:GetSize()
if size > 0 then
local i = m:GetIndexedInstance(1)
for t=1, numCopies do
print("Creating copy ".. t)
local inst = i:Clone()
c:AddInstance(inst)
-- Random translation within 5 inch boundary
local tx = math.random(360) - math.random(360)
local ty = math.random(360) - math.random(360)
local tz = math.random(360) - math.random(360)
local position = s3d.vec.Point3d(tx,ty,tz)
-- Make sure our objects are at least 0.5 inches plus some random deviation
local ns = 36 + math.random(72)
local scale = s3d.vec.Point3d(ns,ns,ns)
local vector = s3d.vec.Dir3d(math.random(), math.random(), math.random()):Normalize()
local angle = math.random()*2*math.pi
local w = math.cos(angle/2)
local qx = vector.x * math.sin(angle/2)
local qy = vector.y * math.sin(angle/2)
local qz = vector.z * math.sin(angle/2)
local rotation = s3d.vec.Quaternion(qx,qy,qz,w)
inst:SetTranslationAt(0,position)
inst:SetScaleAt(0,scale)
inst:SetRotationAt(0, rotation )
end
c:Refresh()
else
s3d.ui.Alert ("You must select an object.")
end
end
- UI Dialog to control the RandomReplicate function
function RandomReplicateUI()
local d = s3d.ui.Dialog("Random Replicate")
d:AddStaticText("Number of Copies")
local numCopies = d:AddNumberText(0,0,40)
d:SetLabel(s3d.ui.Dialog.kOkay, "Replicate")
d:SetLabel(s3d.ui.Dialog.kCancel, "Cancel")
local function checkUI(id)
if id == s3d.ui.Dialog.kOkay then
local num = d:GetValue(numCopies)
if num ~= 0 then
Replicate(num)
end
end
end
d:Present( checkUI )
end
local separator = { "-" }
local randReplicateMenuItem = { "Random Replicate",
function (menuItem)
RandomReplicateUI()
end
}
- Insert this menu item (and a separator) into the Scripting Menu
table.insert(s3d.ui.scripting_menu, separator)
table.insert(s3d.ui.scripting_menu, randReplicateMenuItem)
モジュール(「ReplicateModule」(package.seeall))-- 幾らかの回機能が模写する(numCopies)選択されたオブジェクトを模写する機能ローカルのcの=のs3d.database.GetActiveContextの()のローカルのm=cおよびc:GetManipulatorManagerの()のローカルのサイズ=mおよびm:GetSize()場合、サイズ>その後0ローカルのi=m:GetIndexedInstance(1)t=1については、numCopiesは印刷します。(「作成するコピー「..t)ローカルのinst=i:クローン()c:AddInstance(inst)-- 5インチの境界内の任意の翻訳、ローカルのtx=math.random(-math.random(360)ローカルのtz=math.random(360)-、-math.random(360)ローカルの位置=s3d.vec.Point3d(tx、ty、tz)-)(360)-math.random(360)のローカルのty=math.random(360)- -- 私たちの目的が少なくとも0.5インチプラスであることを確かめる、ある確率差異のローカルのns=36+math.random(72)ローカルの規模=s3d.vec.Point3d(ns、ns、ns) ローカルのベクトル=s3d.vec.Dir3d(math.random()、math.random()、数学。)
任意の ()):Normalize()ローカルの角度=math.random()*2*math.piのローカルのw=math.cos(角度/2)ローカルのqx=vector.x* math.sin(角度/2)ローカルのqy=vector.y* math.sin(角度/2)ローカルのqz=vector.z* math.sin(角度/2)ローカルの回転=s3d.vec.Quaternion(qx、qy、qz、w) inst:SetTranslationAt(0と位置)inst:SetScaleAt(0と規模)inst:SetRotationAt(0と回転)終了c:()をリフレッシュしますほかにs3d.ui.Alert(「オブジェクトを選択しなければなりません。。」)終了終了-- RandomReplicate関数関数RandomReplicateUI()をコントロールするUI対話ローカルのdの=のs3d.ui.Dialog(「ランダム、折れ重なる」)のd:AddStaticText(「コピーの数」)のローカルのnumCopies=d:AddNumberText(0、0、40)のd:SetLabel(s3d.ui.Dialog.kOkay、「折れ重なってください」)のd:SetLabel(s3d.ui.Dialog.kCancel、「取り消してください」)のローカルの関数checkUI(id)場合、id==s3d.ui.Dialog。
kOkay、その後、その後、num ̄=0が折れ重なる場合(num)、ローカルのnum=d:GetValue(numCopies) 終了終了終了d:現在(checkUI)終了ローカルのセパレーター={」}のローカルのrandReplicateMenuItem={「ランダム、折れ重なる。」関数(menuItem)RandomReplicateUI()終了 (")}-- スクリプトを書くメニューtable.insert(s3d.ui.scripting_menu、セパレーター)table.insert(s3d.ui.scripting_menu、randReplicateMenuItem)にこのメニュー品目(またセパレーター)を挿入します。
If you look at the final code above, you may see a couple additional lines added in - a separator and another insertion into the Scripting Menu. I do this to keep menus either grouped by common theme or to keep all my menus separated from others I might download.
上記の最終コードを見れば、2、3行の追加のラインが加えられたのを見てもよい-セパレーターおよびスクリプトを書くメニューの中への別の挿入。私は、共通のテーマによってグループ化されたメニューを維持するかあるいは他のものから私のメニューをすべて分けておくためにこれをします、私はダウンロードするかもしれません。
This pretty much concludes our Random Replication tutorial. There's a lot more that can be accomplished by modifying this script. Adding new controls to your UI to pass limits to the RandomReplicate function or using another selected object as the basis for the random numbers are just a couple ideas.
これはほとんど私たちの任意の応答教本を終えます。このスクリプトの修正により遂行することができるロットがそれ以上です。あなたのUIに範囲をRandomReplicate機能へ渡すために新しいコントロールを加えるか基礎として別の選択されたオブジェクトを乱数に使用することは、単に2、3の考えです。
have fun scripting!
楽しみをスクリプトを書くしてください!
Jon Bradley
ジョン・ブラッドリー
Animator / VFX Artist
There is no Autoload folder in my Scripts folder.
私のスクリプトフォルダにAutoloadフォルダーはありません。
What can I do to install this script.
私は、このスクリプトをインストールするために何を行うことができますか。
ust create that "Autoload" folder inside the "Scripts" folder and put the script in. Make sure to relaunch Strata 3D after putting the script in the right place.
それを単に作成する「自動的にロードしてください」「スクリプト」フォルダーの内部のフォルダー、またスクリプトを入れます。適切な場所にスクリプトを入れた後に再度層3Dを始めるために確かめてください。
I tried that, but it did not work
Iはそれを試みました。しかし、それは作動しませんでした。
I'm looking into this right now. I can not get the scripts to autoload either. I'll post an answer when I have one.
私は今ちょうどこれを調査しています。Iはスクリプトにどちらかに自動的にロードさせることができません。私は、1つ持っている時、答えを記入しましょう。
Brian Lawson
I'm actually very interested in that random replication script, because i have a project at the moment which could needa little bit of chaos... i already got it through the bulletin, but it it doesn't autoload...either...
プロジェクトをちょうど今持つので、私は実際にその任意の応答スクリプトに非常に興味を持っています、混乱の少量をneedaする...公報によってそれに既に得られていたi、しかしそれ、それは自動的にロードしません。..either...
Just because it does not autoload does not mean it cannot be used.
それが自動的にロードしないだけで、それを使用することができないことを意味しません。
You can copy/paste the entire script from the bulletin download in your Scripting Console, select all the code and Evaluate. It will add the menu to your system with all the functionality shown in the tutorials.
あなたがコンソールをスクリプトにする際に公報ダウンロードから全スクリプトをコピーすることができる/貼り、コードをすべて選択し、評価することができます。それは、教本の中で示されるすべての機能性を備えたあなたのシステムにメニューを加えるでしょう。
If you have any problem, definitely let us know. I just tested it out and it should run as expected.
問題を持っている場合は、明確に私たちに知らせてください。私はそれをちょうど実地に試みました。また、それは予想通りに走るべきです。
best,
最良です、
Jon Bradley
Thank you Jon! The script works fine (with CX5 tryout).
ありがとう、ジョン!スクリプトは素晴らしく(CX5選考試験で)作動します。
But?
しかし?
RandomReplicateUI()' function call 'Replicate(num)' before the 'size > 0' test, so
RandomReplicateUI ()」関数呼び出し「折れ重なる(num)」の前に「サイズ>0」テスト、そのように
the UI dialog appear first, even there is no selection - and (if no selection) alert comes after UI dialog completion.
UI対話、最初にそこにさえ現われる、選択でない-また(場合、選択はない)、警戒はUI対?b完成の後に来ます。
I just try:
Iは次のようにちょうど試みます:
local randReplicateMenuItem = { "Random Replicate2",
function (menuItem)
local c = s3d.database.GetActiveContext()
local m = c and c:GetManipulatorManager()
-- and cut the 2 following lines in 'Replicate' function
local size = m and m:GetSize()
if size > 0 then
RandomReplicateUI()
-- and cut the 3 following lines in 'Replicate' function
else
s3d.ui.Alert ("You must select an object.")
end
end
}
ローカルのrandReplicateMenuItem={「任意のReplicate2」、関数(menuItem)ローカルのcの=のs3d.database.GetActiveContextの()のローカルのm=cおよびc:GetManipulatorManager()(また2行の次のラインをカットする、の中で「折れ重なる」関数のローカルのサイズ=mおよびm:GetSize()場合、サイズ>その後0、RandomReplicateUI())また3行の次のラインをカットする、の中で「折れ重なる」関数、ほかに、s3d.ui.Alert(「オブジェクトを選択しなければなりません。」。)終了、終了する。}
Works fine but yes that's not a 'pretty good' code
素晴らしい工場だがはい、それは「かなりよい」コードではありません
Can you make such (better than mine, of course) modification in the Random Replication, please?
任意の応答の中でそのような(もちろん私のものよりよい)修正をしてください。
Edit: not a good english, sorry => I am french
次のものを編集してください:よいenglishでありません(私がそうである=>がフランス式に調理して残念)
You may want to check out the final thread disucssing additional enhancements to the script: http://www.stratacafe.com/forum/topic.asp?TOPIC_ID=5570
スクリプトへの追加の増強をdisucssingする最終糸をチェックしたいと思うかもしれません:http://www.stratacafe.com/forum/topic.asp?TOPIC_ID=5570
The script included there adds detection of the selection state prior to the menu being activated (turns it off entirely if nothing is selected).
そこに含まれたスクリプトは、活性化されている(完全に何も選択されていない場合、それを切る)メニューに先立って選択状態の検知を加えます。
cheers,
喝采、
Jon Bradley