Notifications
Clear all

[Closed] dot net pickbutton

How do I create the equivalent of the max pickbutton in a dot net form?

12 Replies
1 Reply
(@gazybara)
Joined: 1 year ago

Posts: 0
(
 global bgaFORM
 try(bgaFORM.close()) catch()
 local bgaTB, bgaBtn, bgaCB1, bgaCB2, bgaCB3    
 fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)        
 fn defPoint x y = (dotNetObject "System.Drawing.Point" x y)    
 fn defSize x y = (dotNetObject "System.Drawing.Size" x y)
 Clr = defColor 0 0 0 ; ClrBG = defColor 60 60 60 ; ClrFG = defColor 200 200 200
 
 fn defCheckBox dnCB w h locX locY txt =
 (
     dnCB.Width = w ; dnCB.Height = h
     dnCB.BackColor = ClrBG
     dnCB.ForeColor = ClrFG
     dnCB.Appearance = dnCB.Appearance.Button
     dnCB.text = txt
     dnCB.FlatStyle = dnCB.FlatStyle.System
     dnCB.Location = defPoint locX locY 
 )
 fn defForm dnForm w h x y txt =
 (
     dnForm.ShowInTaskbar = false ; dnForm.Text = txt ; dnForm.ClientSize = defSize w h
     dnForm.StartPosition = dnForm.StartPosition.Manual ; dnForm.DesktopLocation = defPoint x y
     dnForm.FormBorderStyle = dnForm.FormBorderStyle.FixedToolWindow
     dnForm.BackColor = ClrBG
 )
 
 bgaFORM = dotnetobject "MaxCustomControls.MaxForm" ; defForm bgaFORM 160 30 10 110 "Main Form"
 bgaCB1 = dotnetobject "CheckBox" ; defCheckBox bgaCB1 150 20 5 5 "dotnetPickButton"
 
 bgaFORM.Controls.AddRange #(bgaCB1)
 bgaFORM.ShowModeless()
 )

yes, thanks for that.
Not sure how to actually capture what is picked however, say I want to select a bone and get it’s name etc…or a mesh…

2 Replies
(@denist)
Joined: 1 year ago

Posts: 0

the same way as for MXS… by using of the pickObject

(@gazybara)
Joined: 1 year ago

Posts: 0

Like this


    (
     global bgaFORM
     try(bgaFORM.close()) catch()
     local bgaCB1, obj  
     fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)		
     fn defPoint x y = (dotNetObject "System.Drawing.Point" x y)	
     fn defSize x y = (dotNetObject "System.Drawing.Size" x y)
     Clr = defColor 0 0 0 ; ClrBG = defColor 60 60 60 ; ClrFG = defColor 200 200 200
     
     fn defCheckBox dnCB w h locX locY txt =
     (
    	 dnCB.Width = w ; dnCB.Height = h
    	 dnCB.BackColor = ClrBG
    	 dnCB.ForeColor = ClrFG
    	 dnCB.Appearance = dnCB.Appearance.Button
    	 dnCB.text = txt
    	 dnCB.FlatStyle = dnCB.FlatStyle.System
    	 dnCB.Location = defPoint locX locY 
     )
     fn defForm dnForm w h x y txt =
     (
    	 dnForm.ShowInTaskbar = false ; dnForm.Text = txt ; dnForm.ClientSize = defSize w h
    	 dnForm.StartPosition = dnForm.StartPosition.Manual ; dnForm.DesktopLocation = defPoint x y
    	 dnForm.FormBorderStyle = dnForm.FormBorderStyle.FixedToolWindow
    	 dnForm.BackColor = ClrBG
     )
     fn boneFilt o = (isKindOf o BoneGeometry)
     fn onPick s e =
     (
    	 if s.checked do
    	 (
    		 obj = pickObject filter:boneFilt
    		 if obj == undefined then s.checked = off else
    		 (
    			 s.text = obj.name
    			 s.checked = off
    			 format "bone = %
" obj
    		 )
     	 )
     )
     
     bgaFORM = dotnetobject "MaxCustomControls.MaxForm" ; defForm bgaFORM 160 30 10 110 "Main Form"
     bgaCB1 = dotnetobject "CheckBox" ; defCheckBox bgaCB1 150 20 5 5 "PickBone"
     dotNet.addEventHandler bgaCB1 "CheckStateChanged" onPick
     bgaFORM.Controls.AddRange #(bgaCB1)
     bgaFORM.ShowModeless() ; ok
     )
    

