Notifications
Clear all

[Closed] when … handleAt:#redrawViews fubar

hello
got some probs with a when construct with handleat.#redrawviews.

what im intend to do with this script, is to make a comfortable face selection mode.
when enabled, all face selections add to current selection. if a single face is selected, which is already selected, it will get unselected.
in basic the script works. but only when im pan the scene or switch to another screen.
i tried different methods to get a view redraw to update the selection but nothing works so far

heres the code so far
im glad for any help ^^


global PB_SelectionAdd_SelectionArray = #{}
global PB_AISelectionAddUpdate = false
global PB_UpdateSelection

clearListener()
deleteAllChangeHandlers id:#PBAddSelection
deleteAllChangeHandlers id:#PBAddSelectionUpdate

fn PB_IntSelectionAdd =
(
	CurrentSelection = getFaceSelection selection[1]
	format "Selected Face 	: %
" CurrentSelection
		
	RemoveIdx = 0
	if CurrentSelection.numberSet == 1 then
	(
		RemoveIdx = findItem PB_SelectionAdd_SelectionArray (CurrentSelection as array)[1]
	)
			
	if RemoveIdx == 0 then
	(
		PB_SelectionAdd_SelectionArray = PB_SelectionAdd_SelectionArray + CurrentSelection			
	)
	else
	(
		PB_SelectionAdd_SelectionArray = PB_SelectionAdd_SelectionArray - CurrentSelection
		
		format "	Remove Selection 	: %
" CurrentSelection
	)

	setFaceSelection selection[1] PB_SelectionAdd_SelectionArray

	PB_AISelectionAddUpdate = true
	
	if keyboard.escPressed then
	(
		format "ChangeHandler removed 
"
		deleteAllChangeHandlers id:#PBAddSelection
		deleteAllChangeHandlers id:#PBAddSelectionUpdate
	)
)

fn PB_SetNewFaceSelection = 
(
	if true do
	(
		redrawViews()
		
		nodeInvalRect selection[1]
		
		setNeedsRedraw complete:true
		
		forceCompleteRedraw doDisabled:true

		print "Redraw !!!"
		PB_AISelectionAddUpdate = false
	)
)

when select selection changes id:#PBAddSelection handleAt:#redrawViews  do 
(	
	if Selection.count == 1 AND (classof selection[1] == Editable_Mesh) do
	(		
		PB_IntSelectionAdd()	
	)
)

when select selection changes id:#PBAddSelectionUpdate do 
(	
	if PB_AISelectionAddUpdate do
	(		
		PB_SetNewFaceSelection()	
	)
)