
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm using the DesignAutomation Framework to try and build API walls, doors, ceilings, floors, pipes, ducts. I need them in different variations and I need to be able to randomize their lengths, orientations and connections. I have been stuck within this connection space for two weeks and am so frustrated. I cannot find out why this doesn't work. The only error message I get is "failed to insert *whatever connection I call*" and that's it. No indication of why or how to fix it. There is no UI in this code, it's all API and DB functionality. I really would appreciate if someone could help me understand what I am doing wrong. In the example that I've provided, I simply try to make two ducts and connect them. I've read and tried what feels like a million different implementations from the forum as well as from BuildingCoder... nothing is working. There is always some kind of road block. What I really need is for someone to give me a clear code example of what I need to make this work just one darn time.
private static Duct CreateDuct(Document newDoc, XYZ p1, XYZ p2, double diameter)
{
FilteredElementCollector collector = new FilteredElementCollector(newDoc);
collector.OfClass(typeof(Level));
var elem = from element in collector where element.Name == "Floor" select element;
Level level = elem.Cast<Level>().ElementAt<Level>(0);
FilteredElementCollector elCollector = new FilteredElementCollector(newDoc).OfClass(typeof(DuctType)).WhereElementIsElementType();
DuctType DT = elCollector.First() as DuctType;
MEPSystemType mepSystemType = new FilteredElementCollector(newDoc)
.OfClass(typeof(MEPSystemType))
.Cast<MEPSystemType>()
.FirstOrDefault(sysType => sysType.SystemClassification == MEPSystemClassification.SupplyAir);
using (Transaction dTrans = new Transaction(newDoc, "Make Duct"))
{
dTrans.Start();
Duct duct = Duct.Create(newDoc, mepSystemType.Id, DT.Id, level.Id, p1, p2);
duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).Set(diameter);
dTrans.Commit();
return duct;
}
}
public static void ConnectTwoDucts(Document doc)
{
//create duct one
XYZ pt1 = new XYZ(0, 0, 0);
XYZ pt2 = new XYZ(0, 10, 0);
Duct duct1 = CreateDuct(doc, pt1, pt2, 5);
//create duct two
XYZ pt3 = new XYZ(0, 15, 0);
XYZ pt4 = new XYZ(0, 25, 0);
Duct duct2 = CreateDuct(doc, pt3, pt4, 2);
Connector duct1end = null;
Connector duct2start = null;
using (Transaction dConTrans = new Transaction(doc, "Connect Ducts"))
{
dConTrans.Start();
//Load Family
Family family = null;
string path = @"C:\ProgramData\Autodesk\RVT 2020\Libraries\US Imperial\Duct\Fittings\Rectangular\Transitions";
foreach (string dirFile in Directory.GetDirectories(path))
{
foreach (string filename in Directory.GetFiles(dirFile))
{
doc.LoadFamily(filename, out family);
}
}
foreach (Connector connect1 in duct1.ConnectorManager.Connectors)
{
if (connect1.Origin.IsAlmostEqualTo(pt2))
{
duct1end = connect1;
break;
}
}
foreach (Connector connect2 in duct2.ConnectorManager.Connectors)
{
if (connect2.Origin.IsAlmostEqualTo(pt3))
{
duct2start = connect2;
break;
}
}
doc.Create.NewTransitionFitting(duct1end, duct2start);
dConTrans.Commit();
}
}
Solved! Go to Solution.