예제 #1
0
 internal static FreeForm FromExisting(Autodesk.Revit.DB.FreeFormElement freeFormElement, bool isRevitOwned)
 {
     return(new FreeForm(freeFormElement)
     {
         IsRevitOwned = isRevitOwned
     });
 }
예제 #2
0
        /// <summary>
        /// Apply SubCategory to Solid
        /// </summary>
        /// <param name="familyDocument"></param>
        /// <param name="subcategory"></param>
        /// <param name="freeform"></param>
        private static void ApplySubCategoryToFreeForm(
            Autodesk.Revit.DB.Document familyDocument,
            string subcategory,
            Autodesk.Revit.DB.FreeFormElement freeform)
        {
            var currentFamilyCategory = familyDocument.OwnerFamily.FamilyCategory;
            var newSubCategory        = familyDocument.Settings.Categories.NewSubcategory(currentFamilyCategory, subcategory);

            freeform.Subcategory = newSubCategory;
        }
예제 #3
0
        /// <summary>
        /// Apply Cutting Settings to Void
        /// </summary>
        /// <param name="freeform"></param>
        private static void ApplyVoidSettingsToFreeForm(Autodesk.Revit.DB.FreeFormElement freeform)
        {
            var elementIsCuttingParameter = freeform.get_Parameter(BuiltInParameter.ELEMENT_IS_CUTTING);

            if (elementIsCuttingParameter != null && !elementIsCuttingParameter.IsReadOnly)
            {
                Revit.Elements.InternalUtilities.ElementUtils.SetParameterValue(elementIsCuttingParameter, 1);
            }

            var cutWithVoidsParameter = freeform.get_Parameter(BuiltInParameter.FAMILY_ALLOW_CUT_WITH_VOIDS);

            if (cutWithVoidsParameter != null && !cutWithVoidsParameter.IsReadOnly)
            {
                Revit.Elements.InternalUtilities.ElementUtils.SetParameterValue(cutWithVoidsParameter, 1);
            }
        }
예제 #4
0
        /// <summary>
        /// Apply Material to Solid
        /// </summary>
        /// <param name="familyDocument"></param>
        /// <param name="material"></param>
        /// <param name="element"></param>
        private static void ApplyMaterialToFreeForm(
            Autodesk.Revit.DB.Document familyDocument,
            Revit.Elements.Material material,
            Autodesk.Revit.DB.FreeFormElement freeform)
        {
            var materialCollector = new Autodesk.Revit.DB.FilteredElementCollector(familyDocument)
                                    .OfClass(typeof(Autodesk.Revit.DB.Material));

            foreach (Autodesk.Revit.DB.Material mat in materialCollector)
            {
                if (mat.Name == material.Name)
                {
                    var materialParam = freeform.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM);
                    if (materialParam != null && !materialParam.IsReadOnly)
                    {
                        Revit.Elements.InternalUtilities.ElementUtils.SetParameterValue(materialParam, material);
                    }
                }
            }
        }
예제 #5
0
 public static FreeForm Wrap(Autodesk.Revit.DB.FreeFormElement ele, bool isRevitOwned)
 {
     return(FreeForm.FromExisting(ele, isRevitOwned));
 }
예제 #6
0
 private FreeForm(Autodesk.Revit.DB.FreeFormElement ele)
 {
     InternalSetFreeFormElement(ele);
 }
예제 #7
0
 private void InternalSetFreeFormElement(Autodesk.Revit.DB.FreeFormElement ele)
 {
     this.InternalFreeFormElement = ele;
     this.InternalElementId       = ele.Id;
     this.InternalUniqueId        = ele.UniqueId;
 }
예제 #8
0
        /// <summary>
        /// Creates a negative block family from the geometry of the target element and boundaries.
        /// </summary>
        /// <remarks>This is the main implementation of the sample command.</remarks>
        /// <param name="targetElement">The target solid element.</param>
        /// <param name="boundaries">The selected curve element boundaries.</param>
        /// <param name="familyLoadOptions">The family load options when loading the new family.</param>
        /// <param name="familyTemplate">The family template.</param>
        public static FailureCondition CreateNegativeBlock(Element targetElement, IList <Reference> boundaries, IFamilyLoadOptions familyLoadOptions, String familyTemplate)
        {
            Document doc = targetElement.Document;

            Autodesk.Revit.ApplicationServices.Application app = doc.Application;

            // Get curve loop for boundary
            IList <Curve> curves = GetContiguousCurvesFromSelectedCurveElements(doc, boundaries);
            CurveLoop     loop   = null;

            try
            {
                loop = CurveLoop.Create(curves);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException)
            {
                // Curves are not contiguous
                return(FailureCondition.CurvesNotContigous);
            }
            List <CurveLoop> loops = new List <CurveLoop>();

            loops.Add(loop);

            // Get elevation of loop
            double elevation = curves[0].GetEndPoint(0).Z;

            // Get height for extrusion
            BoundingBoxXYZ bbox   = targetElement.get_BoundingBox(null);
            double         height = bbox.Max.Z - elevation;

            if (height <= 1e-5)
            {
                return(FailureCondition.CurveLoopAboveTarget);
            }

            height += 1;

            // Create family
            Document familyDoc = app.NewFamilyDocument(familyTemplate);

            // Create block from boundaries
            Solid block = GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, height);

            // Subtract target element
            IList <Solid> fromElement = GetTargetSolids(targetElement);

            int solidCount = fromElement.Count;

            // Merge all found solids into single one
            Solid toSubtract = null;

            if (solidCount == 1)
            {
                toSubtract = fromElement[0];
            }

            else if (solidCount > 1)
            {
                toSubtract =
                    BooleanOperationsUtils.ExecuteBooleanOperation(fromElement[0], fromElement[1], BooleanOperationsType.Union);
            }

            if (solidCount > 2)
            {
                for (int i = 2; i < solidCount; i++)
                {
                    toSubtract = BooleanOperationsUtils.ExecuteBooleanOperation(toSubtract, fromElement[i],
                                                                                BooleanOperationsType.Union);
                }
            }

            // Subtract merged solid from overall block
            try
            {
                BooleanOperationsUtils.ExecuteBooleanOperationModifyingOriginalSolid(block, toSubtract,
                                                                                     BooleanOperationsType.Difference);
            }
            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
            {
                return(FailureCondition.NoIntersection);
            }

            // Create freeform element
            using (Transaction t = new Transaction(familyDoc, "Add element"))
            {
                t.Start();
                RevitFreeFormElement element = Autodesk.Revit.DB.FreeFormElement.Create(familyDoc, block);
                t.Commit();
            }

            // Load family into document
            Family family = familyDoc.LoadFamily(doc, familyLoadOptions);

            familyDoc.Close(false);

            // Get symbol as first symbol of loaded family
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.WherePasses(new FamilySymbolFilter(family.Id));
            FamilySymbol fs = collector.FirstElement() as FamilySymbol;


            // Place instance at location of original curves
            using (Transaction t2 = new Transaction(doc, "Place instance"))
            {
                t2.Start();
                doc.Create.NewFamilyInstance(XYZ.Zero, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                t2.Commit();
            }

            return(FailureCondition.Success);
        }
예제 #9
0
 private void InternalSetFreeFormElement(Autodesk.Revit.DB.FreeFormElement ele)
 {
     this.InternalFreeFormElement = ele;
     this.InternalElementId = ele.Id;
     this.InternalUniqueId = ele.UniqueId;
 }
예제 #10
0
 private FreeForm(Autodesk.Revit.DB.FreeFormElement ele)
 {
     SafeInit(() => InitFreeForm(ele));
 }