dotNet + MXS


#581

Maybe a silly question, but why this code does not response on ItemSelectionChanged ?

try(destroyDialog testR)catch()
 rollout testR "Test" width:400 height:400
 (
 	dotnetcontrol pn "MaxCustomControls.MaxUserControl" width:390 height:390 pos:[5,5] 
 	dotnetcontrol lsv1 "Listview"
 	dotnetcontrol lsv2 "Listview"
 	
 	on testR open do 
 	(
 		lvops.InitListView lsv1 pInitColumns:#("Object") pAllowReorder:false pCheckBoxes:false pLabelEdit:False pInitColWidths:#(50)
 		lsv1.dock = lsv1.dock.fill
 		
 		lvops.InitListView lsv2 pInitColumns:#("Object") pAllowReorder:false pCheckBoxes:false pLabelEdit:False pInitColWidths:#(50)
 		lsv2.dock = lsv2.dock.fill
 		
 		sp1 = dotnetobject "SplitContainer" 
 		sp1.dock = sp1.dock.fill
 		sp1.splitterWidth = 5
 		
 		
 		sp1.Panel1.controls.add lsv1
 		sp1.Panel2.controls.add lsv2
 		pn.controls.add sp1
 
 		for i=1 to 10 do (
 			lvops.AddLvItem lsv1 pTextItems:#(i as string)
 		)
 	)
 	
 	on lsv1 ItemSelectionChanged arg do (
 		format "Item index: % ### Item text: %
" arg.ItemIndex arg.item.text
 	)
 )
 createDialog testR

#582

Does anyone know if Max 2014 uses a different .NET framework than previous versions?

I’ve got someone testing a plugin I’m working on and they’re getting the following message:

I compiled the DLL in version 3.5 and it works fine for my other beta testers. That seems to include another one who is /also/ using 2014, but they also have several prior versions of Max installed and I don’t know whether that would affect the results.


#583

This error occurs when you try and load a .dll from a network location, including mapped network drives. If you load the .dll from a local drive, the error will disappear :slight_smile:


#584

You can allow it by editing the 3dsmax.exe.config:

<runtime>
<loadFromRemoteSources enabled=“true” />
</runtime>


#585

I figured that might be the case, but he says it’s installed right on his c: drive…

I’ll ask him to give that a try and see if it fixes the problem. Either way, it’s a really weird thing to be happening…


#586

Try to right click the file -> properties -> unblock (if ‘unblock’ exists in that dialog).


#587

I was able to bypass the original issue with haavard’s solution, but now the user is getting a different error. Any suggestions on what is indicated by an error with the following format?

MAXScript FileIn Exception [X]
/!\ --Runtime error: dotNet runtime exception: Access to the path "C:\Program Files\AutoDesk\3ds Max 2014\scripts\Autobones\License’ is denied. [OK]


#588

Never mind, running Max as an administrator seems to have fixed it.


#589

This suggests that you may be trying to write to a file, or opening a file for write in a folder that requires administrative privileges. If you require a writeable directory that is accessible for all users of all restriction levels, use the ProgramData directory (C:/ProgramData/). If you only want to ‘read’ a file, make sure you open it with read only access.


#590

I’m in pain with DevXpress TreeList … trying to use .MoveNode to root.
When calling this function, it expects “null” as destination node to move it to root. Unfortunately I have no idea how I could pass it in mxs. “Undefined” doesn’t work.


.<System.Boolean>MoveNode <DevExpress.XtraTreeList.Nodes.TreeListNode>sourceNode <DevExpress.XtraTreeList.Nodes.TreeListNode>destinationNode

documented function

I’ve seen some topic about “null” object bypassed by C#, but I’m not so familiar with it.
Please, help. Thanks


#591

it might be better solution but there is main…
it uses on-fly compiled assembly:

fn CreateDevExpressAssembly = 
(
	source  = ""
	source += "using System;
"
	source += "using System.Reflection;
"
	source += "using System.Windows.Forms;
"
	source += "using DevExpress;
"
	source += "namespace DevExpressOps
"
	source += "{
"
	source += "	public class TreeListOps
"
	source += "	{
"
	source += "		public void MoveNode(DevExpress.XtraTreeList.TreeList tv, DevExpress.XtraTreeList.Nodes.TreeListNode source, DevExpress.XtraTreeList.Nodes.TreeListNode target)
"
	source += "		{
"
	source += "			tv.MoveNode(source, target);
"
	source += "		}
"
	source += "		public void MoveNode(DevExpress.XtraTreeList.TreeList tv, DevExpress.XtraTreeList.Nodes.TreeListNode source)
"
	source += "		{
"
	source += "			tv.MoveNode(source, null);
"
	source += "		}
"
	source += "	}
"
	source += "}
"

	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

	maxroot = getdir #maxroot
	compilerParams.ReferencedAssemblies.AddRange \
	#(
		"System.dll", 
		"System.Windows.Forms.dll",
		maxroot + "DevExpress.Data.v10.1.dll", 
		maxroot + "DevExpress.Utils.v10.1.dll", 
		maxroot + "DevExpress.XtraEditors.v10.1.dll", 
		maxroot + "DevExpress.XtraTreeList.v10.1.dll"
	)

	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
	
	assembly = compilerResults.CompiledAssembly
	assembly.CreateInstance "DevExpressOps.TreeListOps"
)
global TreeListOps = CreateDevExpressAssembly()