absolutely.

First of all I’d like to thank all the guys on this forum who have helped me with this dotnet stuff – it’s been invaluable and I don’t think I’ve would have got far at all without your kind patient assitance. If I could just indulge your patience for a bit longer and ask why the code below doesn’t work – I’m trying to get the background image to change according to the number of clicks of the mouse on different bones…It only ever shows the first member of the BKG array…I don’t get why it doesn’t update. dotnet form controls methods don’t seem to have a remove backround bitmap function. Many thnx in advance,…


 
 
  (
   global bgaFORM
   try(bgaFORM.close()) catch()
   local bgaCB1, obj  
   fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)  
   fn defPoint x y = (dotNetObject "System.Drawing.Point" x y) 
   fn defSize x y = (dotNetObject "System.Drawing.Size" x y)
   Clr = defColor 0 0 0 ; ClrBG = defColor 60 60 60 ; ClrFG = defColor 200 200 200
   bonesd = #();
   t = 0;
   BKG = #("Curves.bmp" , "Bone.bmp")
   fn defCheckBox dnCB w h locX locY txt =
   (
	dnCB.Width = w ; dnCB.Height = h
	dnCB.BackColor = ClrBG
	dnCB.ForeColor = ClrFG
	dnCB.Appearance = dnCB.Appearance.Button
	dnCB.text = txt
	dnCB.FlatStyle = dnCB.FlatStyle.System
	dnCB.Location = defPoint locX locY 
   )
   fn defForm dnForm w h x y txt =
   (
	dnForm = dotnetobject "form"
	dnForm.ShowInTaskbar = false ; dnForm.Text = txt ; dnForm.ClientSize = defSize w h
	dnForm.StartPosition = dnForm.StartPosition.Manual ; dnForm.DesktopLocation = defPoint x y
	dnForm.FormBorderStyle = dnForm.FormBorderStyle.FixedToolWindow
	dnForm.BackColor = ClrBG
	dnForm.visible =false
	-- dnForm.Show (maxHwnd)
 
   )
	theImage = dotNetClass "System.Drawing.Image"
 
 theDir  = getFilenamePath (getSourceFilename() )
theFilename = "Bone.bmp"
 
   fn boneFilt o = (isKindOf o BoneGeometry)
   fn ec s e =
   ( 
	if s.checked then  (s.checked = false) else
	(
	 obj = pickObject filter:boneFilt
 
	 if obj != undefined then
	 ( t = t+1;
   theFilename = BKG[t];
 
head=dotNetObject "label"
head.size=dotNetObject "system.drawing.size" 250 200
head.location=dotNetObject "system.drawing.point" 0 0
header = theImage.FromFile ( theDir + theFilename) 
head.BackgroundImage = header 
bgaFORM.controls.clear	
bgaFORM.controls.add head
append bonesd obj;
s.text = obj.name
s.checked = false
 
	 )
	 ); 
   )
 
   bgaFORM = dotnetobject "MaxCustomControls.MaxForm" ; defForm bgaFORM 160 300 10 110 "Main Form"
   bgaCB1 = dotnetobject "CheckBox" ; defCheckBox bgaCB1 150 20 5 5 "PickBone"
   dotNet.addEventHandler bgaCB1 "CheckStateChanged" ec
   bgaFORM.Controls.AddRange #(bgaCB1)
   bgaFORM.ShowModeless() ;
 
   )
 
 

