An Issue while Using with Transaction()

I am currently experiencing an issue with my script, which is divided into three main parts. The first part uses Auto_Detection to create the initial Connection Group and performs specific operations based on keywords. The second part sorts and classifies the created Contact Regions. The third part performs a new Auto_Detection based on the classified data to generate different Connection Groups.
The problem occurs when I wrap all parts of the script within with Transaction(suspendClicks=True).
Some operations fail, such as the following code in the first part:
if any(key in contact_bodies_2 and key in target_bodies_2 for key in keywords):
cont_region_2.Delete()
This line works properly when I don't use with Transaction, but the execution speed becomes significantly slower. Could you please provide assistance with this issue?
My scripts are shown below,
Part1:
Part2:
Part3:
Answers
-
It maybe that the state of the connection(s) is not being updated before it is acted upon for a second time. I would try using 2 or 3 seperate 'with Transaction' blocks
0 -
I followed the suggestion and separated the script into multiple with Transaction blocks as below, but it still didn’t solve the problem. The content that needs to be deleted in the original connection group is still not being removed. Could you please provide further assistance?
Part1:
Part2:
Part3:
Result:
0 -
@kkman I would recommend not to include addition and removal of Connection Folder in Transaction ( or any API which does this).
A sample script/model can be helpful for a quick check.
0 -
Dear Rajesh Meena, thanks for your kind response. I've uploaded both the model and script as attached. Please check it with/without Transaction(); you will get quite different results."> @Rajesh Meena said:
@kkman I would recommend not to include addition and removal of Connection Folder in Transaction ( or any API which does this).
A sample script/model can be helpful for a quick check.
0 -
@kkman Please try below script once:
I have done two major changes.
- Activated Connection Object before entering into transaction, otherwise renamebased on definition may not work just after opening mechanical project.
- Stored objects to delete in a list and then deleted all of them using ExtAPI.DataModel.Remove
Hope it helps!
1 -
Thanks a lot, @Rajesh Meena. It seems I should use a list to store all the objects that need to be deleted, especially within the "with Transaction()" block; otherwise, the result does not behave as expected.
Is there any documentation or link you can share about how to properly develop scripts using the "with Transaction()" block?
Additionally, I followed your suggestion in more complex model, but I am still getting incorrect results compared to running the script without the "with Transaction()" block.
I have attached the download link for the script and model below for your reference:
https://drive.google.com/drive/folders/1n2EybT25VokC6mMfAep6L2C6118cxYRi?usp=sharing> @Rajesh Meena said:@kkman Please try below script once:
I have done two major changes.
- Activated Connection Object before entering into transaction, otherwise renamebased on definition may not work just after opening mechanical project.
- Stored objects to delete in a list and then deleted all of them using ExtAPI.DataModel.Remove
Hope it helps!
0