Notifications
Clear all

[Closed] Replace max file using windows.getChildrenHWND

Hi,
I recently have a project need to replace objects from a max scene,I tried to find a way to do that ,but did not got a solution,I am trying using windows.getChildrenHWND to simulate pressing buttons,my goal is to press ‘All’ and ‘OK’:

but my code does not work:

for child in (windows.getChildrenHWND 0 parent:#max) do
(
   if findstring child[5] "Replace -" !=undefined then
   (                  
      for classN in (windows.getChildrenHWND child[1]) do
      (
         if findstring classN[5] "All"  !=undefined then
         (
            try(windows.sendMessage classN[1] 0) catch()   
         )                     
      )
   )
)

Any help would be highly appreciate!

4 Replies
2 Replies
 MZ1
(@mz1)
Joined: 11 months ago

Posts: 0

Why you don’t use mergeMAXFile function?

(@momo2012)
Joined: 11 months ago

Posts: 0

I tried ,how can I let the merged object’s position replacing the current one that need to be replaced?For example,if I have 5 objects
below will be replaced,have the same name and same material,but each has different position

object_A_01.pos=[0,0,0] object_A_01.name=“object_A”
object_A_02.pos=[990,0,0] object_A_02.name=“object_A”
object_A_03.pos=[0,990,0] object_A_03.name=“object_A”
object_A_04.pos=[0,0,110] object_A_04.name=“object_A”

below is the need to merged:

object_B.pos=[99,99,99] object_B.name=“object_A”

if

object_A_01
object_A_02
object_A_03
object_A_04

will replaced by object_B,after I merge object_B,how can I replace them as

object_B
object_B
object_B
object_B

via mergeMAXFile function?:curious:

Not sure if it will work in newer versions of max. It would be just great if someone could test


struct ReplaceMaxFileObjects
(
    targetMaxFilename,
    targetMaxFilePath,
    
    replaceMtls = true,
    
    fn handleReplace = 
    (
        
        local hwnd = DialogMonitorOPS.GetWindowHandle()
                
        if hwnd != undefined do (

            local data = windows.getHWNDData hwnd

            if data[4] == "#32770" and data[5] == "Replace File" then
            (
                local childs = windows.getChildrenHWND data[1]
                
                local editIndex = for i=1 to childs.count where childs[i][4] == "Edit" do exit with i

                UIAccessor.SetWindowText childs[editIndex][1] (targetMaxFilePath + targetMaxFilename)            
                UIAccessor.PressButtonByName hwnd "&Open"
                
            ) 
            else if matchpattern data[5] pattern:("*" + targetMaxFilename + "*") then
            (
                UIAccessor.PressButtonByName hwnd "&All"
                 UIAccessor.PressButtonByName hwnd "OK"
            )
            else if data[4] == "#32770" and data[5] == "3ds Max" do 
            (
                local childs = windows.getChildrenHWND data[1]
                
                if childs[4][5] == "Do You Want to Replace Materials along with Objects?" do
                (
                    if replaceMtls then UIAccessor.PressButton childs[1][1] else UIAccessor.PressButton childs[2][1]

                )

            )
            
        )

        true
        
    ),
    
    fn Replace filepath = if isMaxFile filepath do
    (
        targetMaxFilename = filenameFromPath filepath
        targetMaxFilePath = getFilenamePath filepath
        
        DialogMonitorOPS.UnRegisterNotification id:#handleReplace
        DialogMonitorOPS.RegisterNotification handleReplace id:#handleReplace
        DialogMonitorOPS.enabled = true

        actionMan.executeAction 0 "40245"  -- File: File Replace

        DialogMonitorOPS.enabled = false
        DialogMonitorOPS.UnRegisterNotification id:#handleReplace        
        
    )
    
)

replaceDialog = ReplaceMaxFileObjects replaceMtls:false
replaceDialog.replace @"C:\Users\User\Documents\3dsmax\scenes	estfile.max"

1 Reply
(@momo2012)
Joined: 11 months ago

Posts: 0

Just tested,it worked like a charm!Thanks a lot!