Notifications
Clear all

[Closed] Plugins – How to write?

Hi! Thanks a lot. This works.
I have written know my function which calculates the collisons of the program. And now I have two problems. I have made a function which should call my function. This function gets the parameter of maxscript. It’s the following:

def_visible_primitive(Collision, “Collision”);
Value* Collision_cf(Value** arg_list, int count)
{
type_check(arg_list[0], Array,”[animation_paths]);
type_check(arg_list[1], Array, “[radius]);

Array* animation_paths = static_cast<Array*>(arg_list[0]);
Array* radius = static_cast<Array*>(arg_list[1]);

This is the begin of my function. My problem now is that the animation_paths array is a two dimensional array and I want that this will be from type Point3. Is this possible? In maxscript I get the animation_paths and save them into a two dimensional array. Is this array from type point3?
The radius arry should be a two dimensional array of type float.
How can I code this? That I have the right types instead of the type Array*.

My second problem is that I want to give back 2 two-dimensional arrays to maxscript. How can that be done. Now it gives back a value from type Value*. Or does maxscript gives only pointer instead of the arrays so that the arrays are automatically changed?

Thanks a lot
cgneuling

I believe you can get an element from the array and type cast it to type point3 but not sure how. As for the function returning type Value*, just about all of max’s data type are derived from the Value class and arrays are one of them so returning an array should be fairly straight forward. You will need to store the data you want to return in the sdk’s Value / Array data type so you can return it easily.

Hi!
Thanks. I have made it to get the values. Now all I need to finish my program is to give back a two dimensional array. I tried the following code:


Array* arg_list3;
	
	for(int i = 0; i < object_array_size; i++)
	{
		Array* lol;
		for(int j = 0; j < animation_paths_size; j++)
		{
			lol->data[j] = (Value*)visibility_vec[i][j];
		}
		arg_list3->data[i] = lol;
	}
	return arg_list3;

the visibililty_vec is an two dimensional array of type float. The problem is that it is not allowed to convert float to type Value*. Or is there an other option to convert ? I tried also static_cast but this was also not allowed.

Take a look at MaxSDK Help, on MaxScript section and Casting/… subsection:

Here is a casting example:
Quote:


one_typed_value_local(Array* rArray); 
vl.rArray = new Array (steps); 
float data = begin; 
float increment = ((end-begin)/steps); 
for (int i = 0 ; i <= steps ; i++) 
{ 
	Value* aTempNumber = Float::heap_intern(data); 
	vl.rArray->append(aTempNumber); 
	data += increment; 
} 
 
return_value(vl.rArray);
 

I think it might be easier to use the function publishing macros and interfaces. That takes care of most casting issues for you. And I’ve found it to be less prone to import and define statement order errors.

Ok. Thanks for your help is this now for a one dimensional float array? Can I give also back a two dimensional float array AND a two dimensional point3 array? If so how can I do this? If I have an array with the name “position” and its a two dimensional array. Can I give it back with the following code? If so how can I give two two dimensional arrays? Thanks a lot What does float::heap_intern ?

one_typed_value_local(Array* rArray); vl.rArray = new Array (steps);
vl.rArray2 = newArray(steps2); float data = begin; float increment = ((end-begin)/steps); for (int i = 0 ; i <= steps ; i++) {
for(intj = 0; j <= steps2; j++)
{
Value* aTempNumber = Float::heap_intern(position[i][j]); vl.rArray->append(aTempNumber); data += increment;
}
vl.rArray2->append(vl.Array);

} return_value(vl.rArray2);

All non-static instances of the Value class family should be heap-allocated with the ‘new’ operator or one of the following intern() functions so that garbage collection will work.

Why you don’t take a look at documentation…

About the bidimensional array I think its posibile, but didn’t try it.
It should be something like, but not sure of correctness.


 
one_typed_value_local(Array* rArray); 
vl.rArray = new Array (nrRows); 
for (int i = 0 ; i < nrRows; i++) 
{ 
   vl.rArray->append(new Array(nrCols));
   for (int j = 0; j < nrCols; j++) {
   Value* aTempNumber = Float::intern(position[i][j]);   
   vl.rArray[i]->append(aTempNumber); 
   }
} 
return_value(vl.rArray);

 

does this mean that i can write for a two dimensional array of type float the following if “position” is the name of the array? if so how can I give back two two dimenaional arrays? What does heap_intern do? Thanks a lot
one_typed_value_local(Array* rArray);
one_typed_value_local(Array* rArray2);
vl.rArray = new Array (steps);
vl.rArray2 = new Array(steps2);
float data = begin; float increment = ((end-begin)/steps); for (int i = 0 ; i <= steps ; i++) {
for(int j = 0; j <= steps2; j++)
{
Value* aTempNumber = Float::heap_intern(position[i][j]); vl.rArray->append(aTempNumber);
}
vl.rArray2.append(vl.rArray);
}
return_value(vl.rArray2);

sorry. i pushed the enter button.
@spider853: thanks for the answer. I will try that. Do you know if it is also possible to give two arrays back?

1 Reply
(@spider853)
Joined: 10 months ago

Posts: 0

what do you mean? 2D array of 2xn elements? if not I don’t think so, because max returns only one value from function, maybe getting variables by reference, but I’m not sure how to work with references.


one_typed_value_local(Array* rArray);
one_typed_value_local(Array* rArray2);

According to documentation its enough to protect one value from garbage collector, and other values connected to this value will be protected too. (if I’m not wrong)

QUOTES FROM DOC:

There can be only one value_local declaration macro per C++ block.

there is no multiple-value return mechanism in MAXScript.

As with all Value creation inside C++ code, a freshly created array must be protected from garbage collection, either by placing it immediately inside some other protected value, or by using the protection macros described in the Protecting Newly Created Values from the Collector topic.

P.S. Why don’t you read this section of documentation? Its only a few pages but has the answers to the most your questions.
Use the 3ds max 2009 SDK chm, or the last CHM documentation

If I write FLOAT:: intern(positon[i][j]) I get the message: FLOAT must be a class or namespace when following by :: and intern is not a member of global namespace. Do I nead specific header files?

1 Reply
(@spider853)
Joined: 10 months ago

Posts: 0

#include “MAXScrpt.h”

#include “Numbers.h”// for handling of MAXScript Integers and Floats

#include “Arrays.h”

Page 2 / 3