RobotStudio event

Set/Reset Visible using VSTA

Options
I have about 100 objects in my simulation that I need to be able to set or reset the visible property for that object from VSTA.  Can someone give me a small example of how to reference that object from VSTA and set its visible property?  I found an example that shows how to set the current selected items visible property but these will not be selected.  I need to be able to set any objects visible property.

BR

Comments

  • Hi!
    With the following code you can iterate through the objects in the scene and make the object with name xy invisible:

    [code]
    station = Project.ActiveProject as Station;
    foreach (GraphicComponent gc in station.GraphicComponents)
        if(gc.Name.equals("xy"))
            gc.Visible = false;
    [/code]

    Best Regards,
    Matthias

  • Thank you for the response.  I can make this work, but I would rather not loop through all the objects and just reference the one I want.  I think that it will take to long.
  • This did not work BTW it gives me a error (The name 'station' does not exist in the current context)
  • You can try
    [code]
    station.GraphicComponents.TryGetGraphicComponent(String str, out: GraphicComponent gc)
    [/code]

    to get the component with name str in GraphicComponent gc

  • Thank you for trying but I think I am not using the same version as you.  I am missing GraphicComponents from the station.  Are you doing this in VSTA or VS making a Addin?  I am working in VSTA.
  • PerSvensson
    Options
    Hi David

    This may give you some hints
    In my example 'myComponent' is just the name of a box.

    public void Macro_SwitchVisible()
    {
    Station stn = Project.ActiveProject as Station;
    if (stn == null) return;
    GraphicComponent gc = stn.GraphicComponents["myComponent"];
    gc.Visible = !gc.Visible;
    }
    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering
  • Hi Per
    That works if my object is in the root of the tree but how do you reference a obj that is inside of a component that is inside of a component?  For Example say I have a Component called CIMLetters and inside that component I have a component called LetterC.  Inside that component is my actual object.  How do I reference down through the two to the object in the string name?

  • PerSvensson
    Options
    Hi David
    There is a metod for finding certain types(no matter location in the station)  but this doesn't seam to work in VSTA and still you need to loop thru what it reports. But anyway here is an example



    Station stn = Project.ActiveProject as Station;
    if (stn == null) return;
    GraphicComponent[] gcParts = stn.FindGraphicComponentsByType(typeof(Part));
    foreach (Part prt in gcParts)
    {
    prt.Visible = !prt.Visible;
    }

    Per Svensson
    Robotics and Vision Specialist
    Consat Engineering