PDA

View Full Version : Unhide by layer


Kameleon
04-06-2009, 10:52 AM
Hi guys, I thought I'd already posted this here but I guess I did not... It's something quite simple but at least for me it came quite handy. Once in a while I pick this up and add some new stuff, but don't wait for me on that :P Cheers and I hope this is of use to some of you.

macroScript UnhideObjectbyLayer
category:"K Scripts"
(
dotNet.loadAssembly "MaxCustomControls.dll"

local hForm = dotNetObject "MaxCustomControls.MaxForm"
hForm.Size = dotNetObject "System.Drawing.Size" 250 400
hForm.MaximizeBox=False
hForm.MinimizeBox=False
hForm.Text = "Unhide by Layer"
hForm.ShowInTaskbar = False

local lstView = dotNetObject "System.Windows.Forms.ListView"
lstView.Dock = (dotNetClass "System.Windows.Forms.DockStyle").Fill
lstView.View= (dotNetClass "System.Windows.Forms.View").Details
lstView.MultiSelect = False
lstView.FullRowSelect = True
lstView.Sorting = (dotnetclass "System.Windows.Forms.SortOrder").Ascending
lstView.Columns.Add "Layers" 140
lstView.Columns.Add "Active" 50

local mPanel = dotnetobject "System.Windows.Forms.Panel"
mPanel.Size = dotNetObject "System.Drawing.Size" 150 40
mPanel.Dock = (dotnetclass "System.Windows.Forms.DockStyle").Bottom

local btnUnhide = dotNetObject "System.Windows.Forms.Button"
btnUnhide.Size = dotNetObject "System.Drawing.Size" 60 22
btnUnhide.Location = dotNetObject "System.Drawing.Point" ((hForm.Size.Width/2)-30) 10
btnUnhide.Text = "Unhide"

local lstViewItems=#()
for i=0 to LayerManager.count-1 do
(
layer=LayerManager.getLayer i
append lstViewItems layer.name

)

for i=1 to lstViewItems.count do
(
cLayer=LayerManager.getLayer (i-1)
cLayer=cLayer.current
if cLayer==true then lstViewItems[i]= dotNetObject "System.Windows.Forms.ListViewItem" #(lstViewItems[i], "X")
else lstViewItems[i]= dotNetObject "System.Windows.Forms.ListViewItem" #(lstViewItems[i], "-")
)

fn btnUnhide_Click sender args =
(
layer=undefined
if lstView.SelectedItems.Count!=0 then
(
for i=0 to LayerManager.count-1 do
(
layer=layerManager.getLayer i
layer_name=layer.name
if layer_name==lstView.SelectedItems.Item[0].Text then exit
)
layer.nodes &arr_nodes
for i in arr_nodes do unhide i
hForm.Dispose()
)
)

fn hForm_SizeChanged sender args =
(
btnUnhide.Location = dotNetObject "System.Drawing.Point" ((hForm.Size.Width/2)-30) 10
)

dotnet.addEventHandler btnUnhide "Click" btnUnhide_Click
dotnet.addEventHandler hForm "SizeChanged" hForm_SizeChanged

lstView.Items.AddRange lstViewItems

mPanel.Controls.Add btnUnhide

hform.Controls.Add lstView
hform.Controls.Add mPanel

hForm.ShowModeless()
)

JHN
04-06-2009, 11:17 AM
Artur, thanks for sharing!
Can I ask why you would use a maxForm object over a normal dotnet form. And what more objects do live in the MaxCustomControls?

Thanks!
-Johan

ZeBoxx2
04-06-2009, 11:19 AM
you can always check what an assembly exposes using the getExportedTypes() method.


maxcc = dotNet.loadAssembly "MaxCustomControls.dll"
print (maxcc.GetExportedTypes())

JHN
04-06-2009, 11:52 AM
Excellent! I need to do even more dotnet reading I see :)
I didn't find this method in the mxs helpfile though... hmmm.

Thanks,
-Johan

ZeBoxx2
04-06-2009, 12:52 PM
it's a method of the .NET assembly loaded, so not native to MaxScript itself. When you load the assembly, assign it to a variable, then call the MaxScript showProperties() and showMethods() on it; getExportedTypes() is one of the methods listed there :)

JHN
04-06-2009, 12:57 PM
I tried that, but got back red lettered errors... trying it again now after a restart it works, probably did something wrong, which is totally plausible :)

Thanks,
-Johan

LoneRobot
04-06-2009, 01:13 PM
Hi Artur, thanks for sharing.

Johan, these are all listed in the dotnet SDK help file also if you needed some bedtime reading.

Can I ask why you would use a maxForm object over a normal dotnet form. And what more objects do live in the MaxCustomControls?

best thing about Maxform is that it will be the correct interface color, bypassing the need for getting the max UI color and passing that to a dotnet backcolor. There is also a maxusercontrol too, presumably to use when inheriting a custom control.

Kameleon
04-06-2009, 02:21 PM
Hey, thanks!
It seems that the guys already answered your question (yes I do have a break to have lunch now and then :P) either way, I started using MaxForm because of the problems with the focus on textboxes and I've never looked back although in some cases I really don't like the idea of having Max UI colors on the form and controls because on some controls it doesnt work that good, like Tabs for instance, it looks weird, at least to me who use the dark ui scheme. Cheers!!!

LoneRobot
04-06-2009, 02:51 PM
I noticed you linked to me artur from your site, many thanks! :thumbsup:

CGTalk Moderation
04-06-2009, 02:51 PM
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.