MAXScript: How to create layered .NET window in Windows Forms


#62

I also have not encountered a similar task before, so it became interesting for me to implement animation in WPF. This may come in handy somewhere in the future for other tasks.

By the way, during testing, I found that animation freezes occur only when the splash screen is launched before loading the main script in 3ds max 2021. If you run in 3ds max 2020, then there are no freezes and the splash screen works smoothly and stably. What is the reason for this, I still cannot understand.


#63

Yea! and this is proper way to create Image Sequence Player with WPF (Iā€™m not implemented multithread things)

global wpfWindow
(
	if wpfWindow != undefined do wpfWindow.close()
	xamlString =
	"
	<Window
	xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
	xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
	WindowStartupLocation='CenterScreen'
	AllowsTransparency='True'
	WindowStyle='None'
	Background='Transparent'>
	<Window.DataContext>
		<ListBox/>
	</Window.DataContext>
	<Image Source='{Binding SelectedItem}'>
		<Image.Triggers>
			<EventTrigger RoutedEvent='Loaded'>
				<BeginStoryboard>
					<Storyboard
							Storyboard.Target='{Binding}'
							Storyboard.TargetProperty='SelectedIndex'>
						<Int32Animation 
							To='{Binding Items.Count}'
							RepeatBehavior='Forever'
							Duration='0:0:1'/>
					</Storyboard>
				</BeginStoryboard>
			</EventTrigger>
		</Image.Triggers>
	</Image>
	</Window>
	"
	wpfWindow = (dotnetclass "System.Windows.Markup.XamlReader").Parse xamlString
	for image in getfiles "C:/Temp/Gifs/Anim/*.png" do wpfWindow.DataContext.items.add image
	(dotnetobject "System.Windows.Interop.WindowInteropHelper" wpfWindow).owner = dotnetobject "IntPtr" (windows.getMAXHWND())
	(dotnetclass "ManagedServices.AppSDK").ConfigureWindowForMax wpfWindow
	wpfWindow.show()
-- 	wpfWindow.close()
)

#64

Found something useful (to me) to do with this, an asynchronous real-time Heap Monitor. (WIP)
So far it works stable from Max 2014 to Max 2022.

Here testing with some loops:

And here testing the Heap usage with 250 scripted controllers:


#65

Have you tried it in 21/22? Working same (second gif)?

Fckn 403!
And I thought it wont accept too short answer!


#66

as I see the memory leak is bad :face_with_raised_eyebrow:


#67

The .gif is from 2021.


#68

The leak is terrible not bad. But I wanted to show an animation consuming the heap. Changing a few lines it uses like 100 times less memory.


#69

I have similar experience with script controllers. Memory usage by the script controller is very sensitive to script syntax. This topic is absolutely not covered in the 3DS MAX docs. But should be!


#70

Here is the optimized version:


#71

a big difference!