本教程涉及maxscript脚知识,请谨慎阅读!本人也只是动画师,不是程序员,所以不专业或者有问题的地方欢迎批评指出!有时候我们制作插件需要保存一些数据到外部,方便随时调用!虽然max可以通过配置文件写入数据,但是数据较多还是推荐数据库存储!而且数据库可以有很大的延展空间!
比如我要制作一个动作库,将所有平时见到的好的bip动作保存起来,然后每次要用的时候通过查询数据库马上找到文件并导入max,这时候就可以用数据库,一般本地我推荐access数据库,这个不需要服务器,就是一个单一的数据库文件,而且随时可以迁移到别的地方!
maxscript支持的数据库有以下几种
| |
| Driver={Microsoft Access Driver (*.mdb)};DBQ=physical path to .mdb file |
| DRIVER={SQL Server};SERVER=path to server |
| DRIVER={Microsoft ODBC for Oracle};SERVER=path to server |
| Driver={Microsoft Excel Driver (*.xls)};DBQ=physical path to .xls file; DriverID=278 |
| Driver={Microsoft Excel Driver (*.xls)};DBQ=physical path to .xls file;DriverID=790 |
| Driver={Microsoft Paradox Driver (*.db)};DBQ=physical path to .db file;DriverID=26 |
| Driver={Microsoft Text Driver (*.txt;*.csv)};DBQ=physical path to .txt file |
Microsoft Visual FoxPro (with a database container) | Driver= {MicrosoftVisualFoxProDriver};SourceType=DBC;SourceDb=physical path to .dbc file |
Microsoft Visual FoxPro (without a database container) | Driver= {MicrosoftVisualFoxProDriver};SourceType=DBF;SourceDb=physical path to .dbf file |
官网读取sql的范例
DogConn=createOLEObject "ADODB.Connection"DogConn.Open "driver={SQL Server}; server=dsqedb01.autodesk.com; database=MXSTest"
recordSet = createOLEObject "ADODB.Recordset"recordSet.Open "SELECT * from TestTable" DogConn 1 3 -- adOpenKeyset adLockOptimistic
fields=recordSet.Fields -- print out column namescount = fields.countfor i = 1 to count do (local item = fields.item (i-1);
print item.name)recordSet.GetRows() -- display current contents
recordSet.AddNew #("arbitraryFloat", "arbitraryChar", "boolean", "arbitraryInt") #(pi,"Hello World",true,42) -- add via array
recordSet.AddNew (SafeArrayWrapper #("arbitraryFloat", "arbitraryChar", "arbitraryInt")) (SafeArrayWrapper #(e/pi,"Merry xmas!", 54321)) -- add via SafeArrayWrapper
recordSet.close()recordSet.Open "SELECT * from TestTable" DogConnrecordSet.GetRows() -- display current contents
----------------------------------------------------------------------------------
接下来看看我写入access数据库,access数据库是以mdb结尾的数据库文件,用微软access可以打开
先放出数据库结构吧
.selectTdClass{background-color:#edf5fa !important}table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}table{margin-bottom:10px;border-collapse:collapse;display:table;}td,th{padding: 5px 10px;border: 1px solid #DDD;}caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}th{border-top:1px solid #BBB;background-color:#F7F7F7;}table tr.firstRow th{border-top-width:2px;}.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }td p{margin:0;padding:0;}
程序数据库操作代码:
DogConn1 = createOLEObject "ADODB.Connection"
DogConn1.Open "driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=F://WORKS/3dmax/BIPED/anim.mdb"
recordSet1 = createOLEObject "ADODB.Recordset"-------------连接数据库
recordSet1.Open "SELECT * from wenjian" DogConn1 1 3 -- adOpenKeyset adLockOptimistic
fields=recordSet1.Fields -- print out column names
count = fields.count
for i = 1 to count do (local item = fields.item (i-1); print item.name)
recordSet1.GetRows() -- display current contents
recordSet1.AddNew #("fenlei1","fenlei2","fenlei3", "mingzi", "dizhi") #(fenlei1,fenlei2,fenlei3,mingzi,dizhi) -- 写入数据
。。。。。。。。。。。。。。。。。。。。。。。。。省略。。。。。。。。。。。。。
bip1 = $.controller
max motion mode
--File I/O
biped.saveBipFile bip1 (dizhi)
messagebox "成功"
插件最终效果如图,点击保存就会把biped文件存储到本地并写入数据库,然后只需要相应调用加载bip就可以了!非常方便,不需要你再一个一个慢慢寻找导入bip文件
下载地址:下载插件
这个插件是添加动作有配套的另一个负责加载动画