[Closed] c# custom action button
Hey guys been practicing c# in this past few weeks :banghead: :banghead: . I tried to make custom button , when I click it I can execute my customFunction without using event handler [the weak of this action is because its only allow me to execute function without ado thing ex: myFunction thisobject , instead its only allow me to execute myfunction only [maybe if other know gimme some light how to do it in add eventhandler], ref link would do]…it become bottleneck to my workflow, so I planning to write my custom button here… here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using ManagedServices;
namespace thisButtox
{
class Buttos : Button
{
//check if this dll run in max or not, if not run in max then do nothing, if run in max then execute the script.
protected override void OnClick(EventArgs e)
{
string thisFunction = null; \\for customized later.
if (thisFunction != null)
{
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(thisFunction);
}
base.OnClick(e);
}
}
}
im stumble upon how to check if this custom dll run in max or not ?
and second how to convert like ex : thisFunction myBox to “thisFunction myBox” in c#, I can do it in maxscript but I want to compile it in my dll.
Thanks in advance .
trying to answer my own question and hope useful to someone…
using System;
using System.Windows.Forms;
using ManagedServices;
namespace myClassOne
{
class Class1
{
static bool runAsMaxApp = false;
public static void runAsMax()
{
AppDomain curDomain = AppDomain.CurrentDomain;
string str = curDomain.FriendlyName.ToString();
if (str.ToLower() == "3dsmax.exe")
{
runAsMaxApp = true;
}
else
{
runAsMaxApp = false;
}
}
public static void executeThisScript(string fns)
{
if (fns != null)
{
MaxscriptSDK.ExecuteMaxscriptCommand(fns);
}
}
public static void exeThis()
{
if (runAsMaxApp ==true)
{
executeThisScript("messageBox \"This script executed via dotnet !\"");
}
else
{
MessageBox.Show(AppDomain.CurrentDomain.FriendlyName.ToString());
}
}
}
}
compile that as dll, for testing [the importatant part is runAsMax(), everything else is addon ]
theDll= @"{my dll dir}\myClassOne.dll"
fn LoadDynamicDllMax theDllFile=
(
(dotnetclass "System.Reflection.Assembly").Load ((dotnetclass "System.IO.File").ReadAllBytes theDllFile)
)
clearlistener()
LoadDynamicDllMax theDll
aa = dotnetObject "myClassOne.Class1"
aa.exeThis()
– to see the result if this dll running inside max or not, if this running on 3dsmax it’ll max messagebox “This script executed via dotnet !”, else will excute .net messagebox.
The purpose of this is to prevent dll we created show error missing reference when we try to load it outside 3dsmax app. Theres always welcome for another input.
Thanks