まずは、現在編集中のジオメトリを取得してみましょう
mari.geo.current()
次にこのジオメトリに新しいチャンネル(フォトショでいうレイヤー)を作ってみます
newName = 'newChannel' channelInfo = mari.ChannelInfo(newName) mari.geo.current().createChannel(channelInfo)channelInfo は作成する名前が必ず必要なので与えます
その他のフラグについてはドキュメントを参考にしてみてください
デフォルトでは、4K解像度、8bit、RGBカラーマップが作成されます
もう一枚追加しようと、実行してみたらエラーになってしまいました
>>> newName = 'newChannel' ... channelInfo = mari.ChannelInfo(newName) ... mari.geo.current().createChannel(channelInfo) Traceback (most recent call last): File "Maya のように名前がバッティングしないように番号付けてくれるような気の利いたことはしてくれないようです", line 3, in ValueError: A channel with the name newChannel already exists. Channel names must be unique
(だからといって Maya を見直したりはしませんが)
そこで、バッティングを回避する処理を入れてみましょう
チャンネルのリストを取得します
mari.geo.current().channelList()
取得したチャンネルリストと、新しく作る名前と同じものがあるかをチェックして
ふたつ以上あれば _番号 を末尾に付ける処理をチャンネル作成処理に追加します
newName = 'newChannel' channelList = mari.geo.current().channelList() count = 1 for ch in channelList: if newName in ch.name(): count += 1 if count > 1: newName = '%s_%d' % (newName, count) channelInfo = mari.ChannelInfo(newName) mari.geo.current().createChannel(channelInfo)これで、何度実行しても大丈夫になりました
以上、非常に簡単ですが必要な情報の取得と処理の仕方についてでした。
0 件のコメント:
コメントを投稿