Hello,
I am trying to adapt a script found on this forum Replacing Objects
it works great when objects are in the “maxfilepath” but i try to add a custom folder path to it, it’s not working as i would like, it kind of work sometimes but after a 3dsmax restart it’s not working anymore, if some of you has any clue on what i am doing wrong here is on of my many attempt to make this work :
– Create the rollout for the interface
rollout replaceObjectsRollout “Replace Objects” width: 250 height: 200
(
group "Browse and Replace Objects"
(
button replaceButton "Replace" width:200 height:30 pos:[13,145]
button btn_browse "Browse..." width:100 height:20 pos:[13,45]
editText edt_path "Export Location:" labelOnTop:true
)
fn deselectDuplicates =
(
local allNames = #()
local duplicateObjs = #()
for obj in selection do
(
if findItem allNames obj.name == 0 then append allNames obj.name
else append duplicateObjs obj
)
deselect duplicateObjs
)
fn replaceSelectedObjects objNamePattern =
(
– get selected objects
selObjs = selection as array
-- loop through selected objects and replace them with corresponding name
for obj in selObjs do
(
if findString obj.name objNamePattern != undefined do
(
print ("Replacing object: " + obj.name)
objectReplace obj.name
)
)
)
fn objectReplace name all:on =
(
print ("Replacing object " + name)
undo “object replace” on
act = off
pattern = if all then (name + "*") else name
-- collect all nodes with the name or which name match the pattern <name>* (name_01, name 02, etc. )
nodes = for obj in objects where matchpattern obj.name pattern:pattern collect obj
-- replace file has to be in the same directory and has the name of object to replace
file = edt_path.text + "\\" + name + ".max"
if nodes.count > 0 and doesfileexist file do
(
clearSelection()
-- merge only object with the name
mergeMaxFile file #(name) #select #mergeDups #neverReparent #useMergedMtlDups quiet:on
if isvalidnode (node = selection[1]) do
(
-- replace all old instances with new one
for obj in nodes do (
instancereplace obj node
obj.mat = node.mat
)
delete node
act = on
)
)
print ("Object replace " + (if act then "succeeded" else "failed"))
act
)
on btn_browse pressed do
(
newpath = getSavePath()
edt_path.text = newpath
print newpath
)–end do
on replaceButton pressed do
(
deselectDuplicates ()
replaceSelectedObjects ""
)
)
– Create the dialog for the interface
createDialog replaceObjectsRollout