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.

Accessing nodes of closed container

Accessing nodes of closed container

elpie89
Advocate Advocate
881 Views
8 Replies
Message 1 of 9

Accessing nodes of closed container

elpie89
Advocate
Advocate

Is there any way to access node material etc of a closed container from code?

I need to do it with c# API but every suggestion valid for other languages could help

Thanks

0 Likes
882 Views
8 Replies
Replies (8)
Message 2 of 9

denisT.MaxDoctor
Advisor
Advisor

What is the problem with open it and close after? I see that you have a reason. But for me the reason is more interesting than the issue.

0 Likes
Message 3 of 9

elpie89
Advocate
Advocate

I'm working on a the BabylonGTLF Exporter

https://github.com/BabylonJS/Exporters

If a user as a max file with many containers referenced?

How should he do?

the only way for what I see is to merge the containers -> export - > and then reimport the containers

But this is not the best solutions for many reasons, one of them is that you lost the position of the container

In my case using the Babylon exporter, many problems are related to Animation Groups

0 Likes
Message 4 of 9

istan
Advisor
Advisor

This will probably end in the same discussion we already had.. 😉

From MXS (and of course C++) everything should be accessible..

0 Likes
Message 5 of 9

elpie89
Advocate
Advocate

if you speak about this

https://forums.autodesk.com/t5/3ds-max-programming/attach-two-mesh-in-c-api/m-p/8932937#M23943

yes the solution was there, actually, if something is accessible from C++ it is also for C#

Of course, will be only more difficult to find.

But in this case, I'm not even sure Autodesk exposed the containers closed nodes in any languages, or at least I can't find it

0 Likes
Message 6 of 9

elpie89
Advocate
Advocate

hei, no solution for this?

0 Likes
Message 7 of 9

denisT.MaxDoctor
Advisor
Advisor

@elpie89 wrote:

hei, no solution for this?


Well... let's start from beginning.

(first of all i don't care about c# API, all that I show is c++ API)

 

You need to get access to IContainerObject what can be done with couple headers:

#include <IContainerObject.h>
#include <IContainerManager.h>

next is to get the  IContainerObject*:

	//INode* node = ...
	{
		if (GetContainerManagerInterface()->IsContainerNode(node))
		{
			IContainerObject* obj = IContainerObject::GetInterface(node->GetObjectRef());
			if (obj)
			{
...

you can't get nodes from closed container, so if it is closed you have to open:

				BOOL open = obj->IsOpen();
				if (!open) obj->SetOpen(true); 

				NodeTab nodes;
				obj->GetContentNodes(get_nested, nodes);
...

and close the container if it was opened by the method...

 

You have to know and understand two things:

#1 - if you open and close containers you will see scene redraw. So take care of this by using disable/enable scene redraw

#2 - when you open closed container the scene "merge" mechanism works, and it wipes Undo history

 

 

Good luck!

 

PS. actually you have to know three things:

#3 - when you close opened by the method container you loose access to the container's nodes. So you have to do all your "export" inside the method 

0 Likes
Message 8 of 9

elpie89
Advocate
Advocate

Ok there is something I'm missing here.

 

Can you open an inherited container? Because from what I see I can only merge

 

I have already implemented a sort of solution like you suggest but using the merge

What I do is:

HoldFile()

merge containers

export the scene

FetchFile()

Evything works, I thought there was a better way to access node from API.

 

 

0 Likes
Message 9 of 9

denisT.MaxDoctor
Advisor
Advisor

@elpie89 wrote:

Can you open an inherited container? Because from what I see I can only merge

 

I have already implemented a sort of solution like you suggest but using the merge

What I do is:

HoldFile()

merge containers

export the scene

FetchFile()

Evything works, I thought there was a better way to access node from API.

 


you can get nodes from a 'nested' (inherited) container. check the method GetContentNodes

 

next...

 

when you merge nodes from container it's almost the same as open the contained (the difference is only that you can merge for opened containers as well). But merging has the same issue - wiping the undo stack.

 

the exporting action has not to be at the 'middle of work'. usually it has to be done at time 'out for editing'. so the opening of closed containers looks cleaner and safer for me (at least you don't need to Hold and Fetch the scene).

Hold and Fetch might be an option for the export method as well as it can be delegated to user.

 

 

0 Likes