Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Max Script code to display currently selected Material ID ?

Max Script code to display currently selected Material ID ?

345243235
Enthusiast Enthusiast
1,709 Views
0 Replies
Message 1 of 1

Max Script code to display currently selected Material ID ?

345243235
Enthusiast
Enthusiast

So I am trying to slightly modify this open script by  hunter_sk, basically I just want the name of the currently selected material ID to appear after the ID number, which is already displayed on the top left part of the interface.

developer_tools-id_changer.jpg

So far I've added the line (and moved everything downwards to leave a full line for ID name)

label nameID "" pos:[2,20]

 but  I can't figure out the other part (or parts?) that I need for the ID name to appear.

This is the script with only 8 buttons for readability, any help is greatly appreciated 🙏

macroScript h_idchanger
category:"Developer Tools"
icon:#("Material_Modifiers",6)
(
	global id_changer
	global id_changer_selectedFacesChanged
	con = dotNetClass "system.windows.Forms.Control"
	rollout id_changer "id_changer 1.5" width:162 height:185
	(
		label currentIDlabel "Selected ID:" pos:[2,3]
		label currentID "-" pos:[68,3]

		label select "select ID" pos:[117,3]

		label countIDlabel "#:" pos:[2,83]
		label countID "" pos:[15,83] align:#left

		label st "set ID" pos:[131,83]



		button b1 "1" pos:[0,20] width:20 height:20
		button b2 "2" pos:[20,20] width:20 height:20
		button b3 "3" pos:[40,20] width:20 height:20
		button b4 "4" pos:[60,20] width:20 height:20
		button b5 "5" pos:[80,20] width:20 height:20
		button b6 "6" pos:[100,20] width:20 height:20
		button b7 "7" pos:[120,20] width:20 height:20
		button b8 "8" pos:[140,20] width:20 height:20

		

		button m1 "1" pos:[0,100] width:20 height:20
		button m2 "2" pos:[20,100] width:20 height:20
		button m3 "3" pos:[40,100] width:20 height:20
		button m4 "4" pos:[60,100] width:20 height:20
		button m5 "5" pos:[80,100] width:20 height:20
		button m6 "6" pos:[100,100] width:20 height:20
		button m7 "7" pos:[120,100] width:20 height:20
		button m8 "8" pos:[140,100] width:20 height:20

		

		button ok "ok" width:150 height:16

		on ok pressed do
		(
			if($!=undefined) do	subobjectLevel = 0
		)

		fn clearCounters =
		(
			currentID.text = ""
			countID.text = ""
		)
		
		fn updateSelectedID_ePoly = 
		(
			sel=polyop.getFaceSelection $ as array
			
			--update count
			countID.text = sel.count as string
			
			--some faces must be selected
			if( sel.count<1) then
			(
				clearCounters()
				return false
			)

			--get first selected face setMaterialID
			matID = polyop.getFaceMatID $ sel[1]

			allSame = true
			for i = 1 to sel.count do 
			(
				if( polyop.getFaceMatID $ sel[i] != matID) then
				(
					allSame=false
					exit
				)
			)
			if(allSame) then currentID.text = matID as string else currentID.text = "--"
		)

		fn updateSelectedID_polyMesh =
		(
			sel = $.modifiers[#Edit_Poly].GetSelection #face
			countID.text = sel.numberSet as string
			
			currentID.text = "--"
			possibleID = 0
			sel=$.modifiers[#Edit_Poly].GetSelection #face

			for i = 1 to sel.count do
			(
				if (sel[i] == true AND possibleID == 0) do possibleID = (polyOp.getFaceMatID $ i)
				
				if (sel[i] == true AND (polyOp.getFaceMatID $ i) != possibleID) do return false
			)
			currentID.text = possibleID as string
		)
		
		fn updateSelectedID callback id =
		(
			--one ePoly must be selected
			if( selection.count!=1 OR subobjectLevel!=4 ) then 
			(
				clearCounters()
				return false
			)

			if( (classof $) == Editable_Poly ) do updateSelectedID_ePoly()
			
			if( (classof $) == PolyMeshObject ) do updateSelectedID_polyMesh()
		)
		
		fn removeFacesWithSpecificIDfromArray arr findId useBitArray:false =
		(
			for faceId = arr.count to 1 by -1 do
			(
				if (useBitArray == true) then
				(
					if (polyOp.getFaceMatID $ faceId == findId) do arr[faceId] = false
				)
				else
				(
					if (polyOp.getFaceMatID $ arr[faceId] == findId) do deleteItem arr faceId
				)
			)
		)
		
		fn selectID_ePoly id =
		(
			-- deselection
			if (con.modifierKeys == con.modifierKeys.Alt) then
			(
				sel = polyop.getFaceSelection $ as array
				removeFacesWithSpecificIDfromArray sel id
				polyop.setFaceSelection $ sel
			)
			else -- select new or add (with ctrl)
			(
				clearSelectionBool = (con.modifierKeys != con.modifierKeys.Control)
				$.EditablePoly.selectByMaterial id clearCurrentSelection:clearSelectionBool
			)
		)

		fn selectID_polyMesh id =
		(
			if (con.modifierKeys == con.modifierKeys.Alt) then
			(
				sel = $.modifiers[#Edit_Poly].GetSelection #Face --bitArray
				removeFacesWithSpecificIDfromArray sel id useBitArray:true
				$.modifiers[#Edit_Poly].SetSelection #Face sel
			)
			else -- select new or add to selection
			(
				if (con.modifierKeys != con.modifierKeys.Control) then
				(
					$.modifiers[#Edit_Poly].SetSelection #Face #{}
				)
				$.modifiers[#Edit_Poly].selectByMaterialID = id-1
				$.modifiers[#Edit_Poly].ButtonOp #SelectByMaterial
			)
		)
		
		fn selectID id =
		(
			if (ClassOf($) == Editable_Poly) then
			(
				if (subobjectLevel != 4) then subobjectLevel = 4
				selectID_ePoly id
			)
			
			if( ClassOf($) == PolyMeshObject) then
			(
				if (subobjectLevel != 4) then subobjectLevel = 4
				selectID_polyMesh id
			)
			redrawViews()
		)

		fn setID_ePoly id =
		(
			$.EditablePoly.setMaterialIndex id 1

			if( (polyop.getFaceSelection $ as array).count >= 1) do
			(
				currentID.text = id as string
			)
		)
		
		fn setID_polyMesh id =
		(
			$.modifiers[#Edit_Poly].SetOperation #SetMaterial
			$.modifiers[#Edit_Poly].materialIDToSet = id-1
			$.modifiers[#Edit_Poly].Commit ()	
			
			if( ($.modifiers[#Edit_Poly].GetSelection #face).count >= 1) do
			(
				currentID.text = id as string
			)
		)		
		
		fn setID id =
		(
			if (ClassOf($) == Editable_Poly) then
			(
				if (subobjectLevel != 4) then subobjectLevel = 4
				setID_ePoly id
			)
			if (ClassOf($) == PolyMeshObject) then
			(
				if (subobjectLevel != 4) then subobjectLevel = 4
				setID_polyMesh id
			)
		)

		on b1 pressed do ( selectID(1) )
		on b2 pressed do ( selectID(2) )
		on b3 pressed do ( selectID(3) )
		on b4 pressed do ( selectID(4) )
		on b5 pressed do ( selectID(5) )
		on b6 pressed do ( selectID(6) )
		on b7 pressed do ( selectID(7) )
		on b8 pressed do ( selectID(8) )

		on m1 pressed do ( setID(1) )
		on m2 pressed do ( setID(2) )
		on m3 pressed do ( setID(3) )
		on m4 pressed do ( setID(4) )
		on m5 pressed do ( setID(5) )
		on m6 pressed do ( setID(6) )
		on m7 pressed do ( setID(7) )
		on m8 pressed do ( setID(8) )


		on id_changer close do
		(
			id_changer_selectedFacesChanged = undefined
			gc()
		)
	)
	CreateDialog id_changer
	id_changer_selectedFacesChanged = NodeEventCallback mouseUp:true subobjectSelectionChanged:id_changer.updateSelectedID
)

 

0 Likes
1,710 Views
0 Replies
Replies (0)