instancereplace

instancereplace

akaijin
Explorer Explorer
1,819 Views
3 Replies
Message 1 of 4

instancereplace

akaijin
Explorer
Explorer

I'm pretty newbie about maxscript.
In maxscript ,there is instancereplace method.
So,I want to change to make rollout button and select objects by pushing the bottun.
I tried ,but don't work well.


rollout MYTool01 "instancereplace"

button selectObj_btn  "selectObj" pos:[8,5] width:60
button replaceObj_btn "replaceoObj" pos:[8,30] width:60
button replace_btn "execute" pos:[8,50] width:60

local obj=#()
 
 on selectObj_btn pressed do
 (
  srcobj= $selection as array
 ) 
 on  replaceObj_btn pressed do
 (
  dstObj = $selection as array
 )
 on replace_btn pressed do
 (
  instancereplace srcobj dstObj
  )
)
createDialog  MYTool01 width:600


Is there a way to find a good code,please?
Sorry about my poor English.

 

0 Likes
Accepted solutions (2)
1,820 Views
3 Replies
Replies (3)
Message 2 of 4

miauuuu
Collaborator
Collaborator
Accepted solution

 

(
	global rol_MYTool01
	try(destroyDialog rol_MYTool01)catch()
	rollout rol_MYTool01 "instancereplace"
	( 
		local selObj = undefined
		local objsToReplaceArr = #()
		
		button selectObj_btn  "Select source object" width:140
		button replaceObj_btn "Select objects to replace"  width:140
		button replace_btn "EXECUTE"  width:140

		on selectObj_btn pressed do
		(
			selObj = selection[1]
		) 
		on replaceObj_btn pressed do
		(
			objsToReplaceArr = selection as array
		)
		on replace_btn pressed do
		(
			if selObj != undefined and objsToReplaceArr.count != 0 do
			(
				instanceReplace objsToReplaceArr selObj 
			)
		)
	)
	createDialog  rol_MYTool01 
)

Select only one Source object and press the [Select source object] button.

Then select the objects that you want to be replaced and press the [Select objects to replace] button.

Then press the [EXECUTE] button.

 

https://miauu-maxscript.com/
Message 3 of 4

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

here is my version:

 

pick a "target" object as an object for replace with

 

select source nodes and apply "Instance Replace"  

try(destroydialog instancereplaceDialog) catch()
rollout instancereplaceDialog "Instance Replace" width:210  
(
	group "Target:" 
	(
		pickbutton target_bt "Pick Target" width:192 autoDisplay:on align:#right offset:[4,0]
	)
	group "Tools:" 
	(
		button replace_bt "Instance Replace" width:192 align:#right offset:[4,0]
	)
	
	on replace_bt pressed do undo "Replace" on 
	(
		if isvalidobj target_bt.object and selection.count > 0 do
		(
			instancereplace selection target_bt.object
		)
	)
)
createdialog instancereplaceDialog
Message 4 of 4

akaijin
Explorer
Explorer

Hi,miauuuu and denisT

 

Thank you so much!

I can stop worrying about that now.

 

These scripts works well for group objects !

I'll keep on trying, thanks.

 

 

0 Likes