Ejemplo n.º 1
0
 private void buttonRemove_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (null != dataGridParamMap.SelectedItem)
         {
             ParameterMapProperties pmp = (ParameterMapProperties)dataGridParamMap.SelectedItem;
             dataGridParamMap.ItemsSource = null;
             for (int i = 0; i < parameterMapList.Count; i++)
             {
                 ParameterMapProperties properties = parameterMapList[i];
                 if (properties.SpatialCatName == pmp.SpatialCatName && properties.RevitCatName == pmp.RevitCatName && properties.SpatialParamName == pmp.SpatialParamName && properties.RevitParamName == pmp.RevitParamName)
                 {
                     parameterMapList.RemoveAt(i);
                     break;
                 }
             }
             dataGridParamMap.ItemsSource = parameterMapList;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to remove a parameter map.\n" + ex.Message, "Remove Parameter Map", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Ejemplo n.º 2
0
        private static ParameterMapProperties GetParameterMapProperties(Document doc, Entity entity)
        {
            ParameterMapProperties pmp = null;

            try
            {
                string spatialCategoryName  = entity.Get <string>(m_schema.GetField(s_SpatialCategory));
                string spatialParameterName = entity.Get <string>(m_schema.GetField(s_SpatialParameter));
                string revitCategoryName    = entity.Get <string>(m_schema.GetField(s_RevitCategory));
                string revitParameterName   = entity.Get <string>(m_schema.GetField(s_RevitParameter));

                Category spatialCategory = doc.Settings.Categories.get_Item(spatialCategoryName);
                Category revitCategory   = doc.Settings.Categories.get_Item(revitCategoryName);
                if (null != spatialCategory && null != revitCategory)
                {
                    CategoryProperties scp = new CategoryProperties(spatialCategory);
                    CategoryProperties rcp = new CategoryProperties(revitCategory);

                    ParameterProperties spp = new ParameterProperties(spatialParameterName);
                    ParameterProperties rpp = new ParameterProperties(revitParameterName);

                    pmp = new ParameterMapProperties(spp, rpp, scp, rcp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get parameter map properties.\n" + ex.Message, "Get Parameter Map Properties", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(pmp);
        }
Ejemplo n.º 3
0
        public static List <ParameterMapProperties> GetParameterMaps(Document doc)
        {
            List <ParameterMapProperties> parameterMaps = new List <ParameterMapProperties>();

            try
            {
                if (null == m_schema)
                {
                    m_schema = CreateSchema();
                }
                if (null != m_schema)
                {
                    IList <DataStorage> savedStorage = GetParameterMapStorage(doc, m_schema);
                    if (savedStorage.Count > 0)
                    {
                        foreach (DataStorage storage in savedStorage)
                        {
                            Entity entity = storage.GetEntity(m_schema);
                            ParameterMapProperties pmp = GetParameterMapProperties(doc, entity);
                            if (null != pmp)
                            {
                                parameterMaps.Add(pmp);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get parameter maps from data storage.\n" + ex.Message, "Get Parameter Maps", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(parameterMaps);
        }
Ejemplo n.º 4
0
        private List <SpatialElementProperties> FindSpatialElements(ParameterMapProperties pmp, bool includeLinks)
        {
            List <SpatialElementProperties> sepList = new List <SpatialElementProperties>();

            try
            {
                FilteredElementCollector collector       = new FilteredElementCollector(m_doc);
                List <SpatialElement>    spatialElements = collector.OfCategoryId(pmp.SpatialCategory.CategoryObj.Id).WhereElementIsNotElementType().Cast <SpatialElement>().ToList();
                foreach (SpatialElement se in spatialElements)
                {
                    SpatialElementProperties sep = new SpatialElementProperties(se);
                    sep.IsLinked = false;
                    sepList.Add(sep);
                }

                if (includeLinks)
                {
                    FilteredElementCollector linkCollector = new FilteredElementCollector(m_doc);
                    List <RevitLinkInstance> linkInstances = linkCollector.OfCategory(BuiltInCategory.OST_RvtLinks).WhereElementIsNotElementType().Cast <RevitLinkInstance>().ToList();
                    foreach (RevitLinkInstance instance in linkInstances)
                    {
                        LinkedInstanceProperties lip = new LinkedInstanceProperties(instance);
                        if (null != lip.LinkedDocument && null != lip.DocumentTitle)
                        {
                            FilteredElementCollector spaceCollector = new FilteredElementCollector(lip.LinkedDocument);
                            List <SpatialElement>    elements       = spaceCollector.OfCategoryId(pmp.SpatialCategory.CategoryObj.Id).WhereElementIsNotElementType().Cast <SpatialElement>().ToList();
                            if (elements.Count > 0)
                            {
                                foreach (SpatialElement se in elements)
                                {
                                    SpatialElementProperties sep = new SpatialElementProperties(se);
                                    sep.IsLinked       = true;
                                    sep.LinkProperties = lip;
                                    if (sep.SpaceArea > 0)
                                    {
                                        sepList.Add(sep);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessages.AppendLine("Cannot find spatial elements from " + pmp.SpatialCategory.CategoryName);
                errorMessages.AppendLine(ex.Message);
            }
            return(sepList);
        }
Ejemplo n.º 5
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != dataGridSpatial.SelectedItem && null != dataGridRevit.SelectedItem)
                {
                    ParameterProperties spp = (ParameterProperties)dataGridSpatial.SelectedItem;
                    ParameterProperties rpp = (ParameterProperties)dataGridRevit.SelectedItem;
                    if (rpp.IsSelectable)
                    {
                        CategoryProperties scp = (CategoryProperties)comboBoxSpace.SelectedItem;
                        CategoryProperties rcp = (CategoryProperties)comboBoxRevit.SelectedItem;

                        ParameterMapProperties pmp = new ParameterMapProperties(spp, rpp, scp, rcp);

                        var properties = from property in parameterMapList
                                         where property.SpatialCatName == scp.CategoryName && property.RevitCatName == rcp.CategoryName &&
                                         property.SpatialParamName == spp.ParameterName && property.RevitParamName == rpp.ParameterName
                                         select property;
                        if (properties.Count() == 0)
                        {
                            parameterMapList.Add(pmp);

                            dataGridParamMap.ItemsSource = null;
                            dataGridParamMap.ItemsSource = parameterMapList;
                        }
                        else
                        {
                            MessageBox.Show("The selected parameter map already exist in the selsction.\nPlease select different categories and paraemters.", "Existing Maps", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The storage types do not match between spatial and Revit parameters.\nPlease select a valid parameter.", "Storage Type Mismatched", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Please select a pair of parameter from a spatial category and a Revit category.", "Parameter Not Selected", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add links.\n" + ex.Message, "Add Parameter Maps", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 6
0
        private bool WriteParameter(ParameterMapProperties pmp, SpatialElementProperties sep, List <Element> revitElements)
        {
            bool result = false;

            try
            {
                SpatialElement spatialElement = sep.ElementObj;
                if (null != spatialElement)
                {
                    Parameter sParam = spatialElement.LookupParameter(pmp.SpatialParamName);

                    if (null != sParam)
                    {
                        using (Transaction trans = new Transaction(m_doc))
                        {
                            trans.Start("Write Parameters");
                            try
                            {
                                foreach (Element re in revitElements)
                                {
                                    if (re.GroupId != ElementId.InvalidElementId)
                                    {
                                        groupExist = true; continue;
                                    }                                                                              //elements in group
                                    Parameter rParam = re.LookupParameter(pmp.RevitParamName);
                                    if (null == rParam)
                                    {
                                        ElementType elementType = m_doc.GetElement(re.GetTypeId()) as ElementType;
                                        if (null != elementType)
                                        {
                                            rParam = elementType.LookupParameter(pmp.RevitParamName);
                                        }
                                    }

                                    if (null != rParam)
                                    {
                                        if (rParam.IsReadOnly)
                                        {
                                            continue;
                                        }
                                        switch (rParam.StorageType)
                                        {
                                        case StorageType.Double:
                                            try { rParam.Set(sParam.AsDouble()); }
                                            catch { }
                                            break;

                                        case StorageType.ElementId:
                                            try { rParam.Set(sParam.AsElementId()); }
                                            catch { }
                                            break;

                                        case StorageType.Integer:
                                            try { rParam.Set(sParam.AsInteger()); }
                                            catch { }
                                            break;

                                        case StorageType.String:
                                            try { rParam.Set(sParam.AsString()); }
                                            catch { }
                                            break;
                                        }
                                    }
                                }

                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                string message = ex.Message;
                                trans.RollBack();
                            }
                        }
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessages.AppendLine("Cannot write parameter values of family instances inside - " + sep.ElementObj.Number + " : " + sep.ElementObj.Name);
                errorMessages.AppendLine(ex.Message);
            }
            return(result);
        }
Ejemplo n.º 7
0
        private List <Element> FindRevitElements(ParameterMapProperties pmp, SpatialElementProperties sep)
        {
            List <Element> revitElements = new List <Element>();

            try
            {
                BoundingBoxXYZ boundingBox = null;
                Room           room        = null;
                Space          space       = null;

                if (sep.CategoryId == (int)BuiltInCategory.OST_Rooms)
                {
                    room        = sep.ElementObj as Room;
                    boundingBox = room.get_BoundingBox(null);
                }
                else if (sep.CategoryId == (int)BuiltInCategory.OST_MEPSpaces)
                {
                    space       = sep.ElementObj as Space;
                    boundingBox = space.get_BoundingBox(null);
                }

                if (null != boundingBox)
                {
                    XYZ minXYZ = boundingBox.Min;
                    XYZ maxXYZ = boundingBox.Max;

                    if (sep.IsLinked && null != sep.LinkProperties)
                    {
                        minXYZ = sep.LinkProperties.TransformValue.OfPoint(minXYZ);
                        maxXYZ = sep.LinkProperties.TransformValue.OfPoint(maxXYZ);
                    }
                    //bounding box quick filter
                    Outline outline = new Outline(minXYZ, maxXYZ);
                    BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline);
                    BoundingBoxIsInsideFilter   insideFilter    = new BoundingBoxIsInsideFilter(outline);
                    LogicalOrFilter             orFilter        = new LogicalOrFilter(intersectFilter, insideFilter);

                    FilteredElementCollector collector = new FilteredElementCollector(m_doc);
                    List <Element>           elements  = collector.OfCategoryId(pmp.RevitCategory.CategoryObj.Id).WherePasses(orFilter).ToElements().ToList();

                    if (checkBoxIntersect.IsChecked == true)
                    {
                        revitElements.AddRange(elements);
                    }
                    else
                    {
                        //slow solid filter
                        if (elements.Count > 0)
                        {
                            foreach (Element element in elements)
                            {
                                LocationPoint locationPt = element.Location as LocationPoint;
                                if (null != locationPt)
                                {
                                    XYZ point = locationPt.Point;
                                    if (sep.IsLinked && null != sep.LinkProperties)
                                    {
                                        point = sep.LinkProperties.TransformValue.Inverse.OfPoint(point);
                                    }

                                    if (null != room)
                                    {
                                        if (room.IsPointInRoom(point))
                                        {
                                            revitElements.Add(element);
                                        }
                                    }
                                    else if (null != space)
                                    {
                                        if (space.IsPointInSpace(point))
                                        {
                                            revitElements.Add(element);
                                        }
                                    }
                                }

                                LocationCurve locationCurve = element.Location as LocationCurve;
                                if (null != locationCurve)
                                {
                                    Curve curve    = locationCurve.Curve;
                                    XYZ   firstPt  = curve.GetEndPoint(0);
                                    XYZ   secondPt = curve.GetEndPoint(1);
                                    XYZ   centerPt = curve.Evaluate(0.5, true);

                                    if (sep.IsLinked && null != sep.LinkProperties)
                                    {
                                        firstPt  = sep.LinkProperties.TransformValue.Inverse.OfPoint(firstPt);
                                        secondPt = sep.LinkProperties.TransformValue.Inverse.OfPoint(secondPt);
                                    }

                                    if (null != room)
                                    {
                                        //modification: pick centroid
                                        if (room.IsPointInRoom(centerPt))
                                        {
                                            revitElements.Add(element);
                                        }

                                        /*
                                         * if (room.IsPointInRoom(firstPt) || room.IsPointInRoom(secondPt))
                                         * {
                                         *  revitElements.Add(element);
                                         * }*/
                                    }
                                    else if (null != space)
                                    {
                                        if (space.IsPointInSpace(centerPt))
                                        {
                                            revitElements.Add(element);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorMessages.AppendLine("Cannot find model elements from - " + sep.ElementObj.Number + " : " + sep.ElementObj.Name);
                errorMessages.AppendLine(ex.Message);
            }
            return(revitElements);
        }