2017年7月28日 星期五

[Batch]About variable expansion tip an trick!

最近在用Bat Script在寫一些自動化的東西, 卻發現了一些非常奇怪的問題

比如說以下我想用FOR迴圈去批次執行一個陣列

::
@ECHO OFF
FOR %%A IN (First:1 Second:2 Third:3) DO (
        SET "VAR=%%A"
        SET "VAR=%VAR::=_%"
        ECHO %VAR%
)

這樣子執行下去 是不會Print 任何東西的

為什麼會這樣子呢...因為在一開始 Bat就會把他的變數(包在%中) 擴展

所以第二個指定就變成這樣 :

SET "VAR="

事實上 對Bat而言 他看到的程式碼應該會變成這樣 :
SET "VAR=First:1"
SET "VAR="
ECHO %VAR%

SET "VAR=Second:2"
SET "VAR="
ECHO %VAR%

SET "VAR=Third:3"
SET "VAR="
ECHO %VAR%

也就是一開始就會進行擴張解釋!

解決方法是甚麼呢?

首先 要在開頭加上
SETLOCAL EnableDelayedExpansion

這可以開啟Bat 的延遲擴解

然後對於要操作的變數 將%置換成!

::
@ECHO OFF
FOR %%A IN (First:1 Second:2 Third:3) DO (
        SET "VAR=%%A"
        SET "VAR=!VAR::=_!"
        ECHO !VAR!
)

像這樣

就可以成功Print出我們要的結果了

First_1
Second_2
Third_3

Chiaxin



[Python2]Magic operate in List type

Recently I found a nice operator in Python list

# code :
a_simple_array = [1, 2, 3, 4, 5, 6]
a_simple_array[::2] = ('one', 'three', 'five')
print a_simple_array
#
# result :
['one', 2, 'three', 4, 'five' 6]
# End code

原來Python 的Array 可以這樣子去Insert! Magic...



2017年3月12日 星期日

[Maya]Custom shelf define

Maya custom shelf directory could be set in Maya.eng such as MAYA_SHELF_PATH=D:/Working/Maya/shelf

But note a one problem, If you as well as define  MAYA_SCRIPT_PATH ,you must take MAYA_SHELF_PATH before!

Otherwise, The definition wouldn't go correctly

Chiaxin

2017年3月5日 星期日

[Maya]Maya的路徑動態連結(Dynamic Path Link)

Maya的動態連結 Dynamic Path Link

這個名字是我自己取的 總之就是一般化(泛化)我們的工作路徑

怎麼辦到呢? 一般我們用的貼圖路徑及Reference路徑都是採絕對路徑

這個在分享彼此之間的檔案時很不方便

因為可能在我的本機我把檔案放在D:\Workspace\Project

而其他人可能把檔案放在E:\workdata\project

這樣的話檔案轉移到他那裡的時候 路徑連結就會斷掉了!

因此我們可以增加一個變數去控制上層的路徑

找到C:\users\<USERNAME>\documents\maya\<MAYA-VERSION>\Maya.env

<USERNAME>是你的電腦名稱
<MAYA-VERSION>是你的Maya 版本

用記事本將之打開 加入這一行

PROJECTWORKS=D:\Workspace\Project

之後在打包檔案的時候你只要將Texture or Reference路徑改為

$PROJECTWORKS\assets\sourceimages\texture.tga
or
$PROJECTWORKS\assets\assets.ma

對方只要在自己的Maya.env改變PROJECTWORKS就可以指定他電腦的相對路徑!

但是這個做法可能需要一些打包Package Script來幫忙我們改路徑..

Chiaxin

[MentalRay] Maya Custom Shader Install

How to intall Mental Ray Custom Shader ?

Mental Ray shaders commonly place in 

C:\Program Files\Autodesk\mentalrayForMaya2015\shaders (in Maya2015)

example : MayaShaders.dll

It is a binary data, and the mi place in include : MayaShaders.mi

so you need a pairs file : shader.dll and shader.mi

If you want to place them to custom path

example - D:\shaders\mentalray\

You must to set Maya environment to let Maya know what shader do you install

In common, Maya.env in C:\users\<Username>\documents\maya\<MayaVersion>

We just add two line

MI_CUSTOM_SHADER_PATH=D:\shaders\mentalray\include
MI_LIBRARY_PATH=D:\shaders\mentalray\lib

In here, "lib" just a classify, you also could be place in D:\shaders\mentalray

Best is create yourself AETemplates directory and icon directory

You will not get messy in many file

Try to add 

MAYA_CUSTOM_TEMPLATE_PATH=D:\custom\maya\2015-x64\AETemplates
XBMLANGPATH=D:\custom\maya\2015-x64\prefs\icons

Their are AETemplate & Icons for yours

MI_CUSTOM_SHADER_PATH & MI_LIBRARY_PATH make Maya got custom shaders

Finally, we find C:\Program Files\Autodesk\mentalrayForMaya2015\maya.rayrc

open it and add

registry "{DSO}" value "dll" end registry
registry "{_CUSTOM_SHADERS}" value "D:/shaders/mentalray" end registry
link "{_CUSTOM_SHADERS}/lib/shader.{DSO}"
mi "{_CUSTOM_SHADERS}/include/shader.mi"

Complete install, we now can be use custom shader in Maya

Following reference :

https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/Maya/files/GUID-3A452245-0676-4FFB-AAF5-72A10F77C54C-htm.html

https://knowledge.autodesk.com/support/maya/learn-explore/caas/mne-help/global/docs/maya2014/en_us/files/mrfMS-Load-shaders-htm.html