Ejemplo n.º 1
0
 //----------------------------------------------------------
 public static void Get_All_Material_Of_Element_By_Category(Document doc, Element element, List <data_paint> materials)
 {
     try
     {
         if (element.Category.Name == "Railings")
         {
             RailingType type = doc.GetElement(element.GetTypeId()) as RailingType;
             if (type.RailStructure.GetNonContinuousRailCount() > 0)
             {
                 for (var i = 0; i < type.RailStructure.GetNonContinuousRailCount(); i++)
                 {
                     var      idRailing = type.RailStructure.GetNonContinuousRail(i).MaterialId;
                     Material m         = doc.GetElement(idRailing) as Material;
                     if (m != null)
                     {
                         materials.Add(new data_paint()
                         {
                             vat_lieu = m,
                             is_paint = Source.no_paint
                         });
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates height for a railing
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType, EntryMap entryMap)
        {
            if (element == null)
            {
                return(false);
            }

            // For Railing
            RailingType railingType = element.Document.GetElement(element.GetTypeId()) as RailingType;

            if (railingType != null)
            {
                m_Height = UnitUtil.ScaleLength(railingType.TopRailHeight);
                return(true);
            }

            // For ProvisionForVoid
            ShapeCalculator shapeCalculator = ShapeCalculator.Instance;

            if (shapeCalculator != null && shapeCalculator.GetCurrentElement() == element)
            {
                if (String.Compare(shapeCalculator.GetStringValue(), IFCProvisionForVoidShapeType.Rectangle.ToString()) == 0)
                {
                    IFCAnyHandle rectProfile = shapeCalculator.GetCurrentProfileHandle();
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(rectProfile))
                    {
                        // This is already scaled.
                        double?height = IFCAnyHandleUtil.GetDoubleAttribute(rectProfile, "YDim");
                        m_Height = height.HasValue ? height.Value : 0.0;
                        if (m_Height > MathUtil.Eps())
                        {
                            return(true);
                        }
                    }
                }
            }

            if (ParameterUtil.GetDoubleValueFromElementOrSymbol(element, entryMap.RevitParameterName, out m_Height) == null)
            {
                ParameterUtil.GetDoubleValueFromElementOrSymbol(element, entryMap.CompatibleRevitParameterName, out m_Height);
            }

            m_Height = UnitUtil.ScaleLength(m_Height);
            if (m_Height > MathUtil.Eps())
            {
                return(true);
            }

            // For other elements
            if (extrusionCreationData == null)
            {
                return(false);
            }

            m_Height = extrusionCreationData.ScaledHeight;
            return(m_Height > MathUtil.Eps());
        }
        /// <summary>
        /// Calculates height for a railing
        /// </summary>
        /// <param name="exporterIFC">
        /// The ExporterIFC object.
        /// </param>
        /// <param name="extrusionCreationData">
        /// The IFCExtrusionCreationData.
        /// </param>
        /// <param name="element">
        /// The element to calculate the value.
        /// </param>
        /// <param name="elementType">
        /// The element type.
        /// </param>
        /// <returns>
        /// True if the operation succeed, false otherwise.
        /// </returns>
        public override bool Calculate(ExporterIFC exporterIFC, IFCExtrusionCreationData extrusionCreationData, Element element, ElementType elementType)
        {
            if (element == null)
            {
                return(false);
            }
            RailingType railingType = element.Document.GetElement(element.GetTypeId()) as RailingType;

            if (railingType == null)
            {
                return(false);
            }

            m_Height = UnitUtil.ScaleLength(railingType.TopRailHeight);
            return(true);
        }
Ejemplo n.º 4
0
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Add an EventLogTraceListener object
            System.Diagnostics.Trace.Listeners.Add(
                new System.Diagnostics.EventLogTraceListener("Application"));

            // Lay the hands on the active document
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            // Set up a timer
            Timing myTimer = new Timing();

            myTimer.StartTime();
            try {
                Reference       r        = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                Railing         railing  = doc.GetElement(r) as Railing;
                GeometryElement geomElem = railing.get_Geometry(new Options {
                    IncludeNonVisibleObjects = true
                });

                RvtRailing  rvtRailing  = new RvtRailing();
                RailingType railingType =
                    doc.GetElement(railing.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsElementId())
                    as RailingType;

                // Extract and sort out the railign's parts
                foreach (GeometryObject geomObj in geomElem)
                {
                    if (geomObj is GeometryInstance)
                    {
                        GetRailingParts((GeometryInstance)geomObj, rvtRailing);
                    }
                }

                #region Tracing
                // Just a check on the number of total solids
                // obtained from the railing
                IList <Solid> allSolids = new List <Solid>();

                // Get all solids from the revit railing element
                GetSolid(railing.get_Geometry(new Options {
                    IncludeNonVisibleObjects = true
                }), allSolids);

                StringBuilder strBld = new StringBuilder();
                for (int i = 0; i < allSolids.Count; ++i)
                {
                    strBld.AppendFormat("s{0}.Volume = {1}\n", i, allSolids[i].Volume);
                }

                System.Diagnostics.Trace.Write(strBld.ToString());
                #endregion

                TaskDialog.Show("Parts", string.Format("Top Rails: {0}; Length = {1:F2}\nRails: {2}; Length = {1:F2}; Area = {6:F2}sq ft\nBalusters: {3}; Length = {4:F2}\nAllSolids: {5}",
                                                       rvtRailing.TopRails.Count,
                                                       UnitUtils.ConvertFromInternalUnits(rvtRailing.TopRailLength, DisplayUnitType.DUT_MILLIMETERS),
                                                       rvtRailing.Rails.Count,
                                                       rvtRailing.Balusters.Count,
                                                       UnitUtils.ConvertFromInternalUnits(rvtRailing.BalusterLength, DisplayUnitType.DUT_MILLIMETERS),
                                                       allSolids.Count,
                                                       rvtRailing.Rails[0].Volume / rvtRailing.TopRailLength));

                return(Result.Succeeded);
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                return(Result.Cancelled);
            }
            catch (Exception ex) {
                TaskDialog.Show("Exception",
                                string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                System.Diagnostics.Trace.Write(string.Format("{0}\n{1}",
                                                             ex.Message, ex.StackTrace));
                return(Result.Failed);
            }
            finally {
                myTimer.StopTime();
                System.Diagnostics.Trace
                .Write(string.Format("Time elapsed: {0}s",
                                     myTimer.Duration.TotalSeconds));
            }
        }