Beispiel #1
0
        /***************************************************/

        public static ElementType ToRevitElementType(this ClonedType clonedType, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            ElementType elementType = refObjects.GetValue <ElementType>(document, clonedType.BHoM_Guid);

            if (elementType != null)
            {
                return(elementType);
            }

            settings = settings.DefaultIfNull();

            Element source = document.GetElement(new ElementId(clonedType.SourceTypeId));

            if (source == null)
            {
                BH.Engine.Reflection.Compute.RecordError($"The element with ElementId {clonedType.SourceTypeId} does not exist in the active Revit document.");
                return(null);
            }

            ElementType sourceType = source as ElementType;

            if (sourceType == null)
            {
                BH.Engine.Reflection.Compute.RecordError($"The element with ElementId {clonedType.SourceTypeId} exists in the active Revit document, but it is not an element type.");
                return(null);
            }

            elementType = sourceType.Duplicate(clonedType.Name);

            // Copy parameters from BHoM object to Revit element
            elementType.CopyParameters(clonedType, settings);

            refObjects.AddOrReplace(clonedType, elementType);
            return(elementType);
        }
Beispiel #2
0
        /// <summary>
        /// duplicate one FamilySymbol and add to lists
        /// </summary>
        /// <param name="framingSymbol">FamilySymbol to be copied</param>
        /// <param name="symbolName">duplicate FamilySymbol's Name</param>
        /// <returns>new FamilySymbol</returns>
        public FamilySymbol DuplicateSymbol(ElementType framingSymbol, string symbolName)
        {
            // duplicate a FamilySymbol
            ElementType  symbol = framingSymbol.Duplicate(GenerateSymbolName(symbolName));
            FamilySymbol result = symbol as FamilySymbol;

            if (null != result)
            {
                // add to lists
                m_symbolMaps.Add(result.Name, result);
                m_symbols.Add(result);
            }
            return(result);
        }
Beispiel #3
0
        public static ElementType DuplicateByType(this Document document, PanelType panelType_New, Construction construction_New)
        {
            if (construction_New == null || document == null)
            {
                return(null);
            }

            FilteredElementCollector filteredElementCollector = Query.FilteredElementCollector(document, panelType_New);

            if (filteredElementCollector == null)
            {
                return(null);
            }

            List <ElementType> elementTypes = filteredElementCollector.OfClass(typeof(ElementType)).Cast <ElementType>().ToList();

            if (elementTypes == null || elementTypes.Count == 0)
            {
                return(null);
            }

            ElementType elementType = elementTypes.Find(x => x.Name.Equals(construction_New.Name));

            if (elementType == null)
            {
                Construction construction = Analytical.Query.DefaultConstruction(panelType_New);
                if (construction == null)
                {
                    return(null);
                }

                ElementType elementType_ToBeDuplicated = elementTypes.Find(x => x.Name.Equals(construction.Name));
                if (elementType_ToBeDuplicated == null)
                {
                    return(null);
                }

                elementType = elementType_ToBeDuplicated.Duplicate(construction_New.Name);
            }

            if (elementType == null)
            {
                return(null);
            }

            Core.Revit.Modify.SetValues(elementType, construction_New);
            Core.Revit.Modify.SetValues(elementType, construction_New, ActiveSetting.Setting);

            return(elementType);
        }
Beispiel #4
0
        public static ElementType DuplicateByType(this Document document, string name_Old, ApertureConstruction apertureConstruction_New)
        {
            if (apertureConstruction_New == null || document == null || string.IsNullOrWhiteSpace(name_Old))
            {
                return(null);
            }

            BuiltInCategory builtInCategory = apertureConstruction_New.ApertureType.BuiltInCategory();

            if (builtInCategory == BuiltInCategory.INVALID)
            {
                return(null);
            }

            List <ElementType> elementTypes = new FilteredElementCollector(document).OfClass(typeof(ElementType)).OfCategory(builtInCategory).Cast <ElementType>().ToList();

            if (elementTypes == null || elementTypes.Count == 0)
            {
                return(null);
            }

            ElementType elementType = elementTypes.Find(x => x.Name.Equals(apertureConstruction_New.Name));

            if (elementType == null)
            {
                ElementType elementType_ToBeDuplicated = elementTypes.Find(x => x.Name.Equals(name_Old));
                if (elementType_ToBeDuplicated == null)
                {
                    return(null);
                }

                elementType = elementType_ToBeDuplicated.Duplicate(apertureConstruction_New.Name);
            }

            if (elementType == null)
            {
                return(null);
            }

            Core.Revit.Modify.SetValues(elementType, apertureConstruction_New);
            Core.Revit.Modify.SetValues(elementType, apertureConstruction_New, ActiveSetting.Setting);

            return(elementType);
        }
