Kstudio plugins has MAXScript API, which can be used for solutions to your specific tasks.
This reference to understand how to use and develop a connection or automation with Kstudio plugins.
Note: you can find additional examples in the directory “presets”
If you want to expand the Kstudio plugin capabilities with the API and don’t own knowledge of maxscript please refer to email support@3d-kstudio.com

API for Project Manager, Models Manager and Materials Manager

This is the main API struct for Kstudio Managers plugins.
Can be used for adding a custom menu item – see more
GetSelectedItemsInfo IncludeMaps:<bool> IncludeThumbs:<bool> - Returns the Array of struct for Selected Items
IncludeMaps : bool
    Returns the Array of external files, used by item
    (Available for Materials and 3ds Max files(max file must be saved in 3ds max version 2010 or above))
    Returns a path to file, which used for preview

Each element has next properties:
Item : String or MAXObject
    Returns a path to file or Material/textureMap
Assets : Array 
    Array of external files, used by item (IncludeMaps must set to true)
Thumbnail : String
    Returns a path to file, which used for preview (IncludeThumbs must set to true)

RemoveSelection() : void
    Removes Selected Items only from ListView (without any changes for files on HDD!)

Refresh() : void
    Refresh all items in ListView

SaveScreenShot file : void
    Save a screenshot from active viewport to file

CurrentFolder : String
    Returns a path to current directory (or path to material library file)

ConvertToProxy &objectsArray proxyFileName proxyClass - Convert nodes to single Proxy
objectsArray : Array
    Array of nodes for converting to proxy
proxyFileName : String
    Full path to save newly created proxy ( possible be without extension )	
proxyClass : MAXClass
   classOf of target proxy. 
   Set to undefined for convert to proxy which compatable with active renderer

Incomplete list for some supported proxies
classOf of Proxy
 Mental Ray
SelectedStruct = PMStructureInfo()

SelectedStruct.CurrentFolder => "C:\Temp\"

file = @"C:\Temp\Screen.jpg"
SelectedStruct.SaveScreenShot file


selectedItems = SelectedStruct.GetSelectedItemsInfo() 

/* get array of files from selectedItems */
selectedFiles = for item in selectedItems collect item.Item

/* or Array of selected materials from opened Material Library */
selectedMats = for item in selectedItems where superClassOf item.Item == material collect item.Item

/* print array of external files, used by item */
for item in selectedItems do (
    format "%\n" item.Item
    format "Asset Files:\n"
    for file in item.Assets do 
        format "\t%\n" file
Asset Files:
Use this function for filtering merged objects, setting a desired name for objects or other operations.
PMpostFileMerge &PostMergeStruct File:mergedFile Nodes:MergedObjects ParentNode:ParentNode
    struct of some additional parameters. 
    Now has one parameter: UsePlaceDialog. 
    Set UsePlaceDialog to false for disable the open default Place Dialog after merging.
File : String
    Returns a full path to merged file
MergedObjects : Array
    Array of merged nodes
ParentNode : MAXObject
    In case if nodes is groupped it returns a group head. In case if nodes count equals one it returns a node.
Set desired name for merged nodes
Note: place this script to scripts startup directory
fn PMpostFileMerge &PostMergeStruct File: Nodes: ParentNode: = (
    if isValidNode ParentNode and not isDeleted ParentNode do
        ParentNode.Name = uniqueName (getFilenameFile File)

Function PMpostrFileMerge is deprecated since version 2.70.xx Please use PMpostFileMerge instead.

Batch Render&Relink API

Use this global struct for managing Objects or Materials.
    Returns a full path to current 3Ds Max file or Material Library
    Array of scene objects ( excluding studio's objects )
    Set to true to skip rendering the current file
GetDescription [filename:<filename_string>]:
    Returns the user-specified description for the file.
UpdateDescription [filename:<filename_string>] [description:<string>]:
    Save new description for file.
    Returns the state of current mode as string: #Unknown, #Render, #BeforeRender, #Relink or #Test
    Returns the version of used API 
Save a description for 3ds Max file
if BatchPostScript != undefined and pathConfig.appendPath maxFilePath maxFilename == BatchPostScript.MaxFile and BatchPostScript.GetMode() != #Test do (
	local sceneObjects = BatchPostScript.SceneObjects
	local numFaces = 0;
	local numVerts = 0;
	for obj in sceneObjects where superClassOf obj == GeometryClass do (
		local objMeshInfo = getPolygonCount obj
		numFaces += objMeshInfo[1]
		numVerts += objMeshInfo[2]
	/* Save Description */
	if( numVerts > 0 ) do (
		/* get existing file's description */
		local currentDescription = BatchPostScript.GetDescription BatchPostScript.MaxFile;
		local description = StringStream ""
		format "%\nFaces: %\nVertices: %" currentDescription numFaces numVerts to:description
		/* Save description */
		BatchPostScript.UpdateDescription BatchPostScript.MaxFile (description as string);
		/* Free Memory */
		free description
		close description
	BatchPostScript.SkipRender = true
Example for using GetMode() #BeforeRender:
Rendering from multiply cameras (from version 2.70.xx)
if BatchPostScript != undefined and BatchPostScript.GetMode() == #BeforeRender do (
	local wasCancelled = false
	local sceneObjects = for obj in BatchPostScript.SceneObjects where superClassof obj != camera collect obj
	for c in BatchPostScript.SceneObjects where superClassof c == camera and wasCancelled == false do (
		viewport.SetCamera c
		/* Fit camera focal distance to nodes ( available from version 2.70.xx )*/
		BatchPostScript.FitCameraFov sceneObjects
		/* Render using standard Virtual Frame buffer */
		local bm = (render vfb:true renderhiddenobjects:false netrender:false renderType:#normal quiet:false outputSize:[650,650] cancelled:&wasCancelled)
		if ( wasCancelled == false and classOf bm == Bitmap) do (
			bm.filename = BatchPostScript.MaxFile + "_" + c.Name + ".jpg"
			save bm quiet:true
			close bm
			free bm
	/* disable rendering using 'Batch Render&Relink' */
	BatchPostScript.SkipRender = true

The struct ‘PostScriptInfo’ is deprecated!
Please use the ‘BatchPostScript’ instead.

Related to "MaxScript API"

Leave a Reply

Your email address will not be published. Required fields are marked *