Generating Elements Dynamically

Generating Elements Dynamically

Anonymous
Not applicable
831 Views
2 Replies
Message 1 of 3

Generating Elements Dynamically

Anonymous
Not applicable

Hi everyone,


I am trying to programmatically create grids with the attached code fragment. This code fragment is now working fine, but the matter here is that the grids are all generated at one time when the command is completed.

 

Is there any way to dynamically generate grids one by one while the iteration still moving?


This is possible if I show a Message Box on each transaction, but this way I need to manually close the Message Box for every transaction then.

 

Looking forward for a solution

 

My code

 

ElementCategoryFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Lines);
IList<Element> allLines = new FilteredElementCollector(doc).WherePasses(categoryFilter).WhereElementIsNotElementType().ToElements();
foreach (Element e in allLines)
{
    LocationCurve locationCurve = e.Location as LocationCurve;
    foreach (Parameter param in e.Parameters)
    {
        if (param.Definition.Name.Equals("Line Style") && param.AsValueString().Equals("Hz_Grid"))
        {
            using (Transaction tran = new Transaction(doc, "Tạo Lưới"))
            {
                Line line = Line.CreateBound(locationCurve.Curve.GetEndPoint(0), locationCurve.Curve.GetEndPoint(1));
                tran.Start();
                doc.Create.NewGrid(line);
                tran.Commit();                            
            }
        }
    }
}

Thank you

Nguyen Duy Hoa

0 Likes
Accepted solutions (1)
832 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Nguyen Duy Hoa,

 

So yu want to refresh the screen during the execution of the command.

 

This topic has been discussed a couple of times by The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2014/06/refresh-element-graphics-display.html

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

Anonymous
Not applicable

Dear Mr. Jeremy

 

A long awaited answer and yes exactly what I am looking for. It works as desired

 

It means the model elements are actually dynamically generated on each transaction but the view keeps pending during the execution

So, the remedy for this issue is just refreshing the active view during the execution

 

Thank you very much for a pertinent answer

 

Nguyen Duy Hoa

0 Likes