Beispiel #5
0
        public static ElementType DuplicateByName(this Document document, string name_Old, BuiltInCategory builtInCategory, SAMType sAMType_New, IEnumerable <string> parameterNames = null)
        {
            if (sAMType_New == null || document == null || string.IsNullOrWhiteSpace(name_Old) || builtInCategory == BuiltInCategory.INVALID)
            {
                return(null);
            }

            string name_New = sAMType_New.Name;

            if (string.IsNullOrWhiteSpace(name_New))
            {
                return(null);
            }

            List <ElementType> elementTypes = new FilteredElementCollector(document).OfClass(typeof(ElementType)).OfCategory(builtInCategory).Cast <ElementType>().ToList();

            if (elementTypes == null || elementTypes.Count == 0)
            {
                return(null);
            }

            ElementType elementType = elementTypes.Find(x => x.Name.Equals(name_New));

            if (elementType == null)
            {
                ElementType elementType_ToBeDuplicated = elementTypes.Find(x => x.Name.Equals(name_Old));
                if (elementType_ToBeDuplicated == null)
                {
                    return(null);
                }

                elementType = elementType_ToBeDuplicated.Duplicate(name_New);
            }

            if (elementType == null)
            {
                return(null);
            }

            SetValues(elementType, sAMType_New, parameterNames);

            return(elementType);
        }
Beispiel #6
0
        private ElementType CreateTrimType(ElementType type, string trimCol, string shutCol)
        {
            List <Material> materialElements = _doc.CollectElements <Material>(BuiltInCategory.OST_Materials);

            string newTypeName = $"{type.FamilyName}-{trimCol}-{shutCol}";

            _tt.Start();

            ElementType newTrimType = type.Duplicate(newTypeName);

            // Retrieving the materials to match the desired type
            Material trimMat    = null;
            Material shutterMat = null;

            foreach (Material material in materialElements.Where(material => material.Name.Contains("Wood")))
            {
                if (material.Name.Contains(trimCol))
                {
                    trimMat = material;
                }

                if (material.Name.Contains(shutCol))
                {
                    shutterMat = material;
                }
            }

            // Setting the parameters for the new trim type
            if (trimMat != null)
            {
                newTrimType.SetParameter("Material", trimMat.Id);
            }

            if (shutterMat != null)
            {
                newTrimType.SetParameter("Shutter Material", shutterMat.Id);
            }

            _tt.Commit();

            return(newTrimType);
        }
        /// <summary>
        /// <remarks>郑海盛</remarks>
        /// 复制type
        /// </summary>
        /// <param name="eleid"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public virtual ElementType CopyFamilySymbol(ElementId eleid, string name)
        {
            ElementType eType = this.m_RevitDoc.GetElement(eleid) as ElementType;

            using (Transaction trans = new Transaction(this.m_RevitDoc))
            {
                try
                {
                    trans.Start("复制族类型");
                    var type = eType.Duplicate(name);
                    trans.Commit();
                    return(type);
                }
                catch
                {
                    trans.RollBack();
                    return(null);
                }
            }
        }
