Optimize IndependentTag.Create (generating graphics)

Optimize IndependentTag.Create (generating graphics)

ilya.sector.1
Participant Participant
383 Views
3 Replies
Message 1 of 4

Optimize IndependentTag.Create (generating graphics)

ilya.sector.1
Participant
Participant

Hello everybody!


Description:
There are n elements. Each tag must be tagged with (IndependentTag.Create).
Everything happens in a cycle.
Problem:
Graphs are generated after each iteration. This significantly slows down the plugin.
Question:
How to optimize IndependentTag.Create so that it updates the graphics AFTER all iterations, and
not every time?
Is there a way in the API to place tags SIMULTANEOUSLY ( luikeIndependentTag.Create )

 

Best regards!

0 Likes
384 Views
3 Replies
Replies (3)
Message 2 of 4

sam.najjarJVR3P
Participant
Participant

Can you post the code you're trying to optimize?

 

0 Likes
Message 3 of 4

ilya.sector.1
Participant
Participant

If activate view is not another view (where we create tag) => generating graphics every time after IndependentTag.Create.
Can i open another view (and more) in my doc and create tags?  The transaction must be one and without commit \ start

Example:

var
doors = new FilteredElementCollector(Document).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Doors).ToList();
var symbol = new FilteredElementCollector(Document).WhereElementIsElementType().OfCategory(BuiltInCategory.OST_DoorTags).ToList();
var targetPlan = new FilteredElementCollector(Document).OfClass(typeof(ViewPlan)).FirstOrDefault(p => p.Name == "ANOTHER NOT ACTIVATE VIEW");

using (Transaction transaction = new Transaction(Document, "Create tags"))
{
transaction.Start("Start");
foreach (var door in doors)
{
if (door.Location == null) continue;
var point1 = ((LocationPoint) door.Location).Point;
var point2 = ((LocationPoint) door.Location).Point + new XYZ(0,1,0);

var tag1 = IndependentTag.Create(Document, symbol[0].Id, targetPlan.Id,
new Reference(door), false, TagOrientation.Horizontal, point1);
var tag2 = IndependentTag.Create(Document, symbol[0].Id, targetPlan.Id,
new Reference(door), false, TagOrientation.Horizontal, point2);
}

transaction.Commit();
}

 

0 Likes
Message 4 of 4

samernajjar
Contributor
Contributor

I don't think the issue in regenerating the graphics after each tag placement, as this AFAIK should happen after the transaction is committed.
The delay might be happening because you're collecting all the doors in the model and the code is trying to annotate an element that is not visible in the target view. Try restricting the door collection to only the doors visible in the target view using this FilteredElementCollector overload:

 

 

var symbol = new FilteredElementCollector(Document).WhereElementIsElementType().OfCategory(BuiltInCategory.OST_DoorTags).ToList();

//first collect the target view
var targetPlan = new FilteredElementCollector(Document).OfClass(typeof(ViewPlan)).FirstOrDefault(p => p.Name == "ANOTHER NOT ACTIVATE VIEW");

//then restrict the door collection to only get the doors that are visible in the target view
var doors = new FilteredElementCollector(Document, targetPlan.Id).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Doors).ToList();

// the rest of your code....

 

 



0 Likes