I changed code a little because i don’t know for what is this tool and not have this maps
that you use in example
(
global bgaFORM
try(bgaFORM.close()) catch()
local bgaCB1, obj
fn defColor r g b = ((dotNetClass “System.Drawing.Color”).FromArgb r g b)
fn defPoint x y = (dotNetObject “System.Drawing.Point” x y)
fn defSize x y = (dotNetObject “System.Drawing.Size” x y)
Clr = defColor 0 0 0 ; ClrBG = defColor 60 60 60 ; ClrFG = defColor 200 200 200
local bonesd = #(), t = 0, BKG = #(“Curves.bmp” , “Bone.bmp”)
fn defCheckBox dnCB w h locX locY txt =
(
dnCB.Width = w ; dnCB.Height = h
dnCB.BackColor = ClrBG
dnCB.ForeColor = ClrFG
dnCB.Appearance = dnCB.Appearance.Button
dnCB.text = txt
dnCB.FlatStyle = dnCB.FlatStyle.System
dnCB.Location = defPoint locX locY
)
fn defForm dnForm w h x y txt =
(
dnForm = dotnetobject “form”
dnForm.ShowInTaskbar = false ; dnForm.Text = txt ; dnForm.ClientSize = defSize w h
dnForm.StartPosition = dnForm.StartPosition.Manual ; dnForm.DesktopLocation = defPoint x y
dnForm.FormBorderStyle = dnForm.FormBorderStyle.FixedToolWindow
dnForm.BackColor = ClrBG
dnForm.visible =false
)

local theImage = dotNetClass "System.Drawing.Image"
--if current file is not aleady saved next line will cause error, it is better to add different path
local theDir  = getFilenamePath (getSourceFilename())
local theFilename = "Bone.bmp"

fn boneFilt o = (isKindOf o BoneGeometry)
fn ec s e =
( 
    if s.checked then  (s.checked = false) else
    (
        obj = pickObject filter:boneFilt count:#multiple
        if obj != #() then
        ( 
            t = t+1;
            theFilename = BKG[t]
            head = dotNetObject "label"
            head.size = defSize 250 200
            head.location = defPoint 0 0
            header = theImage.FromFile ( theDir + theFilename) 
            head.BackgroundImageLayout = head.BackgroundImageLayout.Center 
            head.BackgroundImage = header 
            bgaFORM.controls.clear    
            bgaFORM.controls.add head
            append bonesd obj;
            s.text = obj[obj.count].name
            s.checked = false
        )
    )
)

bgaFORM = dotnetobject "MaxCustomControls.MaxForm" ; defForm bgaFORM 160 300 10 110 "Main Form"
bgaCB1 = dotnetobject "CheckBox" ; defCheckBox bgaCB1 150 20 5 5 "PickBone"
dotNet.addEventHandler bgaCB1 "CheckStateChanged" ec
bgaFORM.Controls.AddRange #(bgaCB1)
bgaFORM.ShowModeless() ; ok

)

