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: 

Revit 2014 API to open revit family file

2 REPLIES 2
Reply
Message 1 of 3
Dorathijf
1301 Views, 2 Replies

Revit 2014 API to open revit family file

Hi,

I have current revit project opened in Revit User Interface.(i am using Revit 2014)

 

I am opening a website through Revit add-in Ribbon and download the revit files.

now i want that the downloaded revit file should be opened as soon as i finish downloading through the windows form.

i tried OpenAndActivate but can't declare "commandData", as my (download revit) code is in different file. Is there any way i can open the downloaded revit file in current project.

2 REPLIES 2
Message 2 of 3
raunoveb
in reply to: Dorathijf

If you want to download file(s) then you could encapsulate the code that deals with downloading in a different method in a static class (e.g. FamilyDownloader).

Let's say your command (that activates on button click) looks like this:

 

public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
    UIApplication application = revit.Application;
    Document document = application.ActiveUIDocument.Document;
//After downloading these files you should add path to each Family file into a List or other type of collection you can later loop through List<string> fileList = FamilyDownloader.download();
foreach(string path in fileList){
document.LoadFamily(path);
} return Result.Succeeded; }

 In this example .download() method returns a list of paths where Family files were downloaded to. Be sure to correct me or add some other information if it seems that I misunderstood your problem.

Message 3 of 3
Dorathijf
in reply to: raunoveb

thank you for the code. i have used the similar code and it downloads the revit files and loads the family.

but i want to open the loaded family symbol in currently opened project. i am using 

PromptForFamilyInstancePlacement but its not allowing me to add the family symbol. my code is somewhat like this:

public void DL(String url)

{

loadFamily(fs[0].FullName);

}

 

this will download revit file and stroe in folder then i use loadfamily method to place family symbol in opened project.

 

  public void loadFamily(String f)

        {

            String fname = Path.GetFileNameWithoutExtension(f);

 

            Family family =  null;

            FamilySymbol familyFound = null;

            Transaction t = new Transaction(s_document, "Test");

            t.Start();

            s_document.LoadFamily(f, out family);

            FilteredElementCollector familyCollector = new FilteredElementCollector(s_document);

            familyCollector.OfClass(typeof(FamilySymbol));

 

            foreach (FamilySymbol sym in familyCollector)

            {

                if (sym.Family.Name == fname)

                {

                    familyFound = sym;

                }

            }

            t.Commit();

 

            UIDocument uidoc = new UIDocument(s_document);

            uidoc.PromptForFamilyInstancePlacement(familyFound);

         }

 

any suggestions please. Thank you.

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