Cancel
Showing results for 
Search instead for 
Did you mean: 

How to get latest created operation for the use of next activity

Pioneer
Pioneer

Hi,

I created a compound operation and 2 weld operation under it through clicking of one button. Then after through another button both weld operation are  linked by material flow link. 

I need to add compound operation and 2 weld operation many times. but everytime i click another button for material flow link, it get all previously created weld operations also.

How to get latest created weld opeartions? What logic should i applied to get only latest created operation?

 

Thanx

 

5 REPLIES

Re: How to get latest created operation for the use of next activity

Pioneer
Pioneer
private void Button1_Click(object sender, EventArgs e)
{
    TxCompoundOperation compoundoperation = TxApplication.ActiveDocument.OperationRoot.CreateCompoundOperation(new TxCompoundOperationCreationData("First")));
    button2.Click += (SS, EE) =>
    {
        TxNonSimOperation Extranonsim = compoundoperation.CreateNonSimOperation(new TxNonSimOperationCreationData("Nonsimextra"));
    };
};

Here, in above code, Button1 creates compoundoperation and then button2 add new nonsim operation to compound operation.

Problem is , suppose first time i click on button1 and button2, everything works correct, when i second time click button1, it creates new compoundoperation , and then when i click button2 for second time, it creates one nonsim operation in first compound operation and one nonsim operation in second compound operation. But i want to add nonsim only in secondly created compound operation.

How to do it?

Re: How to get latest created operation for the use of next activity

Phenom
Phenom

@ChristyBell

 

I don't understand why you're registering the button2.Click event in the Click event of button1. Is there any reason for that? Maybe that's giving you bad resuts.

 

Regards

Re: How to get latest created operation for the use of next activity

Pioneer
Pioneer

Hello @FredCastro,

 

Thnx for Hint.

I tried outside from button1, u can see an example, But exception throws like "Object referance not set to an instance of Object". Can you check from where error arise?

   public partial class TxPForm : TxForm
    {        
        public TxPForm()
        {
            InitializeComponent();
        }

        TxCompoundOperation compoundop;
        public TxCompoundOperation _compoundop
        {
            get { return compoundop;}
            set { compoundop = value; }
        }
        
        private void CreateOp_Button_Click(object sender, EventArgs e)
        {
           
             TxPForm m = new  TxPForm();
           TxCompoundOperation compoundop= TxApplication.ActiveDocument.OperationRoot.CreateCompoundOperation(new TxCompoundOperationCreationData("MP"));
                m._compoundop = compoundop;
                TxNonSimOperation generateappearance = compoundop.CreateNonSimOperation(new TxNonSimOperationCreationData("first"));

        private void CreateSignal_Button_Click(object sender, EventArgs e)
        {
             TxPForm f = new  TxPForm();
            if (f._compoundop.Count > 0)
            {
                TxObjectList list = f._compoundop.GetAllDescendants(new TxTypeFilter(typeof(TxNonSimOperation)));
                //TxObjectList list = compoundoperation.GetAllDescendants(new TxTypeFilter(typeof(TxNonSimOperation)));
                if (list.Count > 0)
                    foreach (ITxObject operation in list)
                    {
                        TxNonSimOperation ope = operation as TxNonSimOperation;
                        
                        TxPlcDisplaySignal startsig = TxApplication.ActiveDocument.PlcProgramRoot.CurrentPlcProgram.CreatePlcDisplaySignal(new TxPlcDisplaySignalCreationData(operation.Name + "_Start"));
                        ope.StartingSignal = startsig;
                        }
                    }

                }
            }
        

 

Hier In Above code, Without setting a property of Compoundoperation, I could not access created compoun opeartion into another butoon click event. Thats y earlier i wrote click event method into another click event method. 

And also In seperate method i have to create instance of class also seperately.

Re: How to get latest created operation for the use of next activity

Phenom
Phenom

@ChristyBell

 

You don't need to create new instance of your form inside of itself, in your case "f" is probably not getting the compound from "m". Use "this" keyword to set the compoundop variable and be able to use values between your click events

Re: How to get latest created operation for the use of next activity

Pioneer
Pioneer

Hi, @FredCastro,

Super Thanx....It was very small thing i couldnt find..

Thanx a lot