SiNiScript - MAXScript code samples
īģŋ
SiNiScript MAXScript Samples
The following are a few MAXScript examples to help you understand writing your own scripts.
īģŋ
Tip - Copy and paste the code
To use the below MAXScript samples, copy the whole text, then in 3ds Max open the MAXScript Editor and paste the code into it. Save the MAXScript. To evaluate hit Ctrl+E.
Attach By Parent This MAXScript has been written to incorporate SiNiScript functions. It's designed to attach REVIT objects by their parent objects, ie doors.
-- Created by Josh Gruitt - SiNi Software
listParentsArray = #()
allObjstoAttach = #()
fn getMainParent obj =(
if isValidNode obj then (
if isValidNode obj.parent then (
getMainParent obj.parent
)
else(
if findItem listParentsArray obj == 0 then append listParentsArray obj
)
)
)
fn getAllChildren obj arr =(
if obj.children.count > 0 then (
for o in obj.children do (
appendIfUnique arr o
getAllChildren o arr
)
)
)
allObjs = selection
for o in allObjs do getMainParent o
for i = 1 to listParentsArray.count do (
allObjstoAttach = #(listParentsArray[i])
getAllChildren listParentsArray[i] allObjstoAttach
Si_Mesh.AttachObj allObjstoAttach false 0.0 listParentsArray[i].name
)Forensic - Remove empty layers
------------------------------------------------------------------
-- SiNi Software Example Delete Empty Layers Script
-- Press <CTRL E> to run this from Maxscript Editor
------------------------------------------------------------------
clearlistener()
gc()
try(DestroyDialog _Open_DeleteEmptyLayers_Dlg)catch()
rollout _Open_DeleteEmptyLayers_Dlg "Delete Empty Layers" width:150 height:70(
button Open_Bt "Delete Empty Layers" pos:[5,10] width:140 height:23
label _mesage_chk "" pos:[10,40] width:140 height:23
on Open_Bt pressed do(
local RemoveAmount = Si_Clean.DeleteEmptyLayers()
_mesage_chk.text = ("Delete " + (RemoveAmount as string) + " Empty Layers")
)
)
CreateDialog _Open_DeleteEmptyLayers_Dlg
Sculpt - Attach all mesh objects into one mesh
------------------------------------------------------------------
-- SiNi Software Example Attach Objects Script
-- Press <CTRL E> to run this from Maxscript Editor
------------------------------------------------------------------
clearlistener()
gc()
try(DestroyDialog _AttachObj_Dlg)catch()
rollout _AttachObj_Dlg "Attach Objects" width:150 height:125(
checkbox _Weld_chk "Weld Attached" pos:[10,10] width:110 height:18 checked:true
spinner _Weld_Spn "Weld Threshold: " pos:[10,30] type:#float fieldwidth:38 range:[-100,100,0.001]
checkbox _NewName_chk "Change Name" pos:[10,50] width:110 height:18
editText _New_Name "" pos:[5,70] width:140 height:18 enabled:false
button AttachObj_Bt "Attach Selected Objects" pos:[5,95] width:140 height:23
on _NewName_chk changed state do (
if state == true then(
_New_Name.enabled = true
)
else(
_New_Name.text = ""
_New_Name.enabled = false
)
)
on _Weld_chk changed state do (
if state == true then _Weld_Spn.enabled = true else _Weld_Spn.enabled = false
)
on AttachObj_Bt pressed do(
Objs = selection as array
if _Weld_chk.checked == true then
Si_Mesh.AttachObj Objs _Weld_chk.state _Weld_Spn.value _New_Name.text
else
Si_Mesh.AttachObj Objs _Weld_chk.state 0.0 _New_Name.text
)
)
CreateDialog _AttachObj_Dlg
Unite - Relink missing files in an external 3ds Max file, to a given path
------------------------------------------------------------------
-- SiNi Software Relink Files Maxscript Sample Script
-- Press <CTRL E> to run this from Maxscript Editor
------------------------------------------------------------------
clearlistener()
gc()
try(DestroyDialog _ExtRelinkFiles_Dlg)catch()
Global MaxFileDir = undefined
Global RelinkDir = undefined
rollout _ExtRelinkFiles_Dlg "Relink Files External Max File Maxscript Sample" width:500 height:70(
label _MaxFile_lb "Select Max File" pos:[10,10] width:390 height:23 style_sunkenedge:true
button btn_browseMaxFile "..." pos:[410,10] width:40 height:23
label _Path_lb "Select search Path" pos:[10,40] width:390 height:23 style_sunkenedge:true
button btn_browse "..." pos:[410,40] width:40 height:23
button btn_Relink "Relink" pos:[455,40] width:40 height:23 enabled:false
on btn_browseMaxFile pressed do (
MaxFileDir = getOpenFileName caption:"Select Max file..." types:"Max file(*.max)|*.max|All|*.*|"
if MaxFileDir != undefined do (
_MaxFile_lb.text = MaxFileDir
if(MaxFileDir != undefined and RelinkDir != undefined) then btn_Relink.enabled = true
)
)
on btn_browse pressed do (
RelinkDir = getSavePath caption:"Select Relink Directory..."
if RelinkDir != undefined do (
_Path_lb.text = RelinkDir
if(MaxFileDir != undefined and RelinkDir != undefined) then btn_Relink.enabled = true
)
)
on btn_Relink pressed do (
Si_Relink.RelinkMaxFile MaxFileDir RelinkDir
)
)
CreateDialog _ExtRelinkFiles_Dlg
Learning 3ds Max MAXScript
If you are interested in learning the basics of MAXScripting please check out the following link.
Learning 3ds Max Python
If you are interested in learning the basics of Python scripting please check out the following link.
īģŋ
īģŋ