Notifications
Clear all

[Closed] Dot net control on CA modifier not working

I’ve been using a dotnet control that creates a spline and handles for changing its shape…works fine, but then I created a modifier with a button that opens this dotnet form in another window, except that there is no spline being drawn in this window. Why is that?

19 Replies
 lo1

draws a spline object in the scene or draws a spline on the control?
In either case, some test code would be helpful.

Spline isn’t drawn in the window…here is the code…

delete objects
ctrlcentre = circle radius:5
morphs_used =#("up","down","turnaround")
attStr = ""
fn createWindow =
(try(form.close())catch()
--clearListener()
 
 
--Set the parent of the form to be Max. 
--Get the max handle pointer.
maxHandlePointer=(Windows.GetMAXHWND())
--Convert the HWND handle of Max to a dotNet system pointer
sysPointer = DotNetObject "System.IntPtr" maxHandlePointer
--Create a dotNet wrapper containing the maxHWND
maxHwnd = DotNetObject "MaxCustomControls.Win32HandleWrapper" sysPointer
--Show the Max form using the wrapper. 
 
form=dotNetObject "form"
form.Show (maxHwnd)
 
theImage = dotNetClass "System.Drawing.Image" --create an Image dotNetClass
theBitmap = theImage.FromFile "logo.bmp"--get the saved image from file as bitmap
 
graph=dotNetObject "label"
--graphbk = dotNetClass "system.drawing.Image"
graph.BackgroundImage = theBitmap 
 
graph.backColor=(dotNetClass "system.drawing.color").fromArgb 100 100 100
graph.bounds=dotNetObject "system.drawing.rectangle" 10 10 300 300
dotNet.addEventHandler graph "paint" paintGraph
fn bezier2D p1 p1t p2t p2 t=
(
Q1 = (p1t - p1) * t + p1
Q2 = (p2t - p1t) * t +p1t
Q3 = (p2 - p2t) * t +p2t
 
Q4 = (Q2 - Q1) * t + Q1
Q5 = (Q3 - Q2) * t + Q2
 
Q5 = (Q5 - Q4) * t + Q4
)
 
 
-- .DrawLine <System.Drawing.Pen>pen <System.Drawing.Point>pt1 <System.Drawing.Point>pt2
redCol=(dotNetClass "system.drawing.color").orange
blueCol=(dotNetClass "system.drawing.color").blue
col=(dotNetClass "system.drawing.color").blue
redPen=dotNetObject "system.drawing.pen" redCol 2
bluePen=dotNetObject "system.drawing.pen" blueCol 2
 
fn paintGraph sender arg =
(
g=arg.graphics
-- showMethods g
 
local p1=sender.controls.item[0].location
local p1t=sender.controls.item[1].location
local p2t=sender.controls.item[2].location
local p2=sender.controls.item[3].location
 
g.drawLine redPen p1 p1t
g.drawLine redPen p1t p2t
g.drawLine redPen p2t p2
 
for t = 0 to 1 by .01 do
(
dp=bezier2D [p1.x+5,p1.y+5] [p1t.x+2,p1t.y+2] [p2t.x+2,p2t.y+2] [p2.x+5,p2.y+5] t
drawPoint=dotNetObject "system.drawing.point" dp.x dp.y
 
if sender.tag!=undefined do
(
g.drawLine bluePen sender.tag drawPoint
)
sender.tag=drawPoint
)
sender.tag=undefined
)
 
fn mouseMove sender arg=
(
if arg.button==arg.button.left do
(
sender.location=(sender.parent.PointToClient sender.MousePosition)
graph.invalidate()
)
)
--showproperties lb1.location
--lb1t.location.Y
 
lb1=dotNetObject "label"
--lb1.BackgroundImage = dotNetObject "system.drawing.Image" theBitmap
lb1.size=dotNetObject "system.drawing.size" 11 11
lb1.backColor=(dotNetClass "system.drawing.color").green
lb1.location=dotNetObject "system.drawing.point" 20 280
dotNet.addEventHandler lb1 "mouseMove" mouseMove
lb1t=dotNetObject "label"
lb1t.size=dotNetObject "system.drawing.size" 5 5
lb1t.backColor=(dotNetClass "system.drawing.color").green
lb1t.location=dotNetObject "system.drawing.point" 100 280
dotNet.addEventHandler lb1t "mouseMove" mouseMove
lb2=dotNetObject "label"
lb2.size=dotNetObject "system.drawing.size" 11 11
lb2.backColor=(dotNetClass "system.drawing.color").red
lb2.location=dotNetObject "system.drawing.point" 280 20
dotNet.addEventHandler lb2 "mouseMove" mouseMove
lb2t=dotNetObject "label"
lb2t.size=dotNetObject "system.drawing.size" 5 5
lb2t.backColor=(dotNetClass "system.drawing.color").red
lb2t.location=dotNetObject "system.drawing.point" 200 20
dotNet.addEventHandler lb2t "mouseMove" mouseMove
 
--Note the order they are added. This is just so I know what order to calc them in. 
graph.controls.add lb1
graph.controls.add lb1t
 
graph.controls.add lb2t
graph.controls.add lb2
 
form.controls.add graph
form.show()
form.size=dotNetObject "system.drawing.size" 340 360
form.text="Bezier Control Test"
dotNet.setLifeTimeControl graph #dotNet
dotNet.setLifeTimeControl lb1 #dotNet
dotNet.setLifeTimeControl lb1t #dotNet
dotNet.setLifeTimeControl lb2 #dotNet
dotNet.setLifeTimeControl lb2t #dotNet
fn formatProps dn=
(
if classOf dn==dotNetObject or classOf dn==dotNetClass then
(
clearListener()
format "Properties:
"
showProperties dn
format "
Methods:
"
showMethods dn
format "
Events:
"
showEvents dn
)else
(
format "% is not a dotNetObject or dotNetClass
" dn
)
)
--showmethods (dotnetclass "system.drawing.image")
 
)
addmodifier ctrlcentre (EmptyModifier ())
(
attStr += "attdef = attributes facialctrl
"
attStr += "(
"
attStr += " parameters facialctrl rollout:Weights
"
attStr += " (
"
 
for k = 1 to morphs_used.count do 
( 
attStr += " " + morphs_used[k] + " type:#float ui:" + morphs_used[k] as string + "Sl
"
)
 
attStr += " )
"
attStr += " rollout Weights \"Weights\"
"
attStr += " (
"
attStr += " local range = [-2,2,1]
"
attStr += " group \"Upper Left Position\"
"
attStr += " (
"
 
for k = 1 to morphs_used.count do 
(
attStr += " slider " + morphs_used[k] + "Sl \""+ morphs_used[k] + "\" range:range
" 
)
 
attStr += " )
"
attStr += " group \"Upper Right Position\"
"
attStr += " (
"
attStr += " )
"
attStr += " button createWindow \"CreateWindow\" 
"
attStr += " on createWindow pressed do
"
attStr += " (createWindow()
"
 
attStr += " )
"
 
attStr += " )
"
attStr += ")"
ok
)
 