Beispiel #8
0
        public void CreateNewTypes()
        {
            UIDocument uidoc = ActiveUIDocument;
            Document   doc   = uidoc.Document;

            ElementClassFilter           f1 = new ElementClassFilter(typeof(FamilyInstance));
            StructuralMaterialTypeFilter f2 = new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete);
            ElementClassFilter           f3 = new ElementClassFilter(typeof(Floor));
            ElementClassFilter           f4 = new ElementClassFilter(typeof(Wall));
            LogicalAndFilter             f5 = new LogicalAndFilter(f1, f2);
            LogicalOrFilter f6           = new LogicalOrFilter(f3, f4);
            LogicalOrFilter memberFilter = new LogicalOrFilter(f5, f6);

            FilteredElementCollector collector = new FilteredElementCollector(doc);

            collector.WherePasses(memberFilter);
            List <Element> members = collector.ToList();

            using (Transaction tx = new Transaction(doc, "MarkFrames")){
                tx.Start();
                foreach (Element e in members)
                {
                    Debug.Print(string.Format(
                                    "Type '{0}-{1}' listed.",
                                    e.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString(),
                                    e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString()));
                    try {
                        ElementId   eTypeId  = e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsElementId();
                        ElementType eType    = doc.GetElement(eTypeId) as ElementType;
                        ElementType newEType = eType.Duplicate(string.Format(
                                                                   "{0}-{1}",
                                                                   e.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString(),
                                                                   e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString())) as ElementType;
                        e.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).Set(newEType.Id);
                    } catch (Exception) {
                        //throw;
                    }
                }
                tx.Commit();
            }
        }