I changed code a little because i don’t know for what is this tool and not have this maps
that you use in example


 (
 	global bgaFORM
 	try(bgaFORM.close()) catch()
 	local bgaCB1, obj  
 	fn defColor r g b = ((dotNetClass "System.Drawing.Color").FromArgb r g b)  
 	fn defPoint x y = (dotNetObject "System.Drawing.Point" x y) 
 	fn defSize x y = (dotNetObject "System.Drawing.Size" x y)
 	Clr = defColor 0 0 0 ; ClrBG = defColor 60 60 60 ; ClrFG = defColor 200 200 200
 	local bonesd = #(), t = 0, BKG = #("Curves.bmp" , "Bone.bmp")
 	fn defCheckBox dnCB w h locX locY txt =
 	(
 		dnCB.Width = w ; dnCB.Height = h
 		dnCB.BackColor = ClrBG
 		dnCB.ForeColor = ClrFG
 		dnCB.Appearance = dnCB.Appearance.Button
 		dnCB.text = txt
 		dnCB.FlatStyle = dnCB.FlatStyle.System
 		dnCB.Location = defPoint locX locY 
 	)
 	fn defForm dnForm w h x y txt =
 	(
 		dnForm = dotnetobject "form"
 		dnForm.ShowInTaskbar = false ; dnForm.Text = txt ; dnForm.ClientSize = defSize w h
 		dnForm.StartPosition = dnForm.StartPosition.Manual ; dnForm.DesktopLocation = defPoint x y
 		dnForm.FormBorderStyle = dnForm.FormBorderStyle.FixedToolWindow
 		dnForm.BackColor = ClrBG
 		dnForm.visible =false
 	)
 	
 	local theImage = dotNetClass "System.Drawing.Image"
 	--if current file is not aleady saved next line will cause error, it is better to add different path
 	local theDir  = getFilenamePath (getSourceFilename())
 	local theFilename = "Bone.bmp"
 
 	fn boneFilt o = (isKindOf o BoneGeometry)
 	fn ec s e =
 	( 
 		if s.checked then  (s.checked = false) else
 		(
 			obj = pickObject filter:boneFilt count:#multiple
 			if obj != #() then
 			( 
 				t = t+1;
 				theFilename = BKG[t]
 				head = dotNetObject "label"
 				head.size = defSize 250 200
 				head.location = defPoint 0 0
 				header = theImage.FromFile ( theDir + theFilename) 
 				head.BackgroundImageLayout = head.BackgroundImageLayout.Center 
 				head.BackgroundImage = header 
 				bgaFORM.controls.clear	
 				bgaFORM.controls.add head
 				append bonesd obj;
 				s.text = obj[obj.count].name
 				s.checked = false
 			)
 		)
 	)
 
 	bgaFORM = dotnetobject "MaxCustomControls.MaxForm" ; defForm bgaFORM 160 300 10 110 "Main Form"
 	bgaCB1 = dotnetobject "CheckBox" ; defCheckBox bgaCB1 150 20 5 5 "PickBone"
 	dotNet.addEventHandler bgaCB1 "CheckStateChanged" ec
 	bgaFORM.Controls.AddRange #(bgaCB1)
 	bgaFORM.ShowModeless() ; ok
 )
 

double post, sorry:hmm:

always first try isolate the problem… make a simple test and play with it to get it work:
something like this:


try(form.Close()) catch()
(
	global form = dotnetobject "MaxCustomControls.MaxForm"
	form.Text = "Back Change..."
	
	bt = dotnetobject "Button"
	bt.Text = "Change"
	bt.Dock = bt.Dock.Top
	
	cc = dotnetobject "UserControl"
	cc.Dock = cc.Dock.Fill
	
	bt.tag = cc
	fn onClick s e = 
	(
		if s.tag.BackgroundImage != undefined do s.tag.BackgroundImage.Dispose()
		files = getfiles (getdir #ui + @"icons\*.bmp")
		s.tag.BackgroundImage = (dotnetclass "System.Drawing.Image").FromFile files[random 1 files.count]
	)
	
	dotnet.addEventHandler bt "Click" onClick

	form.controls.AddRange #(cc, bt)
	form.showmodeless()
)

Thanks a lot Branco but I think there was nothing essentially wrong with my code except I forgot to use the tag property and specify the tag explicitly in another line (bgaCB1.tag = bgaFORM) instead of using head.backgroundImage…I keep forgetting that…it’s counterintuitive to me and i think there should be some good fundamentals course in dotnet as it’s such a PIA to learn by trial and error.
Denis -interesting little bit of code…not only do you answer the question, you supply a nifty and amusing little toy at the same time. I don’t get the “usercontrol” dotnetobject tho. What is that? And you don’t need to specify any parameters? I never saw that in the documentation but then I can’t wade thru documentation. I simly don’t have the time. thanks again guys.

1 Reply
(@gazybara)
Joined: 1 year ago

Posts: 0

You can think about usercontrol like container for storing other dotnet controls.And then u can use it inside standard mxs dialog.This is one explanation. Denis will tell you more about this probably.