Announcements

We are currently experiencing an issue impacting some Autodesk Products and Services - please refer to the Autodesk Health Dashboard for updates.

A software problem has caused Revit 2020.2.5 to close unexpectedly while run api script

A software problem has caused Revit 2020.2.5 to close unexpectedly while run api script

mr.engineer.aec
Advocate Advocate
764 Views
2 Replies
Message 1 of 3

A software problem has caused Revit 2020.2.5 to close unexpectedly while run api script

mr.engineer.aec
Advocate
Advocate

 Hello,

 While i run script to set value for walls (about ~300wall),

 I have this problem and Revit close automatic.

 Sometimes, it work correct if i run only ~50 walls.

 I can't get Exception in try-catch.

 What should i do ?

 Thank in advanced !

foreach (Wall wall in runWalls)
                {
                    if (transG.HasStarted())
                    {
                      
                        try
                        {
                             //other codes run well 

                            using (Transaction tran = new Transaction(doc, "Set Offset"))
                                {
                                    tran.Start();
                                    FailureHandlingOptions option = tran.GetFailureHandlingOptions();
                                    option.SetFailuresPreprocessor(new DeleteWarningSuper());
                                    tran.SetFailureHandlingOptions(option);
                                    wall.LookupParameter("Top Constraint").Set(ElementId.InvalidElementId);
                                    wall.LookupParameter("Unconnected Height").Set(h);
                                    //doc.Regenerate();
                                    tran.Commit();
                                }
                            
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show(exception.ToString());
                            break;
                        }
                        
                    }
                    else
                    {
                        break;
                    }
                    
                }

 

mrengineeraec_0-1631785012393.png

 

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

jeremy_tammik
Alumni
Alumni
Accepted solution

Yes. 

 

As you may be aware, Revit is designed with an end user interface for end user interaction.

 

The Revit API enables automation of some UI tasks, but does not change the underlying fact.

 

As you might imagine, an end user would normally not modify 300 walls in one single editing command, using 300 separate transactions.

  

I would suggest trying out a few things.

  

First of all, I would suggest trying to wrap all of the modifications into one single transaction. That ought to improve performance as well.

   

I would also suggest avoiding the use of the LookupParameter method for professional programming, since that may well pick up the wrong parameter. There are more reliable ways to identify and retrieve a parameter that do not rely on its display name. Using a built-in parameter enumeration value is faster and much more reliable.

 

On the other hand, it should not be possible to crash Revit so easily and quickly. Can you please provide a complete minimal reproducible case that demonstrates this crash for me to share with the development team for further analysis?

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

A sample model with 300 walls and an embedded macro would be perfect. Thank you!

 

I hope this helps.

   

Best regards,

 

Jeremy

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 3

mr.engineer.aec
Advocate
Advocate

 Hi Mr.Jeremy,

 A transaction for all walls solved this issue.

 Many thanks.

 I use both lookup parameter and get_Parameter(BuiltinP). 

 Thank you for noticing!

0 Likes