the made assembly has two methods:
<TreeListOps >.MoveNode <TreeList> <sourceNode> <targetNode>
and
<TreeListOps >.MoveNode <TreeList> <sourceNode>

second method moves source node to root level


#592

you can do it using only one method as well:

source += "		public void MoveNode(DevExpress.XtraTreeList.TreeList tv, DevExpress.XtraTreeList.Nodes.TreeListNode source, object target)
"
 source += "		{
"
 source += "			tv.MoveNode(source, (target == null) ? null : (DevExpress.XtraTreeList.Nodes.TreeListNode)target);
"
source += "		}
"
 

#593

or the modern technique :slight_smile:

source += "		public void MoveNode(DevExpress.XtraTreeList.TreeList tv, DevExpress.XtraTreeList.Nodes.TreeListNode source, dynamic target)
"
source += "		{
"
source += "			tv.MoveNode(source, target);
"
source += "		}
"

#594

Hi
am new for dot net but trying to discover its possibilities
i wonder how i can rich to max tools and windows from dot net ?
is it possible to change its properties "like docking for example "?


#595

Hi. Is it possible to add multiple menuItems to contextMenu or multiple dropdown items at one time. Like in my case i have an array of names, which need to be added to contextmenu. I wonder how to do it as a single coommand.


#596
(
	cm = dotnetobject "ContextMenu"
	list = #("a","b")
	for item in list do cm.MenuItems.Add item
-- or
	cm.MenuItems.AddRange (for item in list collect (dotnetobject "MenuItem" item))
)

#597

Thank you for your reply DenisT.

Another problem i’ve tried to resolve but without luck was this:

I have some material library, and via dotnet contextMenustrip i’m making a dropdown contextmenu. The problem is with click event. It must assign material with the same name as DropDownItem has. But the MatMenu variable contains the last item, which was added in loop. How can it be done? I mean the click event for each subMenu item.

Thank you.

	mat = #some material library


	
	cursor = dotNetClass "System.Windows.Forms.Cursor"
	MMenu = dotNetObject "System.Windows.Forms.ContextMenuStrip"
	MMenu.RenderMode.System

	for i = 1 to mat.count do
	(
		LibMenu = dotNetObject "System.Windows.Forms.ToolStripMenuItem"  (mat[i].name as string)
		LibMenu.tag = i
		MMenu.Items.Add LibMenu
		for j = 1 to mat[i].count where (mat[i][j] != undefined)  do
		(
			MatMenu = dotNetObject "System.Windows.Forms.ToolStripMenuItem" (mat[i][j].name as string)
			MatMenu.tag = j
			LibMenu.DropDownItems.Add MatMenu
			dotnet.addeventhandler matMenu "Click" GiveMat 
		   

			
		)
	)

				fn giveMat  = 
			(
				$.material = mat[libMenu.tag][matMenu.tag]
			)
	
	MMenu.show cursor.position

// Updated:
I’ve made it work so far. The code is below

mat = #some material library
for i = 1 to mat.count do
	(	
		LibMenu = dotNetObject "System.Windows.Forms.ToolStripMenuItem"  (mat[i].name as string)
		MMenu.Items.Add LibMenu
		for j = 1 to mat[i].count where (mat[i][j] != undefined)  do
		(	
			MatMenu = dotNetObject "System.Windows.Forms.ToolStripMenuItem" (mat[i][j].name as string)
			MatMenu.tag = #(i,j)
			LibMenu.DropDownItems.Add MatMenu
			dotnet.addeventhandler matMenu "Click" GiveMat 
			dotNet.setLifeTimeControl MatMenu #dotNet			
		)
		dotNet.setLifeTimeControl LibMenu #dotNet
	)

		
		fn giveMat sender arg  = 
			(
				a = sender.tag[1]
				b = sender.tag[2]
				$.material = mat[a][b]
			)

#598

instead of putting indexes of material and sub material to tag you can put an actual material

menuitem.tag = dotnetmxsvalue mat -- where mat is a material

#599

When having DevXpress.XTraTreeList inside Container, the cell editor is not getting all keys when typing. It “fights” with 3dsmax shortcuts! Any idea how to focus typing keys to editor, please?

(I have more XtraTreeLists inside container , not in this example.)


 rollout tester "TESTER" (
	dotnetcontrol myCont "MaxCustomControls.MaxUserControl" width:300 height:200 
	local dxt = dotNetObject "DevExpress.XtraTreeList.TreeList"
	
	on tester open do (
		srcSC1 = dotnetobject "SplitContainer"
		srcSC1.dock = srcSC1.dock.fill
		srcSC1.Panel1.controls.add dxt
		
		myCont.controls.add srcSC1
		
		col=dxt.Columns.Add()
		col.visible = true
		col.Caption = "Column"
		
		n = dxt.AppendNode #("Text") -1
	)
)
createDialog tester 350 250
 

#600

search on this forum for enableAccelerators