@noamgatCXBC7 - did you get anywhere with this?
We are working on copying ViewSections with referenced views from one document to another.
We have taken the approach of replicating the callouts, but we've run into the following issues:
Callout head placed in default position
Cannot adjust callout head position
Reference sections do not have a CropShape when using the ViewSection.CreateReferenceSection method. Therefore, when we attempt to replicate the reference section to another document, it fails to replicate due to lack of CropShape (line 30 of code snip below).
We have attempted to use ViewCropRegionShapeManager.SetCropShape() to define the crop shape after creating the reference section with no luck passing in the same Curveloop from the original section, nor when passing the original curves of the section into a new Curveloop (We did not go as granular as defining each point for StartPoint/EndPoint of each curve to create a Curveloop that way).
Below is a code snip (we error at line 30 - list is empty) :
{
try
{
// Get Family and Type Parameter
Parameter sectionFamilyAndType = section.LookupParameter("Family and Type");
ElementId sectionFamilyAndTypeId = sectionFamilyAndType.AsElementId();
var sectionViewFamilyType = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _schaeferDetailsDoc : _doc).GetElement(sectionFamilyAndTypeId);
// Get Section Tag Parameter
Parameter sectionTagParameter = sectionViewFamilyType.LookupParameter("Section Tag");
ElementId sectionTagId = sectionTagParameter.AsElementId();
var sectionTag = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _schaeferDetailsDoc : _doc).GetElement(sectionTagId);
// Get Section Head Parameter
Parameter sectionHeadParameter = sectionTag.LookupParameter("Section Head");
ElementId sectionHeadId = sectionHeadParameter.AsElementId();
FamilySymbol sectionHead = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _schaeferDetailsDoc : _doc).GetElement(sectionHeadId) as FamilySymbol;
// Get Section Tail Parameter
Parameter sectionTailParameter = sectionTag.LookupParameter("Section Tail");
ElementId sectionTailId = sectionTailParameter.AsElementId();
FamilySymbol sectionTail = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _schaeferDetailsDoc : _doc).GetElement(sectionTailId) as FamilySymbol;
// Get Broken Section Display Style Parameter
Parameter brokenSectionDisplayStyleParameter = sectionTag.LookupParameter("Broken Section Display Style");
string brokenSectionDisplayStyleValue = brokenSectionDisplayStyleParameter.AsValueString();
// Get crop shape of callout
ViewCropRegionShapeManager refSectionCRSM = View.GetCropRegionShapeManagerForReferenceCallout(_direction == ReferenceDirection.SchaeferDetailsToProject ? _schaeferDetailsDoc : _doc, section.Id);
IList<CurveLoop> refSectionCropShapeList = refSectionCRSM.GetCropShape();
CurveLoop refSectionCropShape = refSectionCropShapeList[0];
CurveLoopIterator curveLoopIterator = refSectionCropShape.GetCurveLoopIterator();
Curve refSectionCropShapeCurve = curveLoopIterator.Current;
XYZ startPoint = refSectionCropShapeCurve.GetEndPoint(0);
XYZ endPoint = refSectionCropShapeCurve.GetEndPoint(1);
bool continueIterating = curveLoopIterator.MoveNext();
//Get XYZ points of callout
XYZ max = new XYZ(startPoint.X, startPoint.Y, 0);
XYZ min = new XYZ(startPoint.X, startPoint.Y, 0);
while (continueIterating)
{
refSectionCropShapeCurve = curveLoopIterator.Current;
startPoint = refSectionCropShapeCurve.GetEndPoint(0);
endPoint = refSectionCropShapeCurve.GetEndPoint(1);
if (startPoint.X > max.X)
{
max = new XYZ(startPoint.X, max.Y, 0);
}
else if (startPoint.X < min.X)
{
min = new XYZ(startPoint.X, min.Y, 0);
}
if (startPoint.Y > max.Y)
{
max = new XYZ(max.X, startPoint.Y, 0);
}
else if (startPoint.Y < min.Y)
{
min = new XYZ(min.X, startPoint.Y, 0);
}
continueIterating = curveLoopIterator.MoveNext();
}
using (Transaction t4 = new Transaction(_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc, "Duplicate view detailing"))
{
t4.Start();
// have to get all the callouts already in the detail before creating the new one
ICollection<ElementId> existingRefSections = (_direction == ReferenceDirection.SchaeferDetailsToProject ? detail.ProjectDraftingView : detail.SchaeferDetailsDraftingView).GetReferenceSections();
// because this stupid method doesn't tell you the id of the element it creates... how dumb?
if (_direction == ReferenceDirection.SchaeferDetailsToProject) ViewSection.CreateReferenceSection(_doc, detail.ProjectDraftingView.Id, relatedDetail.ProjectDraftingView.Id, min, max);
else if (_direction == ReferenceDirection.WorkingModelToSchaeferDetails) ViewSection.CreateReferenceSection(_schaeferDetailsDoc, detail.SchaeferDetailsDraftingView.Id, relatedDetail.SchaeferDetailsDraftingView.Id, min, max);
// so then have to get the new element id like this... obviously, i'm annoyed by this right now...
// there should only be one additional id
IEnumerable<ElementId> newRefSectionIdsToDoc = (_direction == ReferenceDirection.SchaeferDetailsToProject ? detail.ProjectDraftingView : detail.SchaeferDetailsDraftingView).GetReferenceSections().Except(existingRefSections);
ElementId refSectionIdToDoc = null;
foreach (ElementId _refSectionIdToDoc in newRefSectionIdsToDoc)
{
ElementId refViewId = ReferenceableViewUtils.GetReferencedViewId(_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc, _refSectionIdToDoc);
if (refViewId == (_direction == ReferenceDirection.SchaeferDetailsToProject ? relatedDetail.ProjectDraftingView.Id : relatedDetail.SchaeferDetailsDraftingView.Id))
{
refSectionIdToDoc = _refSectionIdToDoc;
break;
}
}
Element refSectionToDoc = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc).GetElement(refSectionIdToDoc);
// Get Family and Type
Parameter sectionFamilyAndTypeToDoc = refSectionToDoc.LookupParameter("Family and Type");
ElementId sectionFamilyAndTypeToDocId = sectionFamilyAndTypeToDoc.AsElementId();
var sectionViewFamilyTypeToDoc = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc).GetElement(sectionFamilyAndTypeToDocId);
// Get Section Tag
Parameter sectionTagToDocParameter = sectionViewFamilyTypeToDoc.LookupParameter("Section Tag");
ElementId sectionTagToDocId = sectionTagToDocParameter.AsElementId();
var sectionTagToDoc = (_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc).GetElement(sectionTagToDocId);
// Set Section Head
Parameter sectionHeadToDocParameter = sectionTagToDoc.LookupParameter("Section Head");
ICollection<Element> sectionHeads = new FilteredElementCollector(_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc).OfCategory(BuiltInCategory.OST_SectionHeads).ToElements();
ElementId sectionHeadToDocId = null;
foreach (Element elem in sectionHeads)
{
FamilySymbol secHead = elem as FamilySymbol;
string sectionHeadName = sectionHead.Name;
if (char.IsDigit(sectionHeadName[sectionHeadName.Length - 1]))
{
sectionHeadName = sectionHeadName.Remove(sectionHeadName.Length - 1);
}
if (secHead.Name.Contains(sectionHeadName.Trim()))
{
sectionHeadToDocId = secHead.Id;
break;
}
}
sectionHeadToDocParameter.Set(sectionHeadToDocId);
// Set Section Tail
Parameter sectionTailToDocParameter = sectionTagToDoc.LookupParameter("Section Tail");
ICollection<Element> sectionTails = new FilteredElementCollector(_direction == ReferenceDirection.SchaeferDetailsToProject ? _doc : _schaeferDetailsDoc).OfCategory(BuiltInCategory.OST_SectionHeads).ToElements();
ElementId sectionTailToDocId = null;
foreach (Element elem in sectionTails)
{
FamilySymbol secTail = elem as FamilySymbol;
string sectionTailName = sectionTail.Name;
if (char.IsDigit(sectionTailName[sectionTailName.Length - 1]))
{
sectionTailName = sectionTailName.Remove(sectionTailName.Length - 1);
}
if (secTail.Name.Contains(sectionTailName.Trim()))
{
sectionTailToDocId = secTail.Id;
break;
}
}
sectionTailToDocParameter.Set(sectionTailToDocId);
// Set Broken Section Display Style
Parameter brokenSectionDisplayStyleToDocParameter = sectionTagToDoc.LookupParameter("Broken Section Display Style");
brokenSectionDisplayStyleToDocParameter.Set(brokenSectionDisplayStyleValue);
t4.Commit();
}
}
catch (Exception)
{
Autodesk.Revit.UI.TaskDialog.Show("Reference Error", $"Ugh... hate when this happens...\n\nThere was an issue creating the reference of detail {relatedDetail.ProjectDraftingView.Name} in detail {detail.ProjectDraftingView.Name}.\n\nSorry, you'll have to make the reference yourself.");
}
}
@jeremy_tammik - care to weigh in? 😊