[Closed] 3ds max sdk .NET
Hello,
I’m trying out 3dsmaxsdk .NET, is there anyone who would be interested?
Due to lack of documentation it looks more like cryptoanalysis but I already have some results.
for beginning:
my notes
and
eventLister – testing tool for callback and events
Do you have any own knowledge of .net sdk? Want to share?
Links, github repos, pieces of code are welcome.
Hello This is ammazing!
We are trieng to write 3d max listener. We need to listen all we can.
Could you help with writeing such Listener?
Do you know, How to get the the object properties from C# in Visual studio?
What exactly do you expect? For catching 3dsmax callbacks and events you can use:
a/ pure c# solution – clone this https://github.com/pavel-mxsf/EventLister , i thing it’s a good start point
b/ create public class in c#, compile to .dll, load with maxscript (dotnet.loadassembly “xxx.dll”), create instance of your dotnet class in maxscript (obj = dotnetobject “namespace.classname”) and use maxscript callbacks (see General Event Callback Mechanism in help) and Node Event System to call methods on your obj.
to get informations about objects in case A – it’s possible to get IINode objects from callbacks parameters (and see ObjRef property on inode – there are class specific things)
for B – maxscript way you can pass numbers, strings, booleans etc to dotnet so some wrapper should be used. or pass object .handle as parameter and find that object in dotnet with Autodesk.Max.IINode GetINodeByHandle(uint handle)
FYI “attach to process” in VS and debugger works – it helps a lot (breakpoints, watches). (you need to attach to 3dsmax.exe)
I like the idea very much.
- Comparing class_ID
- Retrieving values from an mxs call (fpvalue)
// Comparing class_ID
// Assuming "node" is a IINode value
if (node.ObjectRef.SuperClassID == SClass_ID.Camera || node.ObjectRef.SuperClassID == SClass_ID.Light)
{
[...]
}
// Retrieving values from an mxs call, here we're retrieving nodes
// See Visual Studio Object explorer for other value types (NTab, ITab, STab, BTab, etc)
string mxs = "objects as array";
IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
IFPValue sceneNodes = Global.FPValue.Create();
Global.ExecuteMAXScriptScript(mxs, false, sceneNodes);
for (int i = 0; i<sceneNodes.NTab.Count; i++)
{
IINode node = sceneNodes.NTab[(IntPtr)i];
[...]
}
It’s a shame this thread is so dead…
I don’t know if anyone can help me. I need to retreive the values given by an IntPtr value.More exactly:
for an IPolyLine, there are two properties that return an IntPtr value:
- IntPtr Lengths (Cached lengths for each point.)
- IntPtr Percents (Cached percentages for each point.)
How can I read/use/know what these Lengths or Percents are using this IntPtr value?
Thanks a lot.
You will probably need to Marshal those pointers into a .NET wrapper. But from my experience, not all the C++ SDK Classes have been fully ported to Autodesk.Max .NET SDK. Where are you getting this pointers from?
Cheers,
I have passed a shape by its handle to C#. There, I extract the first spline of the shape and convert it to IPolyLine.
This IPolyLine has these two properties or attributes (‘Percents’ and ‘Lengths’) that return an IntPtr pointer that I suppose points to a floatTab (ParamType2 = 2048 I think).
I need to read these float values, but I don’t know how to get them from these pointers (my knowledge of SDK and C# is just a few days practice).
Thanks a lot for your help, @dgsantana. Obrigado.
Ok, from the C++ SDK, this are trully float pointers, so to make them useful in C#, you can convert the IntPtr to a float array.
var lens = new float[pl.Verts];
Marshal.Copy(pl.Lenghts, lens, 0, pl.Verts);
EDIT: Forgot to say that that “pl” should be your IPolyLine.
I haven’t test this, but should be something on this lines.
Works like a charm! Thanks a lot, @dgsantana.
What’s the whole sense of the ‘Marshall’ class/instruction? All this is too hard for me.
By the way… I have found by chance another way, of course worse than yours:
int numsegments = pl.Segments;
IntPtr percents = pl.Percents;
IFPValue percentsList = Autodesk.Max.GlobalInterface.Instance.FPValue.Create();
percentsList.InitTab((ParamType2) 2048, 0); // 2048 == floatTab
percentsList.FTab.Append(numsegments, percents, 0);
for (int i = 0; i < percentsList.FTab.Count; i++)
{
float myPercent = percentsList.FTab[(IntPtr)i];
[......];
}
Great, glad it word out. The Marshal class is used to “communicate” between the unmanaged world (pointer world) and the .NET managed one. In C#, most people don’t know but it’s possible to write code similar to C, (the reason for the unsafe block and flag), using pointers, and bypassing the .NET type system, of course this should only be done for performance reasons or integration with some C/C++ code.