C# to Maxscript
I figured I’d do a quick tutorial about something a little more difficult, but still very important. I’m going to take you step-by-step through integrating a maxscript document and a C# class library so that you can access the powerful and robust features of the dotnet framework in the rather limited environment that maxscript provides. This lets you do such powerful things as access databases, grab web-deployed content, and more. It is my opinion that dotnet connectivity is the best thing to ever happen to maxscript.
This tutorial is written for C# users. However, the themes here apply to any language that is part of the common language runtime (CLR) framework. If you chose to use C++, VB, etc. you should still be able to compile a class library that can integrate in much the same way.
Step 1: Make a new class library project in Visual Studio.
New class library creation.
So from the startup screen in visual studio, go ahead and go to File > New > Project.
Select a C# class library. I’m going to name mine “Maxscript Sandbox”.
Name your library.
Step 2: Write a test class.
Now let’s write a test class for our new class library. In this screenshot I’ve written a very simple class that contains a string you pass on creation. Once the object exists, you can access the name, or you can call a function that provides you with a sentence that includes the name. Simple enough!
Rename the class to TestObject, and fill in the code you see below.
public class TestObject
{
string Name;
public TestObject(string thisName)
{
Name = thisName;
} public string GetLongName()
{
return ("You can call me " + Name + "!");
}
}
Insert some placeholder code.
Step 3: Compile.
From the drop-down along the top bar, change the build mode from Debug to Release. This means that the compiler will optimize the code for fast execution rather than for debugging and trying to find out what the problem is. On that note, I think there exists a way to debug the class from your script. However, it’s outside the scope of this tutorial. If you’re burning to debug, make a console app that wraps your class and tests functionality from there.
Change to "Release" compilation.
Now, hit F6 or go to Build > Build Solution.
Build the solution to a DLL.
Step 4: Call the new object from Maxscript.
I’ve commented a lot of the code in the next image, but it’s actually a lot shorter than it looks. All you have to do is load the new class library you’ve created, instantiate the object, and then do whatever you want with it.
Notice that I’ve moved the .dll file that resulted from building my class library to somewhere shorter. Normally, your class library would compile to a directory within the project folder you selected when you created the project (like C:/…/Maxscript Sandbox/ Maxscript Sandbox/bin/release/Maxscript Sandbox.dll). I’ve moved that file from that incredibly long directory to something more digestable like C:/Temp/Maxscript Sandbox.dll.
Call the library from Maxscript.
dotnet.loadAssembly ("C:\Temp\Maxscript Sandbox.dll")
ThisTestObject = dotNetObject "Maxscript_Sandbox.TestObject" "Burt"
print (ThisTestObject.GetLongName())
When you run this program, and the dll is in the right place, you’ll find that it outputs as though the object was a native max object. However it’s actually running in the dotnet framework. You can read more about creating objects and the syntax surrounding the Maxscript/C# connection in the documentation. This tutorial was just meant to clarify some of the logistical issues surrounding getting it working.
The final output from the script.
Until next time, happy scripting!
C# to Maxscript的更多相关文章
- 【转】MaxScript.Net接收本地端口的消息执行
MaxScript里开不了线程,但是可以用.Net的BackgroundWorker来做后台处理 BackgroundWorker Fn BackgroundTcpListenerDoWork the ...
- MaxScript重启3dsMax的重新思考
前天看到一位大神写用MaxScript实现重启3dsMax的方法,用的是.net临时编译一个exe出来,然后用这个新的进程来关闭并开启新的max.感觉这种思路不错,或许可以用在别的地方.不过谈及max ...
- 关于 MAXScript 拷贝文件夹及内容到其他位置
之前用 hiddenDOSCommand 本机测试通过,但是换其他电脑有时会不能用... fn xcopy oldfile newfile = ( newfilepath = newfile + &q ...
- 关于如何获取/清除 MAXScript 侦听器内的文本
关于如何获取/清除 MAXScript 侦听器内的文本 用来保存记录?还没想到实际用处,先记上. macroRecorder as string listener as stringclearList ...
- 关于 MAXScript 中文路径返回上级目录(精简版)
之前写过一个 关于 MAXScript 中文路径返回上级目录 的博文 今天无意中发现了一个更简单的方法 代码如下: fn newfile filepath = ( nf = getfilenamepa ...
- 关于 MAXScript 如何剪切文件夹
MAXScript 中可以对文件进行创建删除复制等操作但是唯独不能删除文件夹... 网上搜了一下批处理的剪切方法,在 MAXScript 里调用一下就好了 fn xcopy oldfile newfi ...
- 关于 MAXScript 逐行写入文本
官方帮助文档FileStream Values部分有相关介绍. fn format_txt filepath filetext = ( if doesFileExist filepath == tru ...
- 关于 MAXScript 获取全部文件
MAXScript 官方文档里关于获取文件夹下所有文件的方法 fn getFilesRecursive root pattern = ( dir_array = GetDirectories (roo ...
- maxscript, 批量导出物体
1,将场景中所有选中物体整体导出为一个fbx文件 exportfile filename #noprompt selectedOnly:true using:FBXEXP 2,将场景中所有选中物体各导 ...
- maxscript, 数组和字符串下标是从1开始的
maxscript中数组和字符串下标是从1开始的.
随机推荐
- Hibernate中的session对象update方法的使用
使一个游离对象转变为持久化对象.例如以下代码在session1中保存了一个Customer对象,然后在session2中更新这个Customer对象: Customer customer = new ...
- 分析代码的利器 - ctags
比方我们在分析代码的时候,须要看某一个方法或类的定义,我们须要临时跳转过去看一下,然后还能非常方便的回来.这时候ctags就派上用场了. 比方你有一个src目录,先用ctags对其生成索引: ctag ...
- Codeforces Gym 100418A A - A+-B java高精度
A - A+-BTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...
- Maven3.2创建webapp项目过程中问题以及解决方案
用maven组件来创建web项目,maven的好处一大堆,但是在创建项目的时候问题也很多,诸多不顺,网上找了很多资料,貌似都没能解决问题. 环境:jdk1.7.0_80,eclipse4.4,mave ...
- TreeView
添加项目 TreeView1.Items.Add(nil,'ABC'); 删除选中的节点 TreeView1.Selected.Delete; 删除鼠标右键选中的节点 var ...
- delphi 判断是否出现滚动条
delphi 判断是否出现滚动条 if (GetWindowlong(Stringgrid1.Handle, GWL_STYLE) and WS_VSCROLL) <> 0 the ...
- IOS 日期选择
传统方式 一般情况下弹出日期选择的场景是:用户点击UITextField弹出日期选择,关键代码如下: 点击UITextField弹出日期选择 1 2 3 UITextField *textField; ...
- [Angular 2] Value Providers & @Inject
Dependecies aren’t always objects created by classes or factory functions. Sometimes, all we really ...
- [AngularJS] ngModelController render function
ModelValue and ViewValue: $viewValue: Actual string value in the view. $modelValue: The value in the ...
- 天池大数据周冠军分享|附移动推荐算法赛答辩会Top5选手PPT
上周是淘宝穿衣搭配算法大赛开始评测后的第一周,周冠军是来自浙江大学的"FUC AUTH"队.他们在夺得本周冠军之后,还将自己的获胜经验分享给了大家,究竟有什么秘诀呢? 阿里巴巴天池 ...