View Full Version : dotNet anchor to more than one edge in MaxScript
Mathieson 01-09-2010, 09:04 PM Can anybody explain how to assign more than one anchorstyle to the anchor property in dotNet? I cannot make sense of the examples on the MSDN page (http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx) when relating to MaxScript.
It appears they are using an or comparison to set it to the bottom right corner, which doesn't work in MaxScript. Assigning one after the other just overwrites the first when assigning the second, which I expected.
So yeah, I'm not too sure what to do here. How do I assign an object to anchor to more than one edge?
|
|
denisT
01-09-2010, 10:16 PM
Can anybody explain how to assign more than one anchorstyle to the anchor property in dotNet? I cannot make sense of the examples on the MSDN page (http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx) when relating to MaxScript.
It appears they are using an or comparison to set it to the bottom right corner, which doesn't work in MaxScript. Assigning one after the other just overwrites the first when assigning the second, which I expected.
So yeah, I'm not too sure what to do here. How do I assign an object to anchor to more than one edge?
AnchorStyles is Enumeration. to set a combination use dotnet.combineEnums
sample:
bt.anchor = dotnet.combineEnums bt.anchor.Top bt.anchor.Bottom bt.anchor.Left bt.anchor.Right
Pjanssen
01-09-2010, 10:21 PM
The problem you're facing is that the dotnet/mxs implementation is expecting a value of type AnchorStyles. This happens to be an int enum. In .NET, you can combine these using the OR operator, they'll be treated as an int, and I guess cast back to an AnchorStyles type again. In max, you can do this too, but then you can't assign it directly anymore: it'll complain about non matching type.
I fiddled around a bit with the Enum.Parse method, which could get you the appropriate AnchorStyles enum value you're after. It's a bit of a long shot, but I think it might work:
(
local as_class = dotNetClass "System.Windows.Forms.AnchorStyles"
local as_type = as_class.none.GetType() -- get the enum type
local as_value = (bit.or as_class.bottom.value__ as_class.right.value__) -- get the correct enum int value
local comb_enum = as_class.Parse as_type (as_value as string) -- Use the Enum.Parse function to get a AnchorStyles enum
format "Required value: %\n" as_value
format "Parsed value: %\n" comb_enum.value__
)
I hope this helps, and works.
edit: too late.. although my way is creative, dotnet.combineEnums would be the better way to go, missed that one. :)
Mathieson
01-10-2010, 03:13 AM
Ah, awesome. Thanks for the help guys.
CGTalk Moderation
01-10-2010, 03:13 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.