Inmedモードで法線いじらなければ済む問題ですが、ついやってしまいます。
Inmedモードを切って、
法線をいじって、
Freeze M を掛けて
Inmedモードに戻す
という手順になりますが、これは自動に出来ないのかと今更思いついて書いてみました。
答えは、コマンドイベントを作って、以上の手順を自動にすればいいだけです。
なんで早くこれをやらなかったのかな!
以下のコードをPythonファイルに保存して
例:NormalsEvent.py
プラグインフォルダに入れる:
例: C:\Users\myara\Autodesk\Softimage_2015_SP1\Application\Plugins
ワークグループの場合は:
C:\Workgroup\Application\Plugins
それだけです。あとはSoftimageに任せてください。
from win32com.client import constants as c
xsi = Application
def XSILoadPlugin( in_reg ):
in_reg.Author = "myara"
in_reg.Name = "NormalsEvent Plug-in"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterEvent("Normal_BeginCommand", c.siOnBeginCommand)
in_reg.RegisterEvent("Normal_EndCommand", c.siOnEndCommand)
#RegistrationInsertionPoint - do not remove this line
return True
def XSIUnloadPlugin( in_reg ):
strPluginName = in_reg.Name
Application.LogMessage(str(strPluginName) + str(" has been unloaded."), c.siVerbose)
return True
def Normal_BeginCommand_OnEvent( in_ctxt ):
Application.LogMessage("BeginCommand_OnEvent called", c.siVerbose)
Application.LogMessage("Command: " + str(in_ctxt.GetAttribute("Command")), c.siVerbose)
coms = ['Tweak Normal Tool', 'Average User Normals', 'Set User Normal Values', 'Set Vertex User Normals', 'Set Polygon User Normals', 'Invert User Normals', 'Normalize User Normals', 'Paste User Normals', 'Create User Normals']
if str(in_ctxt.GetAttribute("Command")) in coms:
UserImmed = xsi.GetUserPref("OperationMode")
if UserImmed == True :
xsi.SetGlobal('Normal_Immed', 1)
xsi.SetUserPref("OperationMode", False )
return False
def Normal_EndCommand_OnEvent( in_ctxt ):
Application.LogMessage("EndCommand_OnEvent called", c.siVerbose)
Application.LogMessage("Command: " + str(in_ctxt.GetAttribute("Command")), c.siVerbose)
coms = ['Tweak Normal Tool', 'Average User Normals', 'Set User Normal Values', 'Set Vertex User Normals', 'Set Polygon User Normals', 'Invert User Normals', 'Normalize User Normals', 'Paste User Normals', 'Create User Normals']
if str(in_ctxt.GetAttribute("Command")) in coms:
UserImmed = xsi.GetUserPref("OperationMode")
if xsi.GetGlobal('Normal_Immed') == 1 :
sel = xsi.Selection
for obj in sel:
if obj.Type.find('Component')!=-1:
obj = obj.SubComponent.Parent3DObject
xsi.FreezeModeling(obj)
xsi.SetUserPref("OperationMode", True )
return False
元から書いてある部分
Application.LogMessage("Command: " + str(in_ctxt.GetAttribute("Command")), c.siVerbose)
をあえて残しています。
このコマンドイベントは全てのコマンドを感知して、この行で使われたコマンドのログを残してくれる。
スクリプトエディターのプリファレンスにVerboseもログするようにしない限りログには出てこないけど、似たようなコマンドイベントを作りたい場合は便利だと思ったので、念のため残しておきます。
では、
追記
Softimageは日本語版で使用する場合はとエラーが出ます・・・。
もう少し検証してみます・・・。
追記 2
単純な try を追加してみたらうまくいきました。
良く分からない・・・。
from win32com.client import constants as c
xsi = Application
def XSILoadPlugin( in_reg ):
in_reg.Author = "myara"
in_reg.Name = "NormalsEvent Plug-in"
in_reg.Major = 1
in_reg.Minor = 0
in_reg.RegisterEvent("Normal_BeginCommand", c.siOnBeginCommand)
in_reg.RegisterEvent("Normal_EndCommand", c.siOnEndCommand)
#RegistrationInsertionPoint - do not remove this line
return True
def XSIUnloadPlugin( in_reg ):
strPluginName = in_reg.Name
Application.LogMessage(str(strPluginName) + str(" has been unloaded."), c.siVerbose)
return True
def Normal_BeginCommand_OnEvent( in_ctxt ):
coms = ['Tweak Normal Tool', 'Average User Normals', 'Set User Normal Values', 'Set Vertex User Normals', 'Set Polygon User Normals', 'Invert User Normals', 'Normalize User Normals', 'Paste User Normals', 'Create User Normals']
try:
if str(in_ctxt.GetAttribute("Command")) in coms:
UserImmed = xsi.GetUserPref("OperationMode")
if UserImmed == True :
xsi.SetGlobal('Normal_Immed', 1)
xsi.SetUserPref("OperationMode", False )
except:
pass
return False
def Normal_EndCommand_OnEvent( in_ctxt ):
coms = ['Tweak Normal Tool', 'Average User Normals', 'Set User Normal Values', 'Set Vertex User Normals', 'Set Polygon User Normals', 'Invert User Normals', 'Normalize User Normals', 'Paste User Normals', 'Create User Normals']
try:
if str(in_ctxt.GetAttribute("Command")) in coms:
UserImmed = xsi.GetUserPref("OperationMode")
if xsi.GetGlobal('Normal_Immed') == 1 :
sel = xsi.Selection
for obj in sel:
if obj.Type.find('Component')!=-1:
obj = obj.SubComponent.Parent3DObject
xsi.FreezeModeling(obj)
xsi.SetUserPref("OperationMode", True )
except:
pass
return False