Beispiel #9
0
        public bool TryRebuildRevitModel(Autodesk.Revit.DB.Document inputDoc, RevitModelRequest inputReqeust, out Autodesk.Revit.DB.Element createdElement)
        {
            createdElement = null;
            try
            {
                UseRevitModelRequest useRequest = inputReqeust as UseRevitModelRequest;

                LineElement line1 = inputReqeust.RequestData.LstCurveElements[0] as LineElement;

                LineElement line2 = inputReqeust.RequestData.LstCurveElements[1] as LineElement;

                XYZ midStart, midEnd;

                double width;

                if (line1.ThisCurve.Project(line2.ThisCurve.GetEndPoint(0)).XYZPoint.IsAlmostEqualTo(line1.ThisCurve.GetEndPoint(0)))
                {
                    midStart = (line1.ThisCurve.GetEndPoint(0) + line2.ThisCurve.GetEndPoint(0)) / 2;
                    midEnd   = (line1.ThisCurve.GetEndPoint(1) + line2.ThisCurve.GetEndPoint(1)) / 2;
                    width    = line1.ThisCurve.GetEndPoint(0).DistanceTo(line2.ThisCurve.GetEndPoint(0));
                }
                else
                {
                    midStart = (line1.ThisCurve.GetEndPoint(0) + line2.ThisCurve.GetEndPoint(1)) / 2;
                    midEnd   = (line1.ThisCurve.GetEndPoint(1) + line2.ThisCurve.GetEndPoint(0)) / 2;
                    width    = line1.ThisCurve.GetEndPoint(0).DistanceTo(line2.ThisCurve.GetEndPoint(1));
                }

                Line useMidLine = Line.CreateBound(midStart, midEnd);

                string useTypeName = inputReqeust.UseTypeName;

                FilteredElementCollector useCollector = new FilteredElementCollector(inputDoc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType();

                ElementType useElementType = null;

                foreach (var oneElement in useCollector.ToElements())
                {
                    if (oneElement.Name == useTypeName)
                    {
                        useElementType = oneElement as ElementType;
                        break;
                    }
                }



                Transaction useTransaction = new Transaction(inputDoc, "creatWall");
                useTransaction.Start();
                useElementType = useElementType.Duplicate(useTypeName + Guid.NewGuid().ToString());

                var useStructure = (useElementType as WallType).GetCompoundStructure();
                useStructure.SetLayerWidth(0, width);
                (useElementType as WallType).SetCompoundStructure(useStructure);

                createdElement = Wall.Create(inputDoc, useMidLine, (inputDoc.ActiveView as ViewPlan).GenLevel.Id, false);
                (createdElement as Wall).WallType = useElementType as WallType;
                useTransaction.Commit();


                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #10
0
        public static ElementType set_elementtype(CompoundStructure compound, ObservableCollection <data_materials> mydata_materials, ObservableCollection <data_parameters> mydata_parameters,
                                                  ElementType elementType, string CreateOrUpdate, string name_type_new, string unit_length)
        {
            ElementType elementType_new = null;

            try
            {
                var TypeOftype = elementType.GetType();
                if (CreateOrUpdate == Source.Update)
                {
                    F_SetCompound.set_compound_structure(compound, mydata_materials, mydata_parameters, unit_length);

                    if (elementType.GetType().Name == "WallType")
                    {
                        var wall_Type = elementType as WallType;
                        wall_Type.SetCompoundStructure(compound);
                    }
                    if (elementType.GetType().Name == "FloorType")
                    {
                        var floor_Type = elementType as FloorType;
                        floor_Type.SetCompoundStructure(compound);
                    }
                    if (elementType.GetType().Name == "RoofType")
                    {
                        var roof_Type = elementType as RoofType;
                        roof_Type.SetCompoundStructure(compound);
                    }
                    if (elementType.GetType().Name == "CeilingType")
                    {
                        var ceiling_Type = elementType as CeilingType;
                        ceiling_Type.SetCompoundStructure(compound);
                    }
                }
                else if (CreateOrUpdate == Source.Duplicate)
                {
                    if (elementType.GetType().Name == "WallType")
                    {
                        var wall_Type = elementType.Duplicate(name_type_new) as WallType;
                        elementType_new = wall_Type;
                        wall_Type.SetCompoundStructure(F_SetCompound.set_compound_structure(wall_Type.GetCompoundStructure(), mydata_materials, mydata_parameters, unit_length));
                    }
                    if (elementType.GetType().Name == "FloorType")
                    {
                        var floor_Type = elementType.Duplicate(name_type_new) as FloorType;
                        elementType_new = floor_Type;
                        floor_Type.SetCompoundStructure(F_SetCompound.set_compound_structure(floor_Type.GetCompoundStructure(), mydata_materials, mydata_parameters, unit_length));
                    }
                    if (elementType.GetType().Name == "RoofType")
                    {
                        var roof_Type = elementType.Duplicate(name_type_new) as RoofType;
                        elementType_new = roof_Type;
                        roof_Type.SetCompoundStructure(F_SetCompound.set_compound_structure(roof_Type.GetCompoundStructure(), mydata_materials, mydata_parameters, unit_length));
                    }
                    if (elementType.GetType().Name == "CeilingType")
                    {
                        var ceiling_Type = elementType.Duplicate(name_type_new) as CeilingType;
                        elementType_new = ceiling_Type;
                        ceiling_Type.SetCompoundStructure(F_SetCompound.set_compound_structure(ceiling_Type.GetCompoundStructure(), mydata_materials, mydata_parameters, unit_length));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(elementType_new);
        }
Beispiel #11
0
        const double labelTextOffset      = 0.005;   // 5mm, defined in paper space
        #endregion

        #region InterfaceImplementation
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public virtual Result Execute(ExternalCommandData commandData
                                      , ref string message, ElementSet elements)
        {
            try
            {
                Document document           = commandData.Application.ActiveUIDocument.Document;
                Autodesk.Revit.DB.View view = commandData.View;

                // find major and minor station arrow styles
                FilteredElementCollector fec            = new FilteredElementCollector(document);
                Element majorStationLeaderArrowheadType = fec.OfClass(typeof(ElementType))
                                                          .Cast <ElementType>()
                                                          .FirstOrDefault(x => x.Name.Contains(majorStationLeaderArrowheadName));
                Element minorStationLeaderArrowheadType = fec.OfClass(typeof(ElementType))
                                                          .Cast <ElementType>()
                                                          .FirstOrDefault(x => x.Name.Contains(minorStationLeaderArrowheadName));
                if (majorStationLeaderArrowheadType == null || minorStationLeaderArrowheadType == null)
                {
                    TaskDialog td = new TaskDialog("Missing arrowheads");
                    td.MainContent = "In Manage>Additional Settings>Arrowheads, create two styles of arrowheads, named\r\n" +
                                     "Major Station Arrowhead and Minor Station Arrowhead";
                    td.Show();

                    return(Result.Failed);
                }

                // find major and minor station label types; if not there, create them
                SpotDimensionType majorLabelType = fec.OfClass(typeof(SpotDimensionType))
                                                   .Cast <SpotDimensionType>()
                                                   .FirstOrDefault(sdt => sdt.StyleType == DimensionStyleType.AlignmentStationLabel && sdt.Name.Contains(majorStationSetLabelTypeName));

                SpotDimensionType minorLabelType = fec.OfClass(typeof(SpotDimensionType))
                                                   .Cast <SpotDimensionType>()
                                                   .FirstOrDefault(sdt => sdt.StyleType == DimensionStyleType.AlignmentStationLabel && sdt.Name.Contains(minorStationSetLabelTypeName));

                SpotDimensionType curvatureLabelType = fec.OfClass(typeof(SpotDimensionType))
                                                       .Cast <SpotDimensionType>()
                                                       .FirstOrDefault(sdt => sdt.StyleType == DimensionStyleType.AlignmentStationLabel && sdt.Name.Contains(horizontalCurvatureChangeLabelTypeName));

                using (Transaction t = new Transaction(document, "Create major station labels"))
                {
                    t.Start();
                    if (majorLabelType == null)
                    {
                        // create major station label type with the given arrowhead style
                        majorLabelType = document.GetElement(AlignmentStationLabel.CreateRecommendedTypeForSet(document)) as SpotDimensionType;
                        majorLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_LEADER_ARROWHEAD).Set(majorStationLeaderArrowheadType.Id);
                        majorLabelType.Name = majorStationSetLabelTypeName;
                    }

                    if (minorLabelType == null)
                    {
                        // create minor station label type with the given arrowhead style
                        // exclude the station text, which leave only the arrowheads
                        // make the minor station's color grey
                        // make the text 60% of the original value, in case text is later turned on
                        minorLabelType = document.GetElement(AlignmentStationLabel.CreateRecommendedTypeForSet(document)) as SpotDimensionType;
                        minorLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_LEADER_ARROWHEAD).Set(minorStationLeaderArrowheadType.Id);
                        minorLabelType.get_Parameter(BuiltInParameter.ALIGNMENT_STATION_LABEL_INCLUDE_STATION).Set(0);
                        minorLabelType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(8421504 /* 127*2^0 + 127*2^8 + 127*2^16: grey */);
                        Parameter textSizeParam = minorLabelType.get_Parameter(BuiltInParameter.TEXT_SIZE);
                        textSizeParam.Set(textSizeParam.AsDouble() * 0.6);
                        minorLabelType.Name = minorStationSetLabelTypeName;
                    }

                    if (curvatureLabelType == null)
                    {
                        // create a new label type, based on the default alignment station label type,
                        // but with some adjustments to the label contents, as described below
                        ElementType defaultAlignmentLabelType = document.GetElement(
                            document.GetDefaultElementTypeId(ElementTypeGroup.AlignmentStationLabelType)) as ElementType;

                        curvatureLabelType = defaultAlignmentLabelType.Duplicate(horizontalCurvatureChangeLabelTypeName) as SpotDimensionType;

                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_COORDINATE_BASE).Set(1);              // "Shared" coordinate base

                        // Label position and content
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_ROTATE_WITH_COMPONENT).Set(0);         // do not rotate with component
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_TEXT_ORIENTATION).Set(0);              // horizontal text
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_TEXT_LOCATION).Set(0);                 // text location above leader
                        curvatureLabelType.get_Parameter(BuiltInParameter.ALIGNMENT_STATION_LABEL_INCLUDE_STATION).Set(1); // include station
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_COORDINATE_INCLUDE_ELEVATION).Set(0);       // do not include elevation
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_BOT_VALUE).Set(0);                     // do not include bottom value
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_TOP_VALUE).Set(0);                     // do not include top value
                        curvatureLabelType.get_Parameter(BuiltInParameter.ALIGNMENT_STATION_LABEL_IND_STATION).Set("");    // empty station indicator

                        // Text
                        curvatureLabelType.get_Parameter(BuiltInParameter.DIM_TEXT_BACKGROUND).Set(0);                              // nontransparent text
                        curvatureLabelType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(255 /* 255*2^0 + 0*2^8 + 0*2^16: red */); // text in red color
                        Parameter textSizeParam = curvatureLabelType.get_Parameter(BuiltInParameter.TEXT_SIZE);
                        textSizeParam.Set(textSizeParam.AsDouble() * 0.6);                                                          // text size 60% of default

                        // Leader
                        curvatureLabelType.get_Parameter(BuiltInParameter.SPOT_ELEV_LEADER_ARROWHEAD).Set(ElementId.InvalidElementId); // no leader arrowhead
                    }
                    t.Commit();
                }

                // create major and minor station label sets
                ElementId alignmentId = AlignmentSelectionFilter.SelectAlignment(document);
                Alignment alignment   = Alignment.Get(document.GetElement(alignmentId));

                // start placement from a multiple of the major station interval
                // make sure to compute the multiple in the proper unit system and then convert it back to internal units for further use
                double labelSetsPlacementStartStation = UnitUtils.ConvertFromInternalUnits(alignment.DisplayedStartStation, UnitTypeId.StationingMeters);
                labelSetsPlacementStartStation =
                    Math.Ceiling(labelSetsPlacementStartStation / majorStationInterval) * majorStationInterval;
                labelSetsPlacementStartStation =
                    UnitUtils.ConvertToInternalUnits(labelSetsPlacementStartStation, UnitTypeId.StationingMeters);

                var majorStations = new List <double>();
                using (Transaction t = new Transaction(document, "Create major station labels"))
                {
                    t.Start();
                    AlignmentStationLabelSetOptions options = new AlignmentStationLabelSetOptions();
                    options.Interval     = UnitUtils.ConvertToInternalUnits(majorStationInterval, UnitTypeId.StationingMeters);
                    options.Offset       = UnitUtils.ConvertToInternalUnits(labelTextOffset, UnitTypeId.StationingMeters);
                    options.StartStation = labelSetsPlacementStartStation;
                    options.EndStation   = alignment.DisplayedEndStation;
                    options.TypeId       = majorLabelType.Id;

                    var labels = AlignmentStationLabel.CreateSet(alignment, view, options);
                    foreach (var label in labels)
                    {
                        majorStations.Add(label.Station);
                    }
                    t.Commit();
                }

                using (Transaction t = new Transaction(document, "Create minor station labels"))
                {
                    t.Start();
                    AlignmentStationLabelSetOptions options = new AlignmentStationLabelSetOptions();
                    options.Interval = UnitUtils.ConvertToInternalUnits(minorStationInterval, UnitTypeId.StationingMeters);
                    // setting text offset specification can be skipped,
                    // as in this example the minor station labels do not include any label text, only leader arrowheads
                    options.StartStation = labelSetsPlacementStartStation;
                    options.EndStation   = labelSetsPlacementStartStation + UnitUtils.ConvertToInternalUnits(majorStationInterval, UnitTypeId.StationingMeters);
                    options.TypeId       = minorLabelType.Id;

                    // delete the minor station labels which overlap with the major ones
                    var labels = AlignmentStationLabel.CreateSet(alignment, view, options);
                    foreach (var label in labels)
                    {
                        foreach (var majorStation in majorStations)
                        {
                            if (MathComparisonUtils.IsAlmostEqual(label.Station, majorStation))
                            {
                                label.Element.Pinned = false;
                                document.Delete(label.Element.Id);
                                break;
                            }
                        }
                    }

                    t.Commit();
                }

                if (view.ViewType == ViewType.FloorPlan || view.ViewType == ViewType.CeilingPlan || view.ViewType == ViewType.EngineeringPlan)
                {
                    IList <HorizontalCurveEndpoint> curveEndpoints = alignment.GetDisplayedHorizontalCurveEndpoints();
                    using (TransactionGroup tg = new TransactionGroup(document, "Create horizontal curvature changes labels"))
                    {
                        tg.Start();

                        double previousStation = alignment.DisplayedStartStation;
                        foreach (var curveEndpoint in curveEndpoints)
                        {
                            using (Transaction t = new Transaction(document, "Create one horizontal curvature change label"))
                            {
                                double thisStation = curveEndpoint.Station;
                                // skip placing curvature labels at the start and end points of the alignment
                                if (MathComparisonUtils.IsAlmostEqual((alignment.DisplayedStartStation), thisStation) ||
                                    MathComparisonUtils.IsAlmostEqual((alignment.DisplayedEndStation), thisStation))
                                {
                                    continue;
                                }

                                t.Start();

                                AlignmentStationLabelOptions options = new AlignmentStationLabelOptions(thisStation);
                                options.HasLeader = false;
                                options.TypeId    = curvatureLabelType.Id;

                                AlignmentStationLabel label = AlignmentStationLabel.Create(alignment, view, options);

                                // regeneration is necessary before the label's positional properties (such as Origin)L can be properly evaluated
                                document.Regenerate();

                                // set the shoulder and end to coincide, creating a leader pointing along the view's up direction
                                SpotDimension dim = label.Element as SpotDimension;

                                XYZ leaderDirection = view.UpDirection;
                                // compute the distance to the previous label
                                // if the previous label is too close, flip the placement direction
                                {
                                    var    dimBBox   = dim.get_BoundingBox(view);
                                    double dimOffset = Math.Abs(dimBBox.Max.X - dimBBox.Min.X);
                                    if (MathComparisonUtils.IsGreaterThanOrAlmostEqual(dimOffset, thisStation - previousStation))
                                    {
                                        leaderDirection = leaderDirection.Negate();
                                    }
                                }

                                dim.HasLeader              = true;
                                dim.LeaderHasShoulder      = true;
                                dim.LeaderShoulderPosition = dim.Origin +
                                                             leaderDirection * UnitUtils.ConvertToInternalUnits(labelTextOffset, UnitTypeId.StationingMeters) * view.Scale;
                                dim.LeaderEndPosition = dim.LeaderShoulderPosition;
                                dim.TextPosition      = dim.LeaderShoulderPosition;

                                previousStation = thisStation;
                                t.Commit();
                            }
                        }
                        tg.Assimilate();
                    }
                }

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Beispiel #12
0
        protected virtual Element CreateNewElement(DataRow row)
        {
            // *** Coyove Patched ***

            Element result;

            try
            {
                string text  = APIObjectList.ColumnRes((BuiltInParameter)(-1002002));
                string text2 = APIObjectList.ColumnRes((BuiltInParameter)(-1002001));
                string text3 = row[text].ToString();
                string text4 = row[text2].ToString();
                if (text3 == null || text4 == null || text3 == string.Empty || text4 == string.Empty)
                {
                    result = null;
                }
                else
                {
                    string arg = text4;
                    while (true)
                    {
                        string text5 = text4.Replace("'", "''");
                        string text6 = text3.Replace("'", "''");
                        // string filterExpression = string.Format("[{0}] = '{1}' and [{2}] = '{3}'", new object[]
                        string filterExpression = string.Format("\"{0}\" = '{1}' and \"{2}\" = '{3}'", new object[]
                        {
                            text,
                            text6,
                            text2,
                            text5
                        });
                        if (row.Table.Select(filterExpression).Length <= 1)
                        {
                            break;
                        }
                        text4 = arg + " " + this.m_numberSuffix;
                        Utility.Assign(row, text2, text4);
                        this.m_numberSuffix++;
                    }
                    Element element = null;
                    foreach (Element element2 in base.Elements)
                    {
                        if (element == null)
                        {
                            element = element2;
                        }
                        Parameter parameter = element2.get_Parameter((BuiltInParameter)(-1002002));
                        if (parameter != null && parameter.AsString().Equals(text3))
                        {
                            element = element2;
                            break;
                        }
                    }
                    if (element == null)
                    {
                        result = null;
                    }
                    else
                    {
                        ElementType elementType = element as ElementType;
                        Element     element3    = elementType.Duplicate(text4);
                        base.Elements.Insert(element3);
                        row[base.TableInfo[base.TableInfo.PrimaryKeys[0]].Name] = element3.Id.IntegerValue;
                        result = element3;
                    }
                }
            }
            catch
            {
                result = null;
            }
            return(result);
        }
Beispiel #13
0
 /// <summary>
 /// duplicate one FamilySymbol and add to lists
 /// </summary>
 /// <param name="framingSymbol">FamilySymbol to be copied</param>
 /// <param name="symbolName">duplicate FamilySymbol's Name</param>
 /// <returns>new FamilySymbol</returns>
 public FamilySymbol DuplicateSymbol(ElementType framingSymbol, string symbolName)
 {
     // duplicate a FamilySymbol
     ElementType symbol = framingSymbol.Duplicate(GenerateSymbolName(symbolName));
     FamilySymbol result = symbol as FamilySymbol;
     if (null != result)
     {
         // add to lists
         m_symbolMaps.Add(result.Name, result);
         m_symbols.Add(result);
     }
     return result;
 }