Revit2021.Dynamo

Good afternoon, everyone! Tell me, maybe someone knows the answer to this question. I need to place an instance of the duct connection parts family (a check mark based on the working plane is enabled) on the working plane of another element. I’m having trouble rotating the element along the Y and X axes, since all the rotation nodes work only with the Z axis, I’ll be grateful for your help!

Hi @margarettustinova and welcome

For a more detailed explanation, could you please post a screenshot and share a sample RVT file?

I have upgraded your user level.

1 Like

Welcome, but you still not actuely show the issue, the community wiil need more informations for help…yeah its tricky rotate valve, elbow,dampers in these vectors…but still not sure thats the issue…ps seems you are in an older version…and could give issue as well…so just share what you try and we can try help :wink:

Hello! Yes, of course, here’s a more detailed explanation!

The global problem is that

In Revit 2021, the Duct Fittings category has function Cap Open Ends, but it’s really important to me that this family be in the Generic Models category. However, this category doesn’t have this function, and I can’t select all the elements-we’re talking about 1,000 of them. Only each individual connector has a function to insert a cap. So, I wanted to write a Dynamo script that would position the caps in any plane and attach them to the main family. However, I also can’t use a workplane-based family, since in that case, the caps are attached incorrectly on some faces.

Yeah not sure then i have never change my categori duct fitting to generic, guess it will give some issue, soon or later so cant really recommend it…but guees we have a api for pipe endcap, but not for ducts, but its possible but a longer way,ps endcaps is controlled by duct/pipe series…but very rare i create endcaps on fittings as well

something here should work on ducts, could probably be something similar in your situation, not sure…but maybe @c.poupin have a good idea
Revit_z7IIhRj5HB

1 Like

Hi,
here is an example for duct fitting with rectangular shape

It needs to be adapted for other shapes.

PythonNet3 code

import clr
import sys
import System
from System import Array
from System.Collections.Generic import List, IList, Dictionary, HashSet
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB.Structure import *

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("System.Core")
clr.ImportExtensions(System.Linq)

fitting_type = UnwrapElement(IN[0])

# need to try BuiltInCategory.OST_DuctFitting
cat_list = [BuiltInCategory.OST_DuctFitting, BuiltInCategory.OST_GenericModel]
typed_list = List[BuiltInCategory](cat_list)
filtercat = ElementMulticategoryFilter(typed_list)
#
fittings_toCapOpenEnds = FilteredElementCollector(doc).OfClass(FamilyInstance).WherePasses(filtercat)\
            .Where(System.Func[DB.Element, System.Boolean](lambda e : e.GetTypeId() != fitting_type.Id ))\
            .Where(System.Func[DB.Element, System.Boolean](lambda e : e.MEPModel.ConnectorManager.UnusedConnectors.Size > 0 ))\
            .ToList()
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)


for fiting in fittings_toCapOpenEnds:
    level = doc.GetElement(fiting.LevelId)
    
    for connA in fiting.MEPModel.ConnectorManager.UnusedConnectors:
        c_systemA = connA.CoordinateSystem
        connA_vector = c_systemA.BasisZ
        #
        newfam = doc.Create.NewFamilyInstance(connA.Origin, fitting_type, level, StructuralType.NonStructural)
        connB = list(newfam.MEPModel.ConnectorManager.Connectors)[0]
        c_systemB = connB.CoordinateSystem
        connB_vector_reverse = c_systemB.BasisZ.Negate()
        factor = -1 if connA_vector.CrossProduct(connB_vector_reverse).Z > 0.01 else 1
        angle = connA_vector.AngleTo(connB_vector_reverse)
        axis = Line.CreateUnbound(connA.Origin, XYZ.BasisZ)
        DB.ElementTransformUtils.RotateElement(doc, newfam.Id, axis, factor * angle )
        # set dimension
        newfam.LookupParameter("a").Set(connA.Height)
        newfam.LookupParameter("b").Set(connA.Width)
        # connect to
        connB.ConnectTo(connA)

TransactionManager.Instance.TransactionTaskDone()

OUT = fittings_toCapOpenEnds
1 Like

great…awesome as usual :wink: cool, thanks

1 Like

and works great even if the fitting is generic model even i never had set my fitting categori to generic…but what the user want…so great :wink:

1 Like

Wow This so cool! Can you tell me please can it rotate around Y or X axis?
For example if we also have connector on this face?

No, I have not dealt with this specific case.

1 Like