Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

MaxScript Create Section with Matrix3 transform

MaxScript Create Section with Matrix3 transform

Anonymous
Not applicable
2,221 Views
11 Replies
Message 1 of 12

MaxScript Create Section with Matrix3 transform

Anonymous
Not applicable

Good day.

 

I am currently porting an old MAX project to a new MAX project (in VS). Part of the code is a script to be run using ExecuteMAXScriptScript(). The MaxScript basically creates a section using matrix3. Here is the snippet of the script:

s = section transform:(matrix3 [p1.x,p1.y,p1.z] [p2.x,p2.y,p2.z] [p3.x,p3.y,p3.z] [p4.x,p4.y.p4.z])

 

Now when I run the old MAX project containing this script, it creates the Section (I check this through the Scene Explorer) with certain dimensions, vertices, curves, etc. 

 

My issue is when I run this using the new MAX project, it also creates the Section but when I check its Properties, the dimensions, vertices, etc are all set to 0. I am expecting the same output as the one from the old MAX project.

 

I also checked that ExecuteMAXScriptScript() returned true which shows that the script ran successfully. Before running the script, I also double check that p1 to p4 are non-zero values. Both projects are in VS2015 and both generated plugins are loaded and tested in 3dsMax 2019.

 

Any leads regarding this issue would be very helpful. Thank you very much.

 

 

0 Likes
Accepted solutions (1)
2,222 Views
11 Replies
Replies (11)
Message 2 of 12

leeminardi
Mentor
Mentor

Not sure if this is the issue as you would probably get an error message but your snippet shows:

[p4.x,p4.y.p4.z]

instead of (comma not period between p4.y and p4.z)

[p4.x,p4.y,p4.z]

 

lee.minardi
0 Likes
Message 3 of 12

Anonymous
Not applicable

@leeminardi wrote:

Not sure if this is the issue as you would probably get an error message but your snippet shows:

[p4.x,p4.y.p4.z]

instead of (comma not period between p4.y and p4.z)

[p4.x,p4.y,p4.z]

 


that's just a typo error. the script contains

[p4.x, p4.y, p4.z]

I am wondering if maybe I am missing some configurations or settings of MaxScript for the new MAX project because in the old MAX project, it works.

0 Likes
Message 4 of 12

denisT.MaxDoctor
Advisor
Advisor

@Anonymous wrote:

I am currently porting an old MAX project to a new MAX project (in VS). Part of the code is a script to be run using ExecuteMAXScriptScript(). The MaxScript basically creates a section using matrix3. Here is the snippet of the script:

s = section transform:(matrix3 [p1.x,p1.y,p1.z] [p2.x,p2.y,p2.z] [p3.x,p3.y,p3.z] [p4.x,p4.y.p4.z])

Just curious what is the reason for creating a Section instance via SDK in this such an intricate way?

0 Likes
Message 5 of 12

Anonymous
Not applicable

As I've mentioned, we are just porting an old project to a new one. We are actually not touching much of the way they implemented the MaxScript parts in the code. But I am guessing that this was implemented this way because of the Matrix3? It seems to be the only input data to use for creating the Section. I am not very familiar with MaxScript and if you have other simpler/better ways that this can be implemented, it would be of great help and would be tremendously appreciated.

 

I am thinking if maybe I am missing some important configurations/setup needed for MaxScript in the new VS project? Because it just seems weird that this script is working on the old VS project and not with the new VS project. Both project plugins (old and new) are loaded and tested in 3ds Max 2019.

 

Thank you!

0 Likes
Message 6 of 12

denisT.MaxDoctor
Advisor
Advisor

Of course, you can create an instance (and node) of the Section object and set to node the transform you need. You do not need to call MaxScript to do this.

You can get the сlassid of Section class by looking at the "section.cpp" file from the SDK examples.

After you know the identifier, you can create a section object using CreateInstance.
After that create the node using CreateObjectNode, and then set the transformation of this node using SetNodeTM.


That's all

 

 

 

Message 7 of 12

Anonymous
Not applicable

Hi @denisT.MaxDoctor . Thank you for your suggestion. I tried it and this is what I came up with:

 

