Pals,
I attached my code for method which creates family “mass” with inserted another family “profile” inside itself. I was writing at Forum about connecting family symbol with reference plane on reference line. I have done that know, but there has emerged another problem. When I try to modify family “mass” by moving reference line in it, symbol of family “profile” is not joined with reference line anymore, in other words updating of relationship between family symbol “profile” and reference line is not working. Do anyone know why this happen? Can host refrence help with this?
Pozz and thanks in advance,
Milica
Here is my code:
private void CreateNewFamilyMass(UIApplication uiapp, string familyMassName, string familyFileProfileName, ref string message)
{
Document familyDocument = uiapp.OpenAndActivateDocument(familyDocumentMass).Document;
if (null == familyDocument)
{
message = "Cannot create family document.";
return;
}
View targetLevel = null;
using (var familyTransaction = new Transaction(familyDocument, "Getting View"))
{
familyTransaction.Start();
FilteredElementCollector collector = new FilteredElementCollector(familyDocument).OfClass(typeof(View));
foreach (View v in collector)
{
if (string.Equals(v.Name, "{3D}"))
{
targetLevel = v;
break;
}
}
if (targetLevel == null) return;
familyTransaction.Commit();
}
uiapp.ActiveUIDocument.ActiveView = targetLevel;
using (var familyTransaction1 = new Transaction(familyDocument, "Create generic mass family"))
{
// set reference line from project
familyTransaction1.Start();
FilteredElementCollector lineCollector = new FilteredElementCollector(familyDocument).OfClass(typeof(CurveElement));
ModelLine referenceLine = null;
foreach (ModelLine modLine in lineCollector)
{
if (modLine.IsReferenceLine)
referenceLine = modLine;
}
if (referenceLine == null) return;
List<ElementId> refLines = new List<ElementId>();
refLines.Add(referenceLine.Id);
XYZ translationVec = new XYZ(10, 20, 0);
ElementTransformUtils.MoveElements(familyDocument, refLines, translationVec);
ElementTransformUtils.RotateElements(familyDocument, refLines, Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 10, 0)),0.26);
FilteredElementCollector collectorSP = new FilteredElementCollector(familyDocument).OfClass(typeof(SketchPlane));
SketchPlane skethPlane = null;
foreach (SketchPlane sp in collectorSP)
{
if (sp.Name == "Reference Lines")
{
skethPlane = sp; //break;
}
}
if (skethPlane == null) return;
uiapp.ActiveUIDocument.ActiveView.SketchPlane = skethPlane;
uiapp.ActiveUIDocument.ActiveView.ShowActiveWorkPlane();
//loading of family profile
Family family;
familyDocument.LoadFamily(familyFileProfileName, out family);
family.get_Parameter(BuiltInParameter.FAMILY_WORK_PLANE_BASED).Set(1);
family.get_Parameter(BuiltInParameter.FAMILY_ALWAYS_VERTICAL).Set(0);
FamilySymbol profileSymbol = null;
if (family != null)
{
foreach (FamilySymbol s in family.Symbols)
{
profileSymbol = s;
break;
}
var modLine = familyDocument.GetElement(refLines[0]) as ModelLine;
FamilyInstance instance = familyDocument.FamilyCreate.NewFamilyInstance(modLine.GeometryCurve.GetEndPoint(0), profileSymbol, modLine, StructuralType.NonStructural);
}
familyDocument.OwnerFamily.get_Parameter(BuiltInParameter.FAMILY_WORK_PLANE_BASED).Set(1);
familyDocument.OwnerFamily.get_Parameter(BuiltInParameter.FAMILY_ALWAYS_VERTICAL).Set(0);
familyTransaction1.Commit();
}
var option = new SaveAsOptions();
option.OverwriteExistingFile = true;
familyDocument.SaveAs(familyMassName, option);
//familyDocument.Close(false);
}