Cancel
Showing results for 
Search instead for 
Did you mean: 

API: Selecting operation root levels.

Creator
Creator

Hi everyone,

 

I am quite new to process simulate and its API. Right now i am trying to access/select the last Via location Operation thats inside of a Compund Operation which is also inside another Compound Operation.

 

For more graphical explanation:

-Compund Operation

    -Compound Operation

        -......

        -......

        -......

        -Last Via LocationOperation

 

Right know i have been able to filter the the first level of compond operations but have no idea on how to access that second level and so on. For filtering on that first level i used:

 

TxTypeFilter Sel_Filter = new TxTypeFilter(typeof(TxCompoundOperation));
            TxObjectList Selection_1 = TxApplication.ActiveDocument.OperationRoot.GetDirectDescendants(Sel_Filter);

 

 Would it make sense to get all compound operations and then filter them depending on the level that they are?

Could anyone help me by giving some direction on how to proceed from here?

 

Sorry for the newbie question and thanks in advance

5 REPLIES

Re: API: Selecting operation root levels.

Genius
Genius

Hello Lucas

 

Maybe the code below can help you achieve what you want, please let me know if this is what you're looking for and try to compile it. The code below looks for a compound operation name, but you can adapt for your particular needs.

 

           TxTypeFilter Sel_Filter = new TxTypeFilter(typeof(TxCompoundOperation));
           TxObjectList Selection_1 = TxApplication.ActiveDocument.OperationRoot.GetDirectDescendants(Sel_Filter);

            foreach (TxCompoundOperation compOp in Selection_1)
            {
                if (compOp.Name == "The name of desired compound")
                {
                    TxObjectList weldList = compOp.GetAllDescendants(new TxTypeFilter(typeof(TxRoboticViaLocationOperation)));
                    TxRoboticViaLocationOperation lastViaLoc = weldList[weldList.Count - 1] as TxRoboticViaLocationOperation;
                }
            }

 

 Regards,

Re: API: Selecting operation root levels.

Creator
Creator

Thanks FredCastro, that was a good solution on how to proceed. But now the next road block appears, this identying of robot via location needs to be done in a iterative way until no more last via locations are found. This would mean that inside of the "Selection1" there is more than just one(unknown number) CompoundOp where you need to get that last via-location.

 

I have tried to look for a way of renaming "Weldlist" but seems like you cant dynamically create a list inside a for loop.

 

Any idea/hint on how to proceed?

 

Thanks once again for your help.

Re: API: Selecting operation root levels.

Genius
Genius

Maybe something like this can work. You'll have an array list of last via locations at the end.

 

  {
            TxTypeFilter Sel_Filter = new TxTypeFilter(typeof(TxCompoundOperation));
            TxObjectList Selection_1 = TxApplication.ActiveDocument.OperationRoot.GetDirectDescendants(Sel_Filter);
            TxRoboticViaLocationOperation[] lastViaList = new TxRoboticViaLocationOperation();
            int i = 0;

            foreach (TxCompoundOperation compOp in Selection_1)
            {
                    TxObjectList weldList = compOp.GetAllDescendants(new TxTypeFilter(typeof(TxRoboticViaLocationOperation)));
                    TxRoboticViaLocationOperation lastViaLoc = weldList[weldList.Count - 1] as TxRoboticViaLocationOperation;
                    lastViaList.SetValue(lastViaLoc, i);
                    i++;
            }
        }

 

PS: I'm not actually compiling the code, just trying to give you ideas.

 

Regards,

 

 

Re: API: Selecting operation root levels.

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Lucas_SWE,

 

Do you really have only compound operations and not weld operations or other robotic operations?

If only compound operations, then FredCastro gave you a good example. I would only add that in order to access the compounds on the second level you need one more time to get the DirectDescendants of type TxCompoundOperation.

TxTypeFilter Sel_Filter = new TxTypeFilter(typeof(TxCompoundOperation));
TxObjectList Selection_1 = TxApplication.ActiveDocument.OperationRoot.GetDirectDescendants(Sel_Filter);
foreach(TxCompoundOperation compoundOp in Selection_1)
{
     TxObjectList Selection_level_2 = compoundOp.GetDirectDescendants(Sel_Filter);
     foreach(TxCompoundOperation op in Selection_level_2)
     {
            //here use the code that gets the vias
     }
 }

Best Regards,

DianaG

Re: API: Selecting operation root levels.

Experimenter
Experimenter

Just to add and make things easier ive built an extension library to help speed things along.

 

public static class TecnomatixEx{
  
public static List<T> GetAllDescendants<T>(this ITxObjectCollection obj)
where T:ITxObject
{
var filter = new TxTypeFilter(typeof(T));
var = obj.GetAllDescendants(filter)
 .OfType<T>()
 .ToList();
return result;
}

public static List<T> GetDirectDescendants<T>(this ITxObjectCollection obj)
where T:ITxObject
{
var filter = new TxTypeFilter(typeof(T));
var result = obj.GetDirectDescendants(filter)
   .OfType<T>()
   .ToList();
return result;

}
}


then you can just do 

var items = TxApplication.ActiveDocument.OperationRoot.GetDirectDescendants<TxCompoundOperation>()
   .SelectMany(o=>o.GetDirectDescendants<TxCompoundOperation>();

foreach(var item in items)
{

  // Do yourstuff here.

 
}
 

 

 

I know it does the same thing but the extension really helps over time.