Community
PowerShape and PowerMill API Forum
Welcome to Autodesk’s PowerShape and PowerMill API Forums. Share your knowledge, ask questions, and explore popular API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plugin get the active workplane

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
rui_rita
1210 Views, 10 Replies

Plugin get the active workplane

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



Os melhores cumprimentos | Best regards
Rui Rita
________________________________
NEWCAM, Lda.
10 REPLIES 10
Message 2 of 11
nbaranowski
in reply to: rui_rita

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;
Message 3 of 11

Alternatively you could use:

comboBox1.SelectedItem = pmProject.ActiveWorkplane.Name

Luke Edwards
Consulting Services Manager
Message 4 of 11

I'm working with powermill plugin interface...

 

if (wrkpl.IsActive)
comboBox1.SelectedItem = pmProject.ActiveWorkplane.Name

 

 

 

doesn't exist

 

 



Os melhores cumprimentos | Best regards
Rui Rita
________________________________
NEWCAM, Lda.
Message 5 of 11
rui_rita
in reply to: rui_rita

@luke.edwards.autodesk

@nbaranowski

 

Do you know if there is something like your answers in the plugin?

 

thank you



Os melhores cumprimentos | Best regards
Rui Rita
________________________________
NEWCAM, Lda.
Message 6 of 11

Ok, no I don't know I'm afraid.  You would have to get this through macro commands.


Luke Edwards
Consulting Services Manager
Message 7 of 11

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

Message 8 of 11
rui_rita
in reply to: Vasago

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.



Os melhores cumprimentos | Best regards
Rui Rita
________________________________
NEWCAM, Lda.
Message 9 of 11
TK.421
in reply to: Vasago


@Vasago wrote:

- If it is an external application, you will have to pull thread and ask from time to time if there is any active workplane ..


 

How do I do that?

--------------------------------------
the numbers never lie
Message 10 of 11
TK.421
in reply to: Vasago

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.

--------------------------------------
the numbers never lie
Message 11 of 11
rui_rita
in reply to: TK.421

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>



Os melhores cumprimentos | Best regards
Rui Rita
________________________________
NEWCAM, Lda.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report