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的更多相关文章

  1. 【转】MaxScript.Net接收本地端口的消息执行

    MaxScript里开不了线程,但是可以用.Net的BackgroundWorker来做后台处理 BackgroundWorker Fn BackgroundTcpListenerDoWork the ...

  2. MaxScript重启3dsMax的重新思考

    前天看到一位大神写用MaxScript实现重启3dsMax的方法,用的是.net临时编译一个exe出来,然后用这个新的进程来关闭并开启新的max.感觉这种思路不错,或许可以用在别的地方.不过谈及max ...

  3. 关于 MAXScript 拷贝文件夹及内容到其他位置

    之前用 hiddenDOSCommand 本机测试通过,但是换其他电脑有时会不能用... fn xcopy oldfile newfile = ( newfilepath = newfile + &q ...

  4. 关于如何获取/清除 MAXScript 侦听器内的文本

    关于如何获取/清除 MAXScript 侦听器内的文本 用来保存记录?还没想到实际用处,先记上. macroRecorder as string listener as stringclearList ...

  5. 关于 MAXScript 中文路径返回上级目录(精简版)

    之前写过一个 关于 MAXScript 中文路径返回上级目录 的博文 今天无意中发现了一个更简单的方法 代码如下: fn newfile filepath = ( nf = getfilenamepa ...

  6. 关于 MAXScript 如何剪切文件夹

    MAXScript 中可以对文件进行创建删除复制等操作但是唯独不能删除文件夹... 网上搜了一下批处理的剪切方法,在 MAXScript 里调用一下就好了 fn xcopy oldfile newfi ...

  7. 关于 MAXScript 逐行写入文本

    官方帮助文档FileStream Values部分有相关介绍. fn format_txt filepath filetext = ( if doesFileExist filepath == tru ...

  8. 关于 MAXScript 获取全部文件

    MAXScript 官方文档里关于获取文件夹下所有文件的方法 fn getFilesRecursive root pattern = ( dir_array = GetDirectories (roo ...

  9. maxscript, 批量导出物体

    1,将场景中所有选中物体整体导出为一个fbx文件 exportfile filename #noprompt selectedOnly:true using:FBXEXP 2,将场景中所有选中物体各导 ...

  10. maxscript, 数组和字符串下标是从1开始的

    maxscript中数组和字符串下标是从1开始的.

随机推荐

  1. Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力

    C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...

  2. C++ ADO 数据查询

    ADO 数据查询 关键点 上1条 下1条 第1条 最后1条 实现过程 // stdafx.h : include file for standard system include files, #im ...

  3. java 覆盖hashCode()深入探讨 代码演示样例

    java 翻盖hashCode()深入探讨 代码演示样例 package org.rui.collection2.hashcode; /** * 覆盖hashcode * 设计HashCode时最重要 ...

  4. Android播播放完SD卡指定文件夹音乐之后,自动播放下一首

    最近做一个项目,需要连续播放音乐,播放完一首歌之后,自动播放完下一首歌.不要重复播放. 代码如下: package com.example.asyncplayer_ex; import java.io ...

  5. 使用Active MQ在.net和java系统之间通信

    ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现 一.特性列表 ⒈ 多种语言和 ...

  6. SSL连接建立过程分析(1)

    Https协议:SSL建立过程分析 web訪问的两种方式: http协议,我们普通情况下是通过它訪问web,由于它不要求太多的安全机制,使用起来也简单,非常多web网站也仅仅支持这样的方式下的訪问. ...

  7. iOS开发——UI篇OC篇&UIView/UIWindow/UIScreen/CALayer

    UIView/UIWindow/UIScreen/CALayer 1.UIScreen可以获取设备屏幕的大小. 1 2 3 4 5 6 7 // 整个屏幕的大小 {{0, 0}, {320, 480} ...

  8. day01 Java基础

    1.Win7中,在某目录下:shift+右键->在当前目录打开命令行窗口. Windows中打开画图工具的命令是:mspaint. 2.Windows DOS下“rd *”是删除目录的命令:“r ...

  9. Spark之路 --- Scala IDE Maven配置(使用开源中国的Maven库)和使用

    为什么要使用Maven 摘自百度百科的介绍 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具.Maven 除了以程序构建能力为特色之外,还提 ...

  10. iOS开发:获取设备IP地址

    一.导入头文件 //首先导入头文件信息 #include <ifaddrs.h> #include <arpa/inet.h> #include <net/if.h> ...