format "%
" attStr
attdeff = execute attStr
custAttributes.add ctrlcentre.modifiers[1] attdeff

I note that the maxscript rollout version of this window doesn’t have this problem.

 lo1

your code generates this exception for me and does not run:

-- Compile error: No outer local variable references permitted here:  redPen
--  In line: 	g.drawLine redPen p

redPen is defined outside the nested function.

 lo1

In fact, there are a lot of consequential exceptions, I had to get rid of the whole nested function layout. I am not sure how this runs for you. In any case, the spline is not drawing because the graph’s paint event is not being triggered.
Personally, I’d rewrite the whole thing as a struct.

edit: seems no dotnet events are being registered when run from inside the CA.

ok…that last comment is the most important…no dot net events registered inside ca? OK…well that saves me a lot of time trying to get it to work I guess…it works for me but no blue line, no tangent handles…
edit: However the ca simply runs the createwindow function, which is independent of the ca isnt it?

 lo1

perhaps there’s a solution, I’ll try to look into it.

 lo1

Here is one possible workaround:

rollout dummyRollout ""
(
	on dummyRollout open do
	(
		::createWindow()
		destroyDialog dummyRollout
	)
)

attStr += " button createWindow \"CreateWindow\" 
"
attStr += " on createWindowBtn pressed do
"
attStr += " (
createDialog dummyRollout
"

 lo1

Yes. I can’t explain it, but max is quirky like that.
I’ve used the dummy rollout solution in the past and it seemed to work just fine. Ideally you’d create it off-screen so the user doesn’t experience that momentary flicker.

Ok thanks I will try that…

Page 1 / 2