Object* obj = static_cast<Object *> (CreateInstance(SHAPE_CLASS_ID), Class_ID(0x20b9236d, 0x66da18aa));
INode* s = GetCOREInterface()->CreateObjectNode(obj);
s->SetNodeTM(GetCOREInterface()->GetTime(), inputMatrix);

I used the code above in the new VS project and checked the created node through the Scene Explorer. It still has zero values for its properties (dimensions, vertices, curves, etc). I also used the code above in the old VS project and it created the node with expected properties (non-zero values). 

 

Based on this observation, I believe I may be missing some initialization or configuration or setup for this section creation. But I already checked the old VS project and it contains/shows no initialization part for the section creation.

 

Any tips on where these values are usually tweaked/initialized when created as an object? 

Thank you very much!

 

 

0 Likes
Message 8 of 12

denisT.MaxDoctor
Advisor
Advisor

you do everything right. it remains only to set the length and width (and any other parameters that you need). so, find parameter block and use SetValue... it needs ID. You can use NameToIndex and IndexToID to get parameter ID by name

0 Likes
Message 9 of 12

A012255
Enthusiast
Enthusiast

@denisT.MaxDoctor wrote:



Just curious what is the reason for creating a Section instance via SDK in this such an intricate way?


It saves a lot of development time, as you otherwise would have to write a lot of C++ code for the same feature. Some MXS code lines usually need hundreds of C++ code lines. For complex tasks and when execution time does not matter, I use this approach as well. And you don't need a C++ expert. With C++ you can also better protect your MXS code.

Message 10 of 12

Anonymous
Not applicable

Hi @denisT.MaxDoctor . Unfortunately, there are no more parameter blocks to be used as input.

Object* obj = static_cast<Object *> (CreateInstance(SHAPE_CLASS_ID), Class_ID(0x20b9236d, 0x66da18aa));
INode* s = GetCOREInterface()->CreateObjectNode(obj);
s->SetNodeTM(GetCOREInterface()->GetTime(), inputMatrix);

This same snippet, when built and compiled in the OLD VS project, automatically generates non-zero values for the properties (length, width, vertices, curves, etc) but when built and compiled in the NEW VS project, generates zero values for the properties.

 

Is it expected that the generated node by this snippet only will have zero values for the properties? Because if it is the expected behavior, then I must really be missing some setting/initialization for object creation in the NEW VS project.

 

I already scoured/traced the code flow and cannot find any files/methods which explicitly set the values of the created object's properties (dimensions, faces, curves, vertices, etc).

 

Any tip on where the created object's properties are usually set on in a C++ Max Utility project? I might have missed some locations. 

 

Thank you!

0 Likes
Message 11 of 12

istan
Advisor
Advisor

@Anonymous wrote:

 

Any tip on where the created object's properties are usually set on in a C++ Max Utility project? I might have missed some locations. 


As DenisT already wrote: search for SetValue()..

0 Likes
Message 12 of 12

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

Section is an old Object and as many old objects it is based on IParamBlock... 

It's a dirty code how to make a Section node and set name, transform, width, and length:

INode* CreateSectionShapeNode(MSTR name, Matrix3 transform, float length, float width)
{
	Object* obj = (Object*)CreateInstance(SHAPE_CLASS_ID, Class_ID(0x20b9236d, 0x66da18aa));
	TimeValue t = MAXScript_time();

	ReferenceTarget* refobj = obj->GetReference(1);
	if (refobj && refobj->SuperClassID() == PARAMETER_BLOCK_CLASS_ID) 
	{
		IParamBlock* pb = (IParamBlock*)refobj;
		pb->SetValue(0, t, length);  //PB_LENGTH
		pb->SetValue(1, t, width); //PB_WIDTH
	}

	INode* node = GetCOREInterface7()->CreateObjectNode(obj, name);
	node->SetNodeTM(t, transform);

	obj->NotifyDependents(FOREVER,PART_ALL,REFMSG_CHANGE); 

	return node;
}

it shows all basic and necessary steps to make a Section. Use it as a quick test  

 

0 Likes