Yes, if you have a Detail Group inside your document and copy that would work.
I was testing exactly that.
public static Group CreateGroupDetail(GroupType groupType, View view, XYZ location)
{
var document = groupType.Document;
Group groupBase = new FilteredElementCollector(document)
.WhereElementIsNotElementType()
.OfCategory(BuiltInCategory.OST_IOSDetailGroups)
.OfClass(typeof(Group))
.OfType<Group>()
.FirstOrDefault();
if (groupBase is null)
{
throw new Exception("No group found.");
}
Console.WriteLine($"CreateGroupDetail using {groupBase.GroupType.Name} [{groupBase.GroupType.Id}] to {groupType.Name} [{groupType.Id}]");
var groupView = document.GetElement(groupBase.OwnerViewId) as View;
var elementsToCopy = new[] { groupBase.Id };
var options = new CopyPasteOptions();
var elements = ElementTransformUtils.CopyElements(groupView, elementsToCopy, view, Transform.Identity, options);
var newGroup = elements.Select(e => document.GetElement(e)).OfType<Group>().FirstOrDefault();
newGroup.ChangeTypeId(groupType.Id);
var locationPoint = newGroup.Location as LocationPoint;
var oldLocation = locationPoint.Point;
locationPoint.Point = location;
Console.WriteLine($"CreateGroupDetail location {oldLocation} to {locationPoint.Point}");
return newGroup;
}
Work great but you need to have a Detail Group inside the document in some view, a placeholder like you mention.
Maybe would be possible to copy a view from another document with a detail inside if the main document does not have a Detail Group instance. Would be fun to experiment and useful to fix others Revit API limitations.
PS: Should be a good idea to edit the Revit idea and add the link about this post, so people could find a workaround solution and reference about the issue.