Making Better Flex with API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
This is a pretty basic matter probably, but I wanted some outside perspective on making this work better. I've currently got an add-in that inserts a bunch of duct and duct fittings. My flex always seems to come out a little wonky. It seems to work, but it needs serious improvment. I was wondering if someone can help me understand what I'm doing wrong/missing with these.
Below is a snapshot of the resulting flex and code. It's pretty basic. I just get the points I need for the flex connections and then build out my FlexDuct object. Once I've done that, I will look at the drawing and see if there is any connectors that reside on the flex connector locations, if not, I will make a temporary connector. However, the issue I have is even when my flex finds a currently existing connector and connects to it, it comes in at weird angles.
Thanks!
public static void InsertFlex(Document doc)
{
//Get Level for Flex.
FilteredElementCollector floorColl = new FilteredElementCollector(doc);
floorColl.OfClass(typeof(Level));
ElementId lvl = floorColl.FirstElementId();
//Get the Flex Type
FilteredElementCollector flexType = new FilteredElementCollector(doc);
collector.OfClass(typeof(FlexDuctType));
ElementId flexType = null;
foreach (Element e in collector)
{
if (e.Name == "Flex - Round")
{
flexType = e.Id;
}
}
//Get System
FilteredElementCollector sysColl =
new FilteredElementCollector(doc);
sysColl.OfClass(typeof(MechanicalSystemType));
ElementId sysId = sysColl.FirstElementId();
XYZ point1 = flexConn1Location // This will just be the location of FlexConn1, usually off of a tap.
XYZ point2 = flexConn2Location // This will be the location for FlexConn2, usually to a grille/diffuser.
List<XYZ> pnts = new List<XYZ>();
pnts.Add(point1);
pnts.Add(point2);
FlexDuct flex = FlexDuct.Create(doc, sysId, flexType, lvl, pnts);
Connector conn1 = GetConnectorAtPoint(point1); // This is a routine that will get a connector at flex loc 1.
If (conn1 == null)
{conn1 = CreateTemporaryConnector();} // If we don't have a connector, I just create a temporary object that the flex can connect to)
Connector conn2 = GetConnectorAtPoint(point2);
If (conn2 == null)
{conn2 = CreateTemporaryConnector()};
//Connect the Flex to it's object.
if ((conn1 != null) && (conn2 != null))
{
foreach (Connector c in flex.ConnectorManager.Connectors)
{
if (c.Origin.IsAlmostEqualTo(conn1.Origin))
{
c.ConnectTo(conn1);
}
else if (c.Origin.IsAlmostEqualTo(conn2.Origin))
{
c.ConnectTo(conn2);
}
}
}
doc.Regenerate();
//Delete the temporary objects if needed.
}