Notifications
Clear all

[Closed] Editable Poly .cageColor


(
global changePolyCageColor

 	fn changePolyCageColor =
	(
	cageColor = color 255 0 0 
	selectedCageColor = color 0 255 0
	polyObj = modPanel.getCurrentObject()
	
		if classof polyObj == Editable_Poly then 
		(
		polyObj.CageColor = [255.0/cageColor.r,255.0/cageColor.g,255.0/cageColor.b]
		polyObj.selectedCageColor = [255.0/selectedCageColor.r,255.0/selectedCageColor.g,255.0/selectedCageColor.b]
		)
	
	)
callbacks.addScript #modPanelSelChanged "changePolyCageColor()" id:#v3d_changePolyCagecolor	
)

Hello, something wrong with max (2017.1) or with my code? I trying change .cageColor through callback but color changes only at second time when I select object.

7 Replies

3dsMax 2017. 10 spheres in the scene, converted to editable poly objects. The cage color is the default.
Your code is executed. When I select a sphere its cage color is changed to red/green. No need to select the obejct second time.

If the callback is running and I create a sphere, as soon as I convert it to editable poly the cage color is changed to red/green.

//youtu.be/wp3iNzhItq8

Problem is it doesn’t works as expected…

Yes. Not works in max 2014 too. The object must be reselected manually.

1 Reply
(@rghost)
Joined: 10 months ago

Posts: 0

Bad :-(. Thanks for checking it.

I’ve tried other handlers and the node event system and assigning cage values directly to object too, but get always the same result (max 2014). Can’t find a workaround, sorry.

It’s a BUG and has to be reported (all versions). I see this bug in the source code…

the only solution to update cage colors i found is the using extra call with a timer:

global CageUpdateTimer =
(
	local timer = dotnetobject "Timer"
	timer.interval = 1
	
	fn executeJob s e = 
	(
		format "% %
"  s e
		s.Stop()
		if iskindof s.tag dotnetmxsvalue and iskindof (ep = s.tag.value) Editable_Poly do
		(
			s.tag.value.cagecolor = s.tag.value.cagecolor
			s.tag.value.selectedCageColor = s.tag.value.selectedCageColor
		)
	)
	dotnet.addEventHandler timer "Tick" executeJob
	timer
)


(
	global changePolyCageColor

 	fn changePolyCageColor =
	(
		cageColor = (random white black) as point4
		selectedCageColor = (random green yellow) as point4
		polyObj = modPanel.getCurrentObject()
	
		if classof polyObj == Editable_Poly then 
		(
			polyObj.CageColor = cageColor
			polyObj.selectedCageColor = selectedCageColor
			format ">> changed... %
" polyObj.CageColor
			CageUpdateTimer.tag = dotnetmxsvalue polyObj
			CageUpdateTimer.Start()
		)
	
	)
	callbacks.removeScripts id:#v3d_changePolyCagecolor	
	callbacks.addScript #modPanelSelChanged "changePolyCageColor()" id:#v3d_changePolyCagecolor	
	callbacks.addScript #modPanelSubObjectLevelChanged "changePolyCageColor()" id:#v3d_changePolyCagecolor	
)

   

( i use a similar solution in some other cases )

Thank you for this solution denisT!

btw reported: BSPR-27166 <Editable_Poly>.CageColor maxscript’s functions doesn’t works properly