Cancel
Showing results for 
Search instead for 
Did you mean: 

Copy & manipulate operation

Siemens Legend Siemens Legend
Siemens Legend

Question:

 

I want to copy an existing operation, manipulate the copied operation and after that, i want to add the modified operation to the active document operation root.

Do you have a code example for me?

 

Answer: 

 

To copy an operation under the Operation Root or any other compound operation use the CanPasteList and Paste methods of ITxObjectCollection interface.

 

After that you can modify the new operation content (add/remove child operations or change a child operation absolute location, etc.)

 

 Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.DataTypes;

namespace Example
{
    class OperationExample
    {

        public void Execute()
        {
            TxObjectList operations = TxApplication.ActiveSelection.GetFilteredItems(new TxTypeFilter(typeof(ITxOperation)));
            if (operations.Count > 0)
            {
                ITxOperation op = operations[0] as ITxOperation;
                TxOperationRoot operartionRoot = TxApplication.ActiveDocument.OperationRoot;

                TxObjectList operationsToCopy = new TxObjectList();
                operationsToCopy.Add(op);

                TxObjectList operationsCopies = null;
                if (operartionRoot.CanPasteList(operationsToCopy))
                    operationsCopies = operartionRoot.Paste(operationsToCopy);

                if (operationsCopies != null && operationsCopies.Count > 0)
                {
                    ITxOperation opCopy = operationsCopies[0] as ITxOperation;

                    //now you can modify the copy of the original operation

                    //1. Add robotic via location operation if it is possible
                    ITxRoboticViaLocationOperationCreation operationWithChildren = opCopy as ITxRoboticViaLocationOperationCreation;
                    if (operationWithChildren != null)
                    {
                        TxRoboticViaLocationOperationCreationData creationData = new TxRoboticViaLocationOperationCreationData("via1");
                        creationData.AbsoluteLocation = new TxTransformation();
                        if (operationWithChildren.CanCreateRoboticViaLocationOperation(creationData))
                        {
                            TxRoboticViaLocationOperation viaLocation = operationWithChildren.CreateRoboticViaLocationOperation(creationData);
                            //Modify the via location
                            TxTransformation absLoc = viaLocation.AbsoluteLocation;
                            absLoc.Translation = new TxVector(absLoc.Translation.X + 100, absLoc.Translation.Y, absLoc.Translation.Z);
                            viaLocation.AbsoluteLocation = absLoc;
                        }
                    }

                    //2. Add weld location operation if possible
                    ITxWeldLocationOperationCreation operationWithWeldChildren = opCopy as ITxWeldLocationOperationCreation;
                    if (operationWithWeldChildren != null)
                    {
                        TxWeldLocationOperationCreationData creationData = new TxWeldLocationOperationCreationData("weld1");
                        creationData.WeldPointCreationData = TxMfgCreationDataFactory.CreateWeldPointCreationData("weldPoint1", new TxVector(0, 0, 0));
                        if (operationWithWeldChildren.CanCreateWeldLocationOperation(creationData))
                        {
                            TxWeldLocationOperation weldLocOp = operationWithWeldChildren.CreateWeldLocationOperation(creationData);
                            //Then you can project and manipulate the new weld location operation
                        }
                    }

                    //3. Access the children of the operation copy
                    ITxObjectCollection opCollection = opCopy as ITxObjectCollection;
                    if (opCollection != null)
                    {
                        //get all child operations
                        TxObjectList childOperations = opCollection.GetAllDescendants(new TxNoTypeFilter());


                        //get child operation by index
                        ITxOrderedObjectCollection orderedCollection = opCollection as ITxOrderedObjectCollection;
                        int numOfChildren = orderedCollection.Count;

                        if (numOfChildren > 0)
                        {
                            ITxOperation opChild = orderedCollection.GetChildAt(numOfChildren - 1) as ITxOperation;
                        }
                    }
                }
            }
        }
    }
}

 

2 REPLIES 2

Re: Copy & manipulate operation

Experimenter
Experimenter

HI,

 

i want to Manipulate Location´s.

for that Case I using your example. To Modify my Location i used Option Three.

But in my Case the Location will not be override, ist there some Permissions i have to set?

 

My code Snipped:

//3.Access the children of the operation copy
ITxObjectCollection opCollection = opCopy as ITxObjectCollection;
if (opCollection != null)
{
//get all child operations
TxObjectList childOperations = opCollection.GetAllDescendants(new TxNoTypeFilter());

//get child operation by index
ITxOrderedObjectCollection orderedCollection = opCollection as ITxOrderedObjectCollection;
int numOfChildren = orderedCollection.Count;

for (int i = 0; i < numOfChildren; i++)
{
if (numOfChildren > 0)
{
TxRoboticViaLocationOperation opChild = orderedCollection.GetChildAt(numOfChildren - 1) as TxRoboticViaLocationOperation;

//opChild.AbsoluteLocation.Translation = this.ListClc[i].AbsLocation;
//TxTransformation Transform = opChild.AbsoluteLocation as TxTransformation;
//Transform.Translation = this.ListClc[i].AbsLocation;
//opChild.AbsoluteLocation.Set(Transform);
opChild.AbsoluteLocation.Translation.X = this.ListClc[i].AbsLocation.X;
opChild.AbsoluteLocation.Translation.Y = this.ListClc[i].AbsLocation.Y;
opChild.AbsoluteLocation.Translation.Z = this.ListClc[i].AbsLocation.Z;

}
}
}
}

Re: Copy & manipulate operation

Pioneer
Pioneer

Hy,

 

even though you want to change only translation and not rotation, you need to rewrite absolute location as whole. You can retain old rotation thats not the problem. 

 

So the code would need to be something like this:

 

//

TxRoboticViaLocationOperation opChild = orderedCollection.GetChildAt(numOfChildren - 1) as TxRoboticViaLocationOperation;

TxTransformation absLoc = opChild.AbsoluteLocation;

absLoc.Translation.X = this.ListClc[i].AbsLocation.X;
absLoc.Translation.Y = this.ListClc[i].AbsLocation.Y;
absLoc.Translation.Z = this.ListClc[i].AbsLocation.Z;

opChild.AbsoluteLocation = absLoc;

//

 

So alway change AbsoluteLocation and not only Translation.