cancel
Showing results for 
Search instead for 
Did you mean: 

Copy & manipulate operation

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

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;
                        }
                    }
                }
            }
        }
    }
}