Show attached detail group in Revit 2022

Hey,

Is it possible to Show the attached detail group of a Model group using dynamo?

I spend the past few hours on google to try and find something.
The only thing i found was that it was enabled in the API in Revit 2019.
I just don’t know how I can make it work…

Thanks!

Edit: By ‘Show the attached detail group of a Model group’ i mean show/place the detail group in a view.

This will return the available detail group types for a given model group instance:

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

myGroup = UnwrapElement(IN[0])
dGroups = myGroup.GetAvailableAttachedDetailGroupTypeIds()

outGroups = []

for i in dGroups:
	grp = doc.GetElement(i)
	outGroups.append(grp)

# Preparing output to Dynamo
OUT = outGroups

It primarily uses this method to get the Id’s of the group which can then be converted to their respective element using the GetElement() method.

Thanks for the reply!,
I did not specify what i wanted to do enough.

What i mean by ‘Show the attached detail group of a model group’ is how to show/place the detail group in a view.

This is the method for that step:

I have modified your script a bit to see if i could get it to work.
The only thing that seems to be the problem now is the message below.
I didn’t even know there was a difference between a FloorPlanView and a View.

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

myGroup = UnwrapElement(IN[0])
view = (IN[1])
dGroups = myGroup.GetAvailableAttachedDetailGroupTypeIds()
plaatsen = myGroup.ShowAttachedDetailGroups(view, dGroups)

outGroups = []

for i in plaatsen:
	grp = doc.GetElement(i)
	outGroups.append(grp)

# Preparing output to Dynamo
OUT = outGroups

@MelleH
This one works for me:

import clr #.NET Laden
import sys #sys is de fundamentele Python bibliotheek
#de standaard IronPython-bibliotheken
#sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib') #Imports the
#standaard IronPython-bibliotheken, die alles dekken, van servers en
#encryptie tot reguliere expressies.
import System #The System namespace in de hoofdmap .NET
from System import Array #.NET class voor het verwerken van array-informatie
import System.Collections.Generic as MGen #Module kan nu benaderd worden met MGen.xxxx
#from System.Collections.Generic import * #Hiermee kunt u generieke afhandelen. Revit's API
#soms wil hard-getypte 'generieke' lijsten, genaamd ILists. Als je niet nodig hebt
#deze kunt u deze regel verwijderen.
clr.AddReference('ProtoGeometry')  #Een Dynamo-bibliotheek voor zijn proxygeometrie
#classes. Je hebt dit alleen nodig als je interactie hebt met geometrie.
import Autodesk.DesignScript.Geometry as AGeo #Module kan worden opgeroepen a=met AGeo.xxxx
#from Autodesk.DesignScript.Geometry import * #Laadt alles in Dynamo's
#geometriebibliotheek
clr.AddReference("RevitNodes") #Dynamo's nodes voor Revit
import Revit #Laad in de Revit-namespaces in RevitNodes
clr.ImportExtensions(Revit.Elements) #Meer laden van Dynamo's Revit-bibliotheken
clr.ImportExtensions(Revit.GeometryConversion) #Meer laden van Dynamo's
#Revit-bibliotheken. Je hebt dit alleen nodig als je interactie hebt met geometrie.
clr.AddReference("RevitServices") #Dynamo's classes voor het omgaan met Revit-documenten
import RevitServices 
from RevitServices.Persistence import DocumentManager #Een interne Dynamo class
#dat het document bijhoudt waaraan Dynamo momenteel is gekoppeld
from RevitServices.Transactions import TransactionManager #Een Dynamo class voor
#transacties openen en sluiten om de database van het Revit-document te wijzigen

clr.AddReference("RevitAPI") #Verwijzing naar Revit's API DLL's toevoegen
clr.AddReference("RevitAPIUI") #Verwijzing naar Revit's APIUI DLL's toevoegen

import Autodesk #Loads the Autodesk namespace
import Autodesk.Revit.DB as RDB #Loading Revit's API UI classes module kan nu worden aangeroepen met RDB.xxxx
#from Autodesk.Revit.DB import * #Loading Revit's API UI classes
import Autodesk.Revit.UI as RUI # Loading Revit's API UI classes als RUI.xxxx
#from Autodesk.Revit.UI import * #Loading Revit's API UI classes

