Posted By James Haywood

There are three key components to getting .Net 4.0 working inside of Max 2011...

  1. Recompile the mxsdotNet.dlx file using Visual Studio 2010.
  2. Modify the 3dsMax.exe.config file.
  3. Install the Visual C++ 2010 components.

I'll describe each in detail below, but first I should mention that this is not officially supported by Autodesk.  So if you run into trouble because of it, you're on your own.  Kind of like hacking your video card to make it run faster.

I've been running Max 2011 with .Net 4.0 WPF tools running within it for a couple months now without any noticable issues.  But I can't gaurantee that this will be the case for everyone.  And I've only been using the 64-bit version, although I can't think of why this wouldn't work with the 32-bit version as well.  As for versions of Max before 2011, I have no idea if this will work or not.

So, on to the instructions...

1. Recompiling the mxsdotNet plugin is pretty straighforward.  Just install the SDK, open the ...\samples\maxscript\mxsdotNet\mxsdotNet.sln file and compile.  If you don't have Visual Studio 2010, you can download the already recompiled 64-bit version below.

2. Open the ...\Autodesk\3ds Max 2011\3dsmax.exe.config file in a text editor and add the following lines right before the closing </configuration> tag...

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

3.  Lastly, if you haven't already installed Visual Studio 2010, you'll need to manually install the Visual C++ 2010 components.  But if you have, then these should be installed for you already.  You can download the installers here...

32-bit
64-bit

And that's it.  Once you've got all the necessary files modified correctly, you'll be able to load and use .Net 4.0 assemblies directly in Max.  The DataGridView control alone is worth the effort.

Download 64-bit .Net plugin and config file here.


 
Posted By James Haywood

I recently came across a nasty issue that comes up when hosting a WPF control inside of a docked Max rollout.  The problem is that anything that causes the entire Max UI to redraw (like docking/undocking a rollout or changing the minimized state of the Graphite ribbon while it's docked) makes the WPF control completely disappear.  The elements of the control pop back into existence as you mouse over them, but of course it's a pain to have to keep waving your arrow over a section of the screen to get your controls back.

Fortunately, there's a fairly easy work around to keep it from disappearing.

So, execute the following script and you'll see a row of WPF buttons in a stackpanel docked to the left side of the screen like so...

WPF refresh issue 1

------------------
dotNet.loadAssembly @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll"

rollout wpfRefresh_RLT "" width:70 height:220
(
  dotNetControl eh "Integration.ElementHost" width:70 height:500 align:#left offset:[-14,-5]
   on wpfRefresh_RLT open do
   (
     uc = dotNetObject "System.Windows.Controls.UserControl"
     eh.child = uc
     sp = dotNetObject "System.Windows.Controls.StackPanel"
     for i = 1 to 10 do
     (
       btn = dotNetObject "System.Windows.Controls.Button"
       btn.height = 20
       btn.content = "button " + i as string
       sp.children.add btn
     )
     uc.content = sp
   )
)

createDialog wpfRefresh_RLT style:#(#style_toolwindow,#style_sysmenu,#style_resizing)
cui.RegisterDialogBar wpfRefresh_RLT style:#(#cui_floatable,#cui_dock_left,#cui_handles)
cui.DockDialogBar wpfRefresh_RLT #cui_dock_left
------------------

And now if you do something to make the UI redraw, like I mentioned above, you get this...

WPF refresh issue 2

Wave the mouse arrow over the controls and you'll see them reappear one at a time.

The way to keep this from happening is to catch the Paint event on the ElementHost and manually force it to redraw by calling it's Refresh() method.  That's easy enough, but it turns out that calling Refresh() causes the Paint event to trigger again.  So it gets into a nice little infinite loop and really messes with Max's overall performance.

So we need to add one more step, which is to use a boolean variable to make sure that it only refreshes once and then stops.

Add the following to the rollout to make these changes:


------------------
local doRefresh = true

on eh Paint args do

(
    if doRefresh then
    (
       doRefresh = false
       eh.refresh()
       doRefresh = true
     )
)
-------------------


Now the WPF control will redraw itself whenever it needs to.  The full script can be downloaded here.


 

 

 
Google

User Profile
James Haywood
Seattle, WA

 
Category
 
Archives
 
Links
 
Visitors

You have 455470 hits.

 
Navigation