hi,
I have this code to populate a combo box with the list of the workplanes from the project
Workplanes wrkpls = PMProject.Workplanes;
foreach (Workplane wrkpl in wrkpls)
{
wrkpl_cmb.Items.Add(new MyData(wrkpl.Name.ToString(), wrkpl.Name.ToString()));
}
I want to set my selected item in the combobox the active workplane... How can I know what workplane is active?
thank you for the help
Solved! Go to Solution.
Solved by rui_rita. Go to Solution.
This should do the trick:
PMAutomation powerMILL = new PMAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance); PMProject pmProject = powerMILL.ActiveProject; PMWorkplanesCollection wrkpls = pmProject.Workplanes; PMWorkplane active = null; foreach (PMWorkplane wrkpl in wrkpls) { comboBox1.Items.Add(wrkpl.Name); if (wrkpl.IsActive) { active = wrkpl; } } comboBox1.SelectedItem = active.Name;
Alternatively you could use:
comboBox1.SelectedItem = pmProject.ActiveWorkplane.Name
I'm working with powermill plugin interface...
if (wrkpl.IsActive)
comboBox1.SelectedItem = pmProject.ActiveWorkplane.Name
doesn't exist
Do you know if there is something like your answers in the plugin?
thank you
Ok, no I don't know I'm afraid. You would have to get this through macro commands.
Is it an embedded plugin or an external application?
- If it is a plugin, you can access the events of subscribing to them and managing them in the process process method, with EntityActivated
- If it is an external application, you will have to pull thread and ask from time to time if there is any active workplane ..
I have an embedded plugin that launches me through messageQUEUE when there is an event in Powermill, it is a more or less clean solution until in the libraries the events are implemented in powermill
hi @Vasago
it is a embedded plugin. I'm trying to reproduce the beahavier of a toolpath form in the workplane tab.
I will need the get event EntityActivated, for when I activate a workplane outside the plugin, for the intial when I run my form, I will try the sugestion from @luke.edwards.autodesk
thank you all for the tips.
so after some web browsing and hacking things together, I've come up with this:
public MainWindow() { InitializeComponent(); System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Interval = 500; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } private void timer_Tick(object sender, EventArgs e) { RoutedEventArgs newEventArgs = new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent); button1.RaiseEvent(newEventArgs); } private void button1_Click(object sender, RoutedEventArgs e) { if (powerMill.ActiveProject.Workplanes.ActiveItem == null) { activeWorkplane.Content = "None"; } else { activeWorkplane.Content = powerMill.ActiveProject.Workplanes.ActiveItem.Name; } }
This works, but obviously it continues to send button click events to powermill, and I have an unsightly button that serves no other purpose... I've been using it for a bit like this and haven't noticed any difference in functionality. What kind of problems could this pose in the future? Is there another way I should be going about this? I would like to have my app display a slew of parameters for quick reference.
Hi
I solve my problem using this...
(subscribe events)
....
sub_id_wkplAct= m_services.SubscribeToFilteredEvent(m_token,"EntityActivated", "EntityType", "Workplane");
sub_id_wkplDeact = m_services.SubscribeToFilteredEvent(m_token, "EntityDeactivated", "EntityType", "Workplane");
sub_id_wkplCreate = m_services.SubscribeToFilteredEvent(m_token, "EntityCreated", "EntityType", "Workplane");
sub_id_wkplDelete = m_services.SubscribeToFilteredEvent(m_token, "EntityDeleted", "EntityType", "Workplane");
sub_id_wkplRename = m_services.SubscribeToFilteredEvent(m_token, "EntityRenamed", "EntityType", "Workplane");
....
When the event occur call this function
....
public void getEntityEvent(string p_token, PowerMILL.PluginServices p_services, string XMLEventData)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(XMLEventData);
m_token = p_token;
m_services = p_services;
// Workplane events
if (xmlDoc.DocumentElement.Attributes["subscription_id"].Value.ToString() == sub_id_wkplAct.ToString()) {
wrkpl_cmb.SelectedItem = m_services.GetParameterValueTerse(m_token, "Workplane.Name");
}
if (xmlDoc.DocumentElement.Attributes["subscription_id"].Value.ToString() == sub_id_wkplDeact.ToString()) {
wrkpl_cmb.SelectedIndex = 0;
}
if (xmlDoc.DocumentElement.Attributes["subscription_id"].Value.ToString() == sub_id_wkplCreate.ToString()) {
populate_wrkpl_cmb();
}
if (xmlDoc.DocumentElement.Attributes["subscription_id"].Value.ToString() == sub_id_wkplDelete.ToString()) {
populate_wrkpl_cmb();
}
if (xmlDoc.DocumentElement.Attributes["subscription_id"].Value.ToString() == sub_id_wkplDelete.ToString())
{
populate_wrkpl_cmb();
}
if (xmlDoc.DocumentElement.Attributes["subscription_id"].Value.ToString() == sub_id_wkplRename.ToString())
{
populate_wrkpl_cmb();
}
}
...
and this to polpulate my combobox
private void populate_wrkpl_cmb()
{
wrkpl_cmb.Items.Clear();
wrkpl_cmb.Items.Add("Nenhnum");
Workplanes wrkpls = m_services.Project.Workplanes;
if (wrkpls.Count > 0) {
foreach (Workplane wrkpl in wrkpls)
{
wrkpl_cmb.Items.Add(wrkpl.Name.ToString());
}
}
string s = m_services.GetParameterValue(m_token, "Workplane.Name");
if (s.Contains("Erro") || s.Contains("error"))
{
wrkpl_cmb.SelectedIndex = 0;
} else
{
wrkpl_cmb.SelectedItem = m_services.GetParameterValueTerse(m_token, "Workplane.Name");
}
you can see the result
<iframe width="640" height="620" src="https://screencast.autodesk.com/Embed/Timeline/66fe1517-548d-45d1-a692-f82ddba7889a" frameborder="0" allowfullscreen webkitallowfullscreen></iframe>