How to add large number of objects in the tree without refreshing the tree each time using ACT autom

Member, Moderator, Employee Posts: 873
100 Answers 500 Comments 250 Likes Second Anniversary
✭✭✭✭
edited June 2023 in Structures

How to add large number of objects in the tree without refreshing the tree each time using ACT automation APIs in Mechanical?

Tagged:

Best Answer

  • Member, Moderator, Employee Posts: 873
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭
    Answer ✓

    If one tries to add a lot of objects in the tree in Mechanical, using automation APIs, it refreshes tree each time an object is added. This can lead to large delays in the process.

    So one can suspend the tree first and then add the objects, for example:

    1. with(ExtAPI.DataModel.Tree.Suspend()):
    2. for i in range(100):
    3. ExtAPI.DataModel.Project.Model.AddComment()

    This will be significantly faster as compared to simply adding 100 objects in the tree.

Answers

  • Member, Moderator, Employee Posts: 242
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    The below option would also help in speed up of adding lots of objects.

    1. with Transaction(suspendClicks=True):
    2. for i in range(100):
    3. ExtAPI.DataModel.Project.Model.AddComment()

Welcome!

It looks like you're new here. Sign in or register to get started.