doc = DocumentManager.Instance.CurrentDBDocument #Dit is het actieve Revit document
uiapp = DocumentManager.Instance.CurrentUIApplication #Een handle instellen voor het actieve Revit UI-document
app = uiapp.Application  #Een handle instellen op de momenteel geopende instantie van de Revit-toepassing
uidoc = uiapp.ActiveUIDocument #Een handle instellen op de momenteel geopende instantie van de Revit UI-toepassing
revit_version = int(doc.Application.VersionNumber)
# code omrekenen revit feet naar huidig ingestele document units
if revit_version >= 2022:
    ForgeLength = "autodesk.spec.aec:length-1.0.0"  # zie voor lijst ForgeTypeIds.xlsx in de map handleidingen
    ForgeTypeLength = RDB.ForgeTypeId(ForgeLength)
    getDocUnits = doc.GetUnits()
    getDisplayUnitsLength = getDocUnits.GetFormatOptions(ForgeTypeLength).GetUnitTypeId()
else:
    getDocUnits = doc.GetUnits()
    getDisplayUnits = getDocUnits.GetFormatOptions(RDB.UnitType.UT_Length).DisplayUnits


def ToRevitUnitsLength(InVal):
    if revit_version >= 2022:
        return RDB.UnitUtils.ConvertToInternalUnits(InVal, getDisplayUnitsLength)
    else:
        return RDB.UnitUtils.ConvertToInternalUnits(InVal, getDisplayUnits)


def ToDynamoUnitsLength(InVal):
    if revit_version >= 2022:
        return RDB.UnitUtils.ConvertFromInternalUnits(InVal, getDisplayUnitsLength)
    else:
        return RDB.UnitUtils.ConvertFromInternalUnits(InVal, getDisplayUnits)

def ToRevitUnitsLengthFromMM(InVal):
	if revit_version >= 2022:
		return RDB.UnitUtils.Convert(InVal, RDB.UnitTypeId.Millimeters, RDB.UnitTypeId.Feet)
	else:
		return RDB.UnitUtils.Convert(InVal, RDB.DisplayUnitType.DUT_MILLIMETERS, RDB.DisplayUnitType.DUT_DECIMAL_FEET)
	
def ToRevitUnitsLengthFromMM(InVal):
	if revit_version >= 2022:
		return RDB.UnitUtils.Convert(InVal, RDB.UnitTypeId.Millimeters, RDB.UnitTypeId.Feet)
	else:
		return RDB.UnitUtils.Convert(InVal, RDB.DisplayUnitType.DUT_MILLIMETERS, RDB.DisplayUnitType.DUT_DECIMAL_FEET)
	
def GroupByKey(Items,Keys):
	UKeys=[]
	for Key in Keys:
		if Key not in UKeys:
			UKeys.append(Key)
	GrpList=[]
	for empt in range(len(UKeys)):
		GrpList.append([])
	Inds=[]
	for Key in Keys:
		Inds.append(UKeys.index(Key))
	for Item, Ind in zip(Items, Inds):
		GrpList[Ind].append(Item)
	return [GrpList,UKeys]

def GetName(ele):
	elename = None
 	try:
 		elename = ele.Name
 	except:
 		elename = RDB.Element.Name.__get__(ele)
 	return elename 

# einde code omrekenen revit feet naar huidig ingestelde document units
# Hieronder kan je dan gaan programmeren
# Gebruik boiler template

#Start Transaction
#TransactionManager.Instance.EnsureInTransaction(doc)
#Eind Transactie
#TransactionManager.Instance.TransactionTaskDone()

adetailgroup = UnwrapElement(IN[0])
views = UnwrapElement(IN[1])
groups = UnwrapElement(IN[2])

ids = []
for a in adetailgroup:
	ids.append(a.Id)
#Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)	

s=0
for g in groups:
	RDB.Group.ShowAttachedDetailGroups(g, views ,ids[s])
	s += 1	

#Eind Transactie
TransactionManager.Instance.TransactionTaskDone()

OUT = views

Attached detail group.dyn (23.8 KB)

Make sure that the view isn’t a viewtemplate

@GavinCrump

Hello,

We keep getting the following error (Revit 2023):

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line 25, in <module>
Exception: The attached detail group detailGroupTypeId does not match the input view's orientation.
Parameter name: detailGroupTypeId

The Revit API gives the following remark:

Currently, perpendicular elevation views (for example, North and East views) are considered compatible when deciding whether or not to allow a detail group to be displayed in a view. The show operation may generate an error (FailureMessage) based on id if the orientation of the annotations do not match the orientation of the target view (for example, the failure definition DimensionPerpendicularToView). To prevent displaying detail groups in the wrong view, you can check the OwnerViewId of a detail group to make sure it matches the view in which you are trying to display it.

What are we doing wrong? I tried getting the OwnerViewId although those give back -1 (since there is no view). We are working with Floorplans.

Hope you can help!

Found solution here: