dotNet + MXS


#401

Is there any way to get a Object wirecolor and set it to a dotnetcontrol using System.Drawing.Color ??


      rollout DotNet_Roll "Test"
    (
    
    	dotNetControl btn "system.windows.forms.button" width:112 height:45 pos:[4,5]
    
    	on btn mouseUp senderArg arg do
    	(
    		if (arg.button == arg.button.left) then
    		(
    			for i=1 to (shapes.count) do
    			(
    				nodes = shapes[1]
    				select nodes
    					btn.Text = nodes.name
    					senderArg.backColor = nodes.wirecolor
    			)
    			--senderArg.backColor = senderArg.backColor.lightGreen
    		)
    	)
    	
    	on DotNet_Roll open do
    	(
    		btn.flatstyle = (dotnetclass "System.Windows.Forms.Flatstyle").flat
    	)
    )
    createDialog DotNet_Roll
      

>> MAXScript Rollout Handler Exception: – Unable to convert: (color 154 215 229) to type: System.Drawing.Color <<

thanks in advance


#402


c = dotnetClass "System.drawing.color" 
--dotNetClass:System.Drawing.Color 
c.fromArgb 1.0 0.4 0.2 
--dotNetObject:System.Drawing.Color


Maybe that gives some direction, you probably have to divide the wirecolor by 255.

-Johan


#403

c = thenode.wirecolor
senderArg.backColor = (dotNetClass “System.Drawing.Color”).fromARGB c.r c.g c.b


#404

This may be a stupid question but is there a way to write to the maxscript listener via a c# assembly?


#405
    that´s it, thanks [b]denisT[/b] !
    
  another Question (MXS example):

        try(destroydialog testRol) catch()
       rollout testRol "test"
       (
        imgTag it width:340 height:480 bitmap:undefined enabled:on opacity:10.0 pos:[0,0]
       	
       	on iT dblclick do
       	(
       		dir = getOpenFileName types:"ALL | *.*"
       		if dir != undefined do
       		(
       			IMG = openbitmap dir
       			it.bitmap = IMG
       		)
       	)
       )
       createDialog testRol width:340 height:480
       
    how could i do that using .NET ? 

is there any chance to get/set BackGround Images inside tabControl backGround ?


#406

Yes, If you are using max 2010 you can use the managedservices.dll to pass info. Add this class to your solution and instantiate a maxscriptops object -

using ManagedServices.MaxscriptSDK;
using System.Windows.Forms;

namespace Integration
{
	public class MaxScriptOps
	{
		public void Execute(string ExecuteString, bool TestMode)
		{
			if (TestMode) {
				MessageBox.Show("Execute (" + Strings.Chr(34) + ExecuteString + Strings.Chr(34) + ")");
			}
			else {
				ExecuteMaxscriptCommand("Execute (" + Strings.Chr(34) + ExecuteString + Strings.Chr(34) + ")");
			}
		}
		
		public void PrintToListener(string caption, string text, bool TestMode)
		{
			if (TestMode) {
				MessageBox.Show("Print @" + Strings.Chr(34) + caption + " - " + text + Strings.Chr(34) + "% - %\
");
			}
			else {
				ExecuteMaxscriptCommand("Print @" + Strings.Chr(34) + caption + " - " + text + Strings.Chr(34) + "% - %\
");
			}
		}
		
		public void FormatToListener(string caption, string text, bool TestMode)
		{
			if (TestMode) {
				MessageBox.Show("Format" + Strings.Chr(34) + "% - %\
" + Strings.Chr(34) + " " + Strings.Chr(34) + caption + Strings.Chr(34) + " " + Strings.Chr(34) + text + Strings.Chr(34));
			}
			else {
				ExecuteMaxscriptCommand("Format" + Strings.Chr(34) + "% - %\
" + Strings.Chr(34) + " " + Strings.Chr(34) + caption + Strings.Chr(34) + " " + Strings.Chr(34) + text + Strings.Chr(34));
			}
		}
	}
}

#407

Thank a lot LoneRobot! =)
Fun fact of life, I just finished reading your blog entry on the ManagedServices 5 minutes ago. XD
http://lonerobot.net/?p=472


#408

great!, glad you found it useful :cool:


#409

how could i set a background Image into a tabpage ?

e.g

tab 1

click
fileChooser to pick an .jpeg/.bmp
confirm
the image shown on tabPage BG

i don´t know how to use this method:
http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.ImageLayout.html

thanks in advance


#410

