//PLUGIN {EE6D5D65-B7D5-48A5-86B4-801584E109D3}plugin|test
public override void ProcessPluginCommand(string Command) {
string[] commandsplittext = Command.Split('|');
switch (commandsplite[0]) {
case "plugin":
mainb.atcam_get_macro(commandsplite[1]);
break;
default:
break;
}
public void atcam_get_macro(string str) {
switch (str) {
case "test":
System.Windows.Forms.MessageBox.Show(ps.Busy.ToString());
Com("print='test'"); it work
System.Windows.Forms.MessageBox.Show(ComEx("print='TestEX'")) ; no work
break;
default: break;
} }
public void Com(string comd) {
//ps.DoCommand(token, comd);
ps.InsertCommand(token, comd);
}
private string ComEx(string comd) {
object item=null;
Com("ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT");
ps.DoCommandEx(token, comd, out item);
return item.ToString().TrimEnd();
}
I might be able to help out sometime tomorrow, but for now, it would help to clarify exactly what you are trying to do. Is the main issue that powermill is busy when you try and send the command and want a way around that?
Also it may help to know what you want this command to do. If we know that, it might help someone figure out a workable alternative.
For example, I want to set up my tool ——Using plugins I can set up what I want faster
If I click the button on the plugin directly, he can work smoothly
The function will display the specified page,and Recall the information of the currently active tool。
now I want to bind the macro to the right-click menu
To quickly operate my plugin
i use “ProcessPluginCommand” , Simulate clicking the button or Call function
if i use “invoke” ,powermill is busy,“DoCommandEx” not work ,message:The object reference is not set to the instance of the object(ToolSetMain.Visibility = Visibility.Visible;)
Alright, so I think I have a better idea of things now.
I believe that this is what you are asking for, but I am not 100% sure. If you need help calling macros from within your plugin, then this isn’t what you want. I could explain that as well if needed.
I’ll just talk about how to run methods that are inside your plugin, using a macro with a plugin command.
You can issue commands both with and without using the pluginframework.
With the framework:
public override void ProcessPluginCommand(string Command)
{
List<string> tokens = CommandUtils.GetCommandTokens(Command);
while (tokens.Count > 0)
{
//Get the next token and remove it from the list
string token = CommandUtils.GetStringToken(ref tokens);
//convert token to lowercase
token = token.ToLower();
switch (token)
{
// The name of your command is the case
case "setup_tool":
// call whatever methods you need to, or just put code directly here.
SetupTool();
break;
default:
//if command is not recognised
MessageBox.Show("Command not recognised: " + token);
break;
}
}
}
// This method would be whatever you want the plugin to do in response to the command.
// I prefer to use methods with commands to keep it better organized, but this isn't needed.
public void SetupTool()
{
// Put whatever code you need in here.
}
So, if you wanted to call this command from a macro, the macro would look like this:
PLUGIN {EE6D5D65-B7D5-48A5-86B4-801584E109D3} setup_tool
Then in your right-click menu, just run the macro with that code in it.
Without the framework:
In the plugin guide, this is the example they give to create a command for your plugin without using the framework:
public void ProcessCommand(string Command)
{
if (Regex.IsMatch(Command, @"\s*raise\s*basic_form\s*", RegexOptions.IgnoreCase))
{
RaiseForm();
}
}
private void RaiseForm()
{
// Create the new window, and ensure it's not displayed in the taskbar
m_basic_form = new BasicForm(); m_basic_form.ShowInTaskbar = false;
// Attempt to parent the window with PowerMILL
WindowInteropHelper wih = new WindowInteropHelper(m_basic_form);
wih.Owner = new IntPtr(m_parent_window);
// Show the new window
m_basic_form.Show();
}
So, if you wanted to call this command from a macro, the macro would look like this:
PLUGIN {EE6D5D65-B7D5-48A5-86B4-801584E109D3} raise basic_form
Then in your right-click menu, just run the macro with that code in it.
So in your case, it may look something like:
public void ProcessCommand(string Command)
{
//The words in double quotes can change to whatever you want your command to be called.
if (Regex.IsMatch(Command, @"\s*setup\s*tool\s*",
RegexOptions.IgnoreCase))
{
// Call whatever method you need to run for the command.
// You could just directly insert code,
// but I think calling a method keeps it looking cleaner and more organized.
SetupTool();
}
}
// This method would be whatever you want the plugin to do in response to the command.
// you can call multiple methods if you want to.
public void SetupTool()
{
// Put whatever code you need in here.
}
i copy you code
and successfully compiled
look like not work
could there be a problem somewhere else
i recorded my actions
//there ComEx()
private string ComEx(string comd)
{
object item;
Com("ECHO OFF DCPDEBUG UNTRACE COMMAND ACCEPT");
ps.DoCommandEx(token, comd, out item);
return item.ToString().TrimEnd();
}
Try using:
insert_command("print='TestEx'");
Here is some more information about the different methods if you don't have it already:
These ones are not part of the framework:
These methods are found in the PluginFrameworkBase class of the framework:
sorry last is busy。
this method is only used to issue
i can use insertcommand
but now. I need is the return value
in processplugincommand “docommandex”is not work
and have a question
The scrollbar on the plugin does not work
Mouse wheel events will be intercepted by powermill PLUGIN PANES
only combobox work
So I came across this forum thread:
https://forums.autodesk.com/t5/powermill-forum/is-anyone-know-why-quot-docommand-quot-and-quot-docom...
It looks like if you need to capture information from Powermill when powermill is busy you need to create a new thread to do so. I have not tried this and cannot guarantee that it will work, but in that forum thread someone apparently explains how to do it.
As for mouse wheel events, if I want a to scroll in a ListBox or some other control with the mouse wheel, I wrap them in a scroll viewer and attach this to the PreviewMouseWheel event:
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
ScrollViewer scv = (ScrollViewer)sender;
scv.ScrollToVerticalOffset(scv.VerticalOffset - e.Delta);
e.Handled = true;
}
Here is the xaml that I used for one of my plugins:
yes,It is correct to create a new thread
If you want to update the ui, you have to go back to the main thread,
it's work
This is the code after my test
private Thread tr;
public override void ProcessPluginCommand(string Command)
{
tr = new Thread(SwitchVoid);
tr.Start();
}
private void SwitchVoid()
{
mainb.TestEX();
tr.Abort();
}
public void TestEX()
{
System.Windows.Forms.MessageBox.Show("Test");
ps.InsertCommand(token,"print=Test");
System.Windows.Forms.MessageBox.Show(ComEx("print='TestEX'"));
Dispatcher.Invoke(DispatcherPriority.Normal,
(ThreadStart)delegate ()
{
UWH_groove_main.Visibility = Visibility.Visible;
});
}
and the mouse wheel events
When I add previewmousewheel events to "scrollview" or "listview"
Place the mouse in the listview and scroll the wheel
None of them respond
Only the entire vertical plug-in window of powermill is moved
<ScrollViewer PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<ListView PreviewMouseWheel="NCoutputmain_Lv_PreviewMouseWheel" x:Name="NCoutputmain_Lv"
private void NCoutputmain_Lv_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Test_listview");
}
private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
System.Windows.Forms.MessageBox.Show("Test_Scroll");
}
I tried replicating your problem, but I couldn't. I have no problem with the PreviewMouseWheel event getting triggered, everything works fine for me. Do you have some other mouse event that would interfere with it?
I actually upgraded from powermill 2015 to 2016 yesterday, and funnily enough now also have your problem with scrolling. I never had it with powermill 2015, so now I am just as lost as you.
Can't find what you're looking for? Ask the community or share your knowledge.