Max geometry esporter in C#


#21

ok, this is very nice but you are running too, i ask a little example of c# or a step by step example to avoid a lot of incomprehension :slight_smile:

So, i read the Lesson7 example found in internet, i compiled this dll and in max work:
http://dl.dropbox.com/u/47659776/ClassLibrary2.rar
and maxscript loading:


   pathdll = @"C:\Documents and Settings\Admin\Desktop\ClassLibrary2.dll"
   clearListener()
   dll = dotnet.loadAssembly pathdll
   esp = dll.createInstance("AutodeskMaxDllDemo.NodeReport")
   showMethods esp
   showProperties esp
   esp.GetReport()
   
and return:
"Node Scene Root
   	Node Box001
   "
   OK

Now:

  1. the Autodesk.Max.dll must be installed in the max root installation folder ?
  2. these dll work for max2011 32 bit, but for all other version of max ?
  3. how can i get the geometry data like yout C++ code ? i want a maxscript new function example :
nodegroups = selection as array
   fout =  fopen "esportmesh.bin" "wb"
   meshdata =  dll.createInstance("GameMesh.meshdata")
   meshdata.getdata nodegroups
   meshdata.writetofile fout
   fclose fout.

we must resolve this question before continuing, for my purpose i need only some basic informations with c# code:
A) Pass a node , editmesh, editpoly as function parameter
B) Use the corresponding maxscript function like getVerts , getFace , ecc…
C) Use the corresponding maxscript modifier to get the Edit_Normal data, Skin data ecc…

:buttrock:


#22

and an off-topic question: why maxscipt lock the dll file ? i’m try to delete the ClassLibrary2.dll but is running in max, i write in maxscript “gc light:on” (i use it to kill some file not correctly closed) but nothing , so i unkock it with Unlocker.exe but nothing…
I must close max every time i compiling a new dll ?


#23

instead of dotnet.loadassembly path use

(dotnetclass "System.Reflection.Assembly").Load ((dotnetclass "System.IO.File").ReadAllBytes path)

#24

Thanks, i will try…
After 1h of test i found finally a interessant function to work with max nodes:


 		public static String GetNodeName(uint handle)
 		{
 			IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
 			IInterface13 Interface = Global.COREInterface13;
 			IINode theNode = Interface.GetINodeByHandle(handle);
 			return theNode.Name;
 		}

#25

thanks, now i can delete the dll witout close max

according with Max SDK i tried to get the IMesh from a IINode, but i can’t undestand the ConvertToType parameters… why don’t exist a SDK documents in C# ???:bounce:

		public static String GetTriMeshFromNode(uint handle)
		{
			int t = 0;
			IGlobal Global = Autodesk.Max.GlobalInterface.Instance;
			IINode node = Global.COREInterface13.GetINodeByHandle(handle);
			
			IObject obj = node.EvalWorldState(0,true).Obj;

			if (node.ObjectRef.SuperClassID != SClass_ID.Geomobject) return ("SuperClass : " + node.ObjectRef.SuperClassID.ToString() + " not valid");

			IMesh mesh = obj.ConvertToType(t, IClass_ID ?!?!?!?!?);

			return mesh.GetVert(0).ToString() ;

		}

#26

you found it in fn get_method1 in geometry_class.ms but:

i’m trying to translate the Max SDK C++ example into C# code without success… in internet (http://www.ephere.com/autodesk/max/) where are some little fragments of source code or, always, an plugin extension what i can do the same thing in maxscript… but nothing else.

The Topic question is this:
"Someone can write with C# an example to use a function similar to maxscript’s function with which get the maxscript’s parameters (example nodes, point3 ,mesh, materiale ecc…) witout plugin or similar class extension?"

the C# source code what i did work only with some “System” value like “Int32”, “String”, “Short” ecc… or conversion do into maxscritp example:
BytesArray = dotnet.ValueToDotNetObject #(1,2,3,4,5,6,7,8,9,…) (dotNetClass “System.Byte[]”)

I see axample the “15. From C++ to Maxscript and vice versa” of “3DSMAX_SDK_DavidLanier.pdf”


#27

So what exactly is the problem with using the C++ SDK documentation? The C# wrapper is not going to be different from that with only a few minor exceptions. I guess the bottom-line is that the SDK is very convoluted and difficult to get in to, regardless of whether you’re using C++ or C#. The core concepts will be quite easy and straightforward, but there are a lot of things around a plugin which you’ll have to get exactly right to make it work.

As for making a gup that exposes functions to maxscript: the David Lanier book is a little bit outdated in that respect. It will be easier to do this using function publishing. That is a reasonably well documented topic in the SDK documentation too.


#28

exemple: can you made in C# the example found in “15. From C++ to Maxscript and vice versa” ?


#include "Maxscrpt\Maxscrpt.h"
#include "maxscrpt\Strings.h"
#include "maxscrpt\arrays.h"
#include "maxscrpt
umbers.h"
#include "maxscrpt\maxobj.h"
#include "maxscrpt\definsfn.h"
def_visible_primitive(MyFunction, "MyFunction" );
Value* MyFunction_cf(Value** arg_list, int count)
{
return &false_value ; //return the Maxscript false value
}

