Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

is this code safe?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
phildebrandt
582 Views, 1 Reply

is this code safe?

if(selection.Elements.Size == 1)
                {
                    System.Collections.IEnumerator es = selection.Elements.GetEnumerator();
                    es.MoveNext();
                    Type t = es.Current.GetType();
                    
                    switch (t.FullName)
                    {
                        case "Autodesk.Revit.DB.ImportInstance":
                            TaskDialog.Show("test", "Revit file selected.");
                            break;
                        case "Autodesk.Revit.DB.Instance":
                            TaskDialog.Show("test", "Revit file selected.");
                            break;
                        case "Autodesk.Revit.DB.FamilyInstance":
                            TaskDialog.Show("test", "Revit family selected.");
                            break;
                        default:
                            TaskDialog.Show("test", "Default switch case.");
                            break;
                    }
                }

I'm just wondering how safe the code above is to use? Namely, if this is used in a foreign country do the class names change?

1 REPLY 1
Message 2 of 2
ollikat
in reply to: phildebrandt

I don't know about the safety but wouldn't it also work like this (C++):

 

"if (t == ImportInstance::typeId)"

  TaskDialog.Show("test", "Revit file selected.");

 

(I'm not sure about C#...typeof(ImportInstance) might be the same thing...?)

 

Think that this might be more robust way of doing that.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community