Tag Archives: Max

Max SDK Save (Write) Image (jpg,png,dds etc.) File with C#

Max SDK Save (Write) Image (jpg,png,dds etc.) File with C#

This function writing Image File.Max SDK.Autodesk.Max.dll must be added to references.

/// <summary>
/// This function writing bitmap File
/// </summary>
/// <param name="bitmap">Bitmap properties</param>
/// <param name="global">Your Global</param>
/// <param name="outputPath">File writing location</param>
public void SaveBitmap(IBitmap bitmap,IGlobal global,string outputPath)
{
	IBitmapInfo bitmapInfo = global.BitmapInfo.Create();
	bitmapInfo.SetName(outputPath);
	
	//Image file format can set using this function
	/*bitmapInfo.SetType(17);
	bitmapInfo.SetDevice("DDS Image File"); */
	
	bitmap.OpenOutput(bitmapInfo);
	bitmap.Write(bitmapInfo, 0);
	bitmap.Close(bitmapInfo, 0);
	global.TheManager.DelBitmap(bitmap);
}

Max SDK Load Bitmap(jpg,png,dds etc.) with .NET(C#)

Max SDK Load Images(jpg,png,dds etc.) with .NET(C#)

This Function is loading textures and showing image height.

/// <summary>
/// This Function is loading textures.
/// </summary>
/// <param name="path">File Location</param>
/// <param name="global">Your IGlobal param.</param>
public void LoadBitmap(IGlobal global,string path)
{
	IBitmap bitmap = global.TheManager.NewBitmap;
	IBitmapInfo bitmapInfo = global.BitmapInfo.Create();
	bitmapInfo.SetName(path);
	global.TheManager.LoadInto(bitmapInfo, bitmap, false);

	MessageBox.Show("Height of image:" + bitmap.Height.ToString());
}

3d Max UV Coordinate C#

3d Max UV Coordinate C#

This Function is return uv coordinate of node.In other words it is return texture vert(Tv) at index.

public class Uv
{
	public float X { get; set; }
	public float Y { get; set; }
	public float Z { get; set; }
}

/// <summary>
/// Return uv coordinate by index
/// </summary>
/// <param name="node">node </param>
/// <param name="coordinateIndex">index of uv array </param>
/// /// <param name="global">IGlobal object.</param>
/// <param name="mapNumber">UVW Map Number</param>
public Uv GetUvCoordinate(IINode node, int coordinateIndex,IGlobal global, int mapNumber = 1 )
{
	IObjectState objState = node.EvalWorldState(0, true);
	IObject iObj = objState.Obj;
	if(iObj == null)
	{
		return null;
	}
	TriObject triObject = (TriObject)iObj.ConvertToType(0, global.TriObjectClassID);

	if (triObject == null)
	{
		return null;
	}

	IMesh mesh;
	mesh = triObject.Mesh_;

	if (coordinateIndex >= mesh.Maps[mapNumber].NumVerts)
	{
		return null;
	}

	Uv uv = new Uv();
	//Uv Array is arranged in a row
	//Texture verts(Tv) has all uv coordinates
	uv.X = mesh.Maps[mapNumber].Tv[coordinateIndex * 3];
	uv.Y = mesh.Maps[mapNumber].Tv[(coordinateIndex * 3) + 1];

	return uv;
}

Get Instance of Node C#

Get Instance of Node C#
This function return only instance of any node.

//global is your start IGlobal object
private Autodesk.Max.INodeTab GetNodeInstances(IGlobal global,IINode node)
{
	IObject obj = node.ObjectRef;
	Autodesk.Max.INodeTab instanceAndRef = global.NodeTab.Create();
	Autodesk.Max.INodeTab result = global.NodeTab.Create();

	global.IInstanceMgr.InstanceMgr.GetInstances(node, instanceAndRef);

	IntPtr indexer ;
	
	for (int i = 0; i < instanceAndRef.Count; i++)
	{
		indexer = new IntPtr(i);

		if (obj.Handle == instanceAndRef[indexer].ObjectRef.Handle)
		{
			result.InsertNode(instanceAndRef[indexer], result.Count, true);
		}

		Marshal.FreeHGlobal(indexer);
	}

	return result;
}

Show,Update,End Progress Bar of Max SDK With C#

Show,Update,End Progress Bar of Max SDK With C#

public uint ProgressBarFunc(ref IntPtr ppContext)
{
	return 0;
}
delegate uint ProgressBarDelegate(ref IntPtr ppContext);

public void ShowProgressBar()
{
        //yourInterface is IInterface of Max SDK ,You can take pointer on BeginEditParams from UtilityObj
	ProgressBarDelegate progressBarDelegate = new ProgressBarDelegate(ProgressBarFunc);
	IntPtr progressBarFunc = Marshal.GetFunctionPointerForDelegate(progressBarDelegate);
	yourInterface.ProgressStart("Progress Started", false, progressBarFunc, IntPtr.Zero); 
        //If false parametre is true ,cancel btn of progress bar will be show.
	yourInterface .ProgressUpdate(0, false, "Progress Update");
	yourInterface .ProgressEnd();
}

Select Instance of Object (Max Script)

Select instances of object
This function is select to instances of any object:

fn selectAllInstanceObj obj=
(
	if(obj == undefined) then
	(
		return format"Object undefined" 
	)
	result = #()	
	instanceMgr.getInstances obj &instances	
	instCount = instances.count 
	
	for i = 1 to instCount do
	(
		areRef = ((obj != instances[i]) and not (areNodesInstances obj instances[i]) )
		if( not areRef) then
		(
			join result  #(instances[i])
		)
	)
	
	select result
)

Max Find Only Instance (C++)

Max SDK and C++

Find any object instance using Max SDK and C++
This code block is returned only instance of objects. IInstanceMgr::GetInstanceMgr()->GetInstances functions is finding any object references and instance.But This functions return only instance.

INodeTab MaxSDK::GetInstances(INode *node)
{
    Object *obj = node->GetObjectRef();
    INodeTab instanceAndRef;
    IInstanceMgr::GetInstanceMgr()->GetInstances(*node, instanceAndRef);
    INodeTab onlyInstance;

    for (int k=0; k < instanceAndRef.Count(); k++)
    {
        if (obj == instanceAndRef[k]->GetObjectRef())
		{
			onlyInstance.AppendNode(instanceAndRef[k]);
		}
    }
    return onlyInstance;
}