i have tried to compile a c++ dll with maxsdk but don’t work, there are a lot of error during compiling in Maxscrpt.h…, and 3dsPluginWizard in Visual Studio express give me a “Access denied” ??? with c# and Autodesk.max.dll i resolve a lot of issue but i can’t understand now traslate the sdk documentation… why is so difficult ???

this is the only thing what work:


using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Max;

namespace ClassLibrary
{
	public class MyClass
	{
		//some test
		public String GetNodeName(uint handle)
		{
			IGlobal global = Autodesk.Max.GlobalInterface.Instance;
			IINode node = global.COREInterface13.GetINodeByHandle(handle);
			return node.Name;
		}
		public int GetTimeValue()
		{
			IGlobal global = Autodesk.Max.GlobalInterface.Instance;
			int t = global.COREInterface13.Time;
			global.TheListener.EditStream.Printf(t.ToString() + "
", null);
			return t;
		}
	}
}


#29

Also with Max.NET tutorials don’t work nothing… compiled the test.dll, put into plugins folder, load with


 mytestfn = (dotNetObject "MyProject.MyPlugin").MyTestFunction
 mytestfn $ 1
 

and always – -- runtime error , no method found which matched argument list

using System;
 using System.Windows.Forms;
 using System.ComponentModel;
 using System.Collections.Generic;
 using System.Data;
 using System.Text;
 using Autodesk.Max;
 
 namespace MyProject
 {
 	public class MyPlugin : IPlugin
 	{
 		/* into maxscript write this to instanciate the function
 		 * mytestfn = (dotNetObject "MyProject.MyPlugin").MyTestFunction
 		*/
 		public void Cleanup() {}
 		public void Initialize(IGlobal global, ISynchronizeInvoke sync) {}
 		public void MyTestFunction(IValue val, int count)
 		{
 			MessageBox.Show("Didn't work");
 		}
 	}
 }

Now can i pass a **** parameters ??? i test all possible parameters…


#30

Somewhat off topic, I tried this again, and I can load the reflection just fine from what I can tell, but when I go to create and Instance, it returns undefined.

Im calling my namespace and form1 like I do with my normal loadassembly?

 
wee = dll.CreateInstance( "turboTools.ObjectPlacer.form1")


#31

Is the casing correct?


#32

Ya, it’s copied from my other one that works


#33

hae you take a look at http://forums.cgsociety.org/showthread.php?f=98&t=1020505&page=2&pp=15 ?
have you compiled in framework 2.0 ? the 3dstdio 64 bit have a lot of problem.


#34

Hm… Yes, it is Dotnet 2.0 I’m pretty sure, compiled as 64bit for 64bit Max.

I could try to compile as 3.5 or something and see if it works?


#35

uhm, give me source code, because i think the problem is the 64bit version, i have max32 and 64 also, and 64 do a lot of problem with dll…


#36

I have 32 and 64bit as well. I will try those later.


#37

Hi i tried to build a kind of conversion from maxsript and csharp’s dll, passing a DotNet array of point can be in my opinion a good solution to exchange some basic geometry data.

fn main =
(
	clearlistener()
	dll = dotnet.loadAssembly "my.dll"
	Point3Class = dotnetclass "Test.Point3Class"
	VertexCont = 10
	Vertex = dotnetobject "Test.Point3Class[]" (dotNetObject "System.Int32" VertexCont)
	
	-- C# is zero based !
	for n=0 to VertexCont-1 do
	(
		local Pt = dotnetobject "Test.Point3Class" (n*3+1) (n*3+2) (n*3+3)
		local Idx = dotNetObject "System.Int32" n -- in max9 32bit using Idx = n is the same
		format "set>P% [%,%,%]
" n Pt.x Pt.y Pt.z
		Vertex.Set Idx Pt
	) 
	for n=0 to VertexCont-1 do
	(
		local Idx = dotNetObject "System.Int32" n
		local Pt = Vertex.Get Idx
		format "get<P% [%,%,%]
" n Pt.x Pt.y Pt.z
	)
	OK
)

main()

and this the C# code (compile as dll library with Visual C# 2005 express)


using System;
using System.Collections.Generic;
using System.Text;

namespace Test
{
    public class Point3Class
    {
        public static float x = 0;
        public static float y = 0;
        public static float z = 0;
        public Point3Class(float X ,float Y,float Z)
        {
            x = X;
            y = Y;
            z = Z;
        }
        public float length()
        {
            float sq = (x * x) + (y * y) + (z * z);
            return sq;
        }
    }
    public class TheClass
    {
        public float Test(Point3Class[] vertex)
        {
            float accum = 0;
            for (int i = 0; i < vertex.Length; i++)
            {
                accum += vertex[i].length();
            }
            return accum;
        }
    }
}

but don’t work because all Points printed have the same value ??? And i’m not sure that i’ve written is corect :wink:


#38

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.