Notifications
Clear all

[Closed] dotNet anchor to more than one edge in MaxScript

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 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?

3 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

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

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: %
" as_value
	format "Parsed value: %
" 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.

Ah, awesome. Thanks for the help guys.