hey guys,
how to add ModifierKeys (alt,shift,ctrl) inside mouseEnter event handler ?

 test:
	-- dotNET
    	dN_UI = dotNetObject "System.Windows.Forms.Form" 
    		dN_UI.location = dotNetObject "System.Drawing.Point" 0 0
    		dN_UI.text = "dotNET test"
    		dN_UI.width = 200
    		dN_UI.height = 300
    		dN_UI.showInTaskBar = false
    		dN_UI.showIcon = false
    
    	-- tab control
    	tab_Control = dotNetObject "System.Windows.Forms.TabControl"
    		tab_Control.size = dotNetObject "System.Drawing.Size" (200-15) (300-37)
    		tab_Control.location = dotNetObject "System.Drawing.Point" 0 0
    		
    		-- tab A
    		tab_A = dotNetObject "System.Windows.Forms.TabPage"
    			tab_A.text = "A"
    			tab_A.backColor = (dotNetClass "System.Drawing.Color").fromARGB 120 120 120
    			
    			-- button 1 
    			btn_1  = dotNetObject "System.Windows.Forms.Button"
    				btn_1.size = dotNetObject "System.Drawing.Size" 120 50
    				btn_1.name = "btn_1"
    				btn_1.location = dotNetObject "System.Drawing.Point" 20 150
    				btn_1.backColor = (dotNetClass "System.Drawing.Color").Gray
    			
    	-- add button to tabPage
    	tab_A.controls.add(btn_1)
    	
    	-- add tabPage to tab Control
    	tab_Control.controls.add(tab_A)
    	
    	-- add tab Control to form
    	dN_UI.controls.add(tab_Control)
    	
    		fn btn_mouseEnter senderArg eventArg =
    		(
    			senderArg.Focus()
    			
    			case (senderArg.Name) of
    			(
    				"btn_1":
    				(
    					format "% % 
" (senderArg.Name) (senderArg.getType())
    				) -- 1
    				
    			) -- end case
    			
    			if (eventArg.Keys == eventArg.Keys.Alt) do
    			(
    				btn_1.backColor = (dotNetClass "System.Drawing.Color").Yellow
    				format "% % 
" (eventArg.getType())
  				print "alt is been pressed !!!"
    			) -- end right handler
    			
    			btn_1.backColor = (dotNetClass "System.Drawing.Color").Gray
    			senderArg.Update()
    		) --
    
    		-- button 1
    		dotNet.addEventHandler btn_1 "mouseEnter" btn_mouseEnter
    		
    	-- show ,NET form
    	dN_UI.Show()
    
 --returns
 &gt;&gt; MAXScript dotNet event handler Exception: -- Unknown property: "keys" in dotNetObject:System.EventArgs &lt;&lt;
 
 
 i´m following these references:
 [http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.Button.html](http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.Button.html)
 
 [http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.Keys.html](http://www.scriptspot.com/bobo/mxs9/dotNet/dotNetObject_System.Windows.Forms.Keys.html)
 
 
 thanks in advance,
 i´ll appreciate any inputs

#411

Hi Renato

this should be ok:


 	-- dotNET
 		dN_UI = dotNetObject "System.Windows.Forms.Form" 
 			dN_UI.location = dotNetObject "System.Drawing.Point" 0 0
 			dN_UI.text = "dotNET test"
 			dN_UI.width = 200
 			dN_UI.height = 300
 			dN_UI.showInTaskBar = false
 			dN_UI.showIcon = false
 	
 		-- tab control
 		tab_Control = dotNetObject "System.Windows.Forms.TabControl"
 			tab_Control.size = dotNetObject "System.Drawing.Size" (200-15) (300-37)
 			tab_Control.location = dotNetObject "System.Drawing.Point" 0 0
 			
 			-- tab A
 			tab_A = dotNetObject "System.Windows.Forms.TabPage"
 				tab_A.text = "A"
 				tab_A.backColor = (dotNetClass "System.Drawing.Color").fromARGB 120 120 120
 				
 				-- button 1 
 				btn_1  = dotNetObject "System.Windows.Forms.Button"
 					btn_1.size = dotNetObject "System.Drawing.Size" 120 50
 					btn_1.name = "btn_1"
 					btn_1.location = dotNetObject "System.Drawing.Point" 20 150
 					btn_1.backColor = (dotNetClass "System.Drawing.Color").Gray
 				
 		-- add button to tabPage
 		tab_A.controls.add(btn_1)
 		
 		-- add tabPage to tab Control
 		tab_Control.controls.add(tab_A)
 		
 		-- add tab Control to form
 		dN_UI.controls.add(tab_Control)
 		
 			fn btn_KeyDown send arg =
 			(
 				if (arg.KeyValue == 18) do
 				(
 					btn_1.backColor = (dotNetClass "System.Drawing.Color").Yellow
 					  print "alt is been pressed !!!"
 				) -- end right handler
 			)
 			fn btn_mouseEnter senderArg eventArg =
 			(
 				senderArg.Focus()
 				
 				case (senderArg.Name) of
 				(
 					"btn_1":
 					(
 						format "% % 
" (senderArg.Name) (senderArg.getType())
 					) -- 1
 					
 				) -- end case
 
 				btn_1.backColor = (dotNetClass "System.Drawing.Color").Gray
 				senderArg.Update()
 			) --
 	
 			-- button 1
 			dotNet.addEventHandler btn_1 "mouseEnter" btn_mouseEnter
 			dotNet.addEventHandler btn_1 "KeyDown" btn_KeyDown
 			
 		-- show ,NET form
 		dN_UI.Show()
 
 

#412

thanks for the input MerlinEl ! what´s the meaning of 18 ??


   arg.KeyValue == 18
   

i´m testing this workaround:


   kb_Alt = booleanClass
   kb_Shift = booleanClass
   kb_Ctrl = booleanClass
   
   		fn btn_keyDown senderArg eventArg =
   		(
   			kb_Alt = eventArg.Alt
   			kb_Shift = eventArg.Shift
   			kb_Ctrl = eventArg.Control
   			eventArg.Handled = false
   			eventArg.SuppressKeyPress = true
   			format "% % % 
" (kb_Alt) (kb_Shift) (kb_Ctrl)
   		) --
   
   		fn btn_keyUp senderArg eventArg =
   		(
   			kb_Alt = eventArg.Alt
   			kb_Shift = eventArg.Shift
   			kb_Ctrl = eventArg.Control
   			eventArg.Handled = false
   			eventArg.SuppressKeyPress = true
   			format "% % % 
" (kb_Alt) (kb_Shift) (kb_Ctrl)
   		) --
   
   			-- button 1
   			dotNet.addEventHandler btn_1 "mouseEnter" btn_mouseEnter
   			dotNet.addEventHandler btn_1 "keyDown" btn_keyDown
   			dotNet.addEventHandler btn_1 "keyUp" btn_keyUp
   

#413

Each key or key combo is represented by integer.
It is up to you, if you want to use werbs or numbers.

format "Key Value:%

" arg.KeyValue


#414

*** EDIT ***

thanks for the explanation !

by the way,
how to convert keyboard numbers (1,2,3,4,5,6,7,8,9,0) into keyValues to work into numericUpDown form  ?

#415

   	dN.close()

	dN = dotNetObject "System.Windows.Forms.Form"
		dN.topMost = true

			t = dotNetObject "System.Windows.Forms.NumericUpDown"
			t.size = dotNetObject "System.Drawing.Size" 60 30
			t.minimum = 1
			t.maximum = 26
			t.InterceptArrowKeys = true
			t.IsAccessible = true
			t.name = "dotNET_NumericUpDown"
			t.location = dotNetObject "System.Drawing.Point" 50 150
			t.backColor = (dotNetClass "System.Drawing.Color").lightGray

		dN.controls.add(t)

	-- show ,NET form
	dN.Show()


    

i don´t know why i can´t type numbers directly… i just want to place numbers e.g (21 = key 2 then key 1) like a standard MXS spinner.

what should i have to do ?


#416

You need to disable the keyboard accelerators. Your keystroks aren’t getting through to the control.


 fn DisableAccel= (enableAccelerators = false)	
 fn EnableAccel= (enableAccelerators = true)	
 
 dN.close()
 
 dN = dotNetObject "System.Windows.Forms.Form"
 	dN.topMost = true
 
 		t = dotNetObject "System.Windows.Forms.NumericUpDown"
 		t.size = dotNetObject "System.Drawing.Size" 60 30
 		t.minimum = 1
 		t.maximum = 26
 		t.InterceptArrowKeys = true
 		t.IsAccessible = true
 		t.name = "dotNET_NumericUpDown"
 		t.location = dotNetObject "System.Drawing.Point" 50 150
 		t.backColor = (dotNetClass "System.Drawing.Color").lightGray
 		
 		dotnet.AddEventHandler t #GotFocus DisableAccel
 		dotnet.AddEventHandler t #LostFocus EnableAccel
 
 	dN.controls.add(t)
 
 
 -- show ,NET form
 dN.Show()
 	
 

#417

it’s max key accelerators problem:


dN.close()

fn gotFocus s e = (enableaccelerators = off)

dN = dotNetObject "System.Windows.Forms.Form"
	dN.topMost = true

		t = dotNetObject "System.Windows.Forms.NumericUpDown"
		t.size = dotNetObject "System.Drawing.Size" 60 30
		t.minimum = 1
		t.maximum = 26
		t.InterceptArrowKeys = true
		t.IsAccessible = true
		t.name = "dotNET_NumericUpDown"
		t.location = dotNetObject "System.Drawing.Point" 50 150
		t.backColor = (dotNetClass "System.Drawing.Color").lightGray

		dotNet.addEventHandler t "GotFocus" gotFocus
	dN.controls.add t



-- show ,NET form
dN.Show()

also you can use “MaxCustomControls.MaxForm” instead of “System.Windows.Forms.Form”. It solves the problem too.


#418

heh, biddle…


#419

yeahhhh, now it´s working, thanks a lot for the input guys !!


       	fn Accelerator senderArg eventArg =
       	(
       		theFocus = senderArg.ContainsFocus
       		if (theFocus == true) 
       			then
       			(
       				enableAccelerators = false
       			)
       		else
       		(
       			enableAccelerators = true
       		)
       	)
       	
       	fn onEnter senderArg eventArg =
       	(
       		senderArg.BeginInit()
     		senderArg.Update()
     		senderArg.Refresh()
           		senderArg.EndInit()
     	)
       	
       	dotNet.addEventHandler t "Enter" onEnter
       	dotNet.addEventHandler t "mouseEnter" Accelerator
       

#420

sorry, double post…