So in my opinion the only difference in my code will be a replacement of the @"D:\testfamilie.rfa" with an url from a
website? or is that to easy.
Second question in this existing code, we using it with a pushbutton. When you load again you get an error. But is there a way to add it again without an error? So for example in Revit, when you press the Component button it's also loads again a component that is already been loaded without the error?
Thanks en hopefully someone can help with both questions 🙂
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Structure;
namespace Loadf
{
[Transaction(TransactionMode.Manual)]
public class Loadfamily : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
String fileName = @"D:\testfamilie.rfa";
using (Transaction t = new Transaction(doc, "family"))
try
{
t.Start("param");
//try to load family
Family family = null;
if (!doc.LoadFamily(fileName, out family))
{
throw new Exception("Unable to load " + fileName);
}
//loop trough door symbols and add a new table
ISet<ElementId> familySymbolIds = family.GetFamilySymbolIds();
double x = 0.0, y = 0.0;
foreach (ElementId id in familySymbolIds)
{
FamilySymbol symbol = family.Document.GetElement(id) as FamilySymbol;
XYZ location = new XYZ(x, y, 0);
if (!symbol.IsActive)
{ symbol.Activate(); doc.Regenerate(); }
FamilyInstance instance = doc.Create.NewFamilyInstance(location, symbol, StructuralType.NonStructural);
}
t.Commit();
return Result.Succeeded;
}
catch (Exception ex)
{
// If something went wrong return Result.Failed
message = ex.Message;
return Result.Failed;
}
}
}
}