protected void SetOutputsFromPropertySetElement(IGH_DataAccess DA, DB.PropertySetElement psetElement)
        {
            if (psetElement is null)
            {
                return;
            }

            foreach (var assetPropInfo in _assetData.GetAssetProperties())
            {
                // determine which output parameter to set the value on
                var paramInfo = _assetData.GetGHParameterInfo(assetPropInfo);
                if (paramInfo is null)
                {
                    continue;
                }

                // grab the value from the first valid builtin param and set on the ouput
                foreach (var builtInPropInfo in _assetData.GetAPIAssetBuiltInPropertyInfos(assetPropInfo))
                {
                    if (psetElement.get_Parameter(builtInPropInfo.ParamId) is DB.Parameter parameter)
                    {
                        DA.SetData(paramInfo.Name, parameter.AsGoo());
                        break;
                    }
                }
            }
        }
Пример #2
0
        SetOutputFromPropertySetElementParam(IGH_DataAccess DA, DB.PropertySetElement srcElement,
                                             DB.BuiltInParameter srcParam, string paramName)
        {
            if (srcElement is null)
            {
                DA.SetData(paramName, null);
                return(false);
            }

            bool valueFound = false;
            var  param      = srcElement.get_Parameter(srcParam);

            if (param != null)
            {
                valueFound = true;
                switch (param.StorageType)
                {
                case DB.StorageType.None: break;

                case DB.StorageType.String:
                    DA.SetData(paramName, param.AsString());
                    break;

                case DB.StorageType.Integer:
                    if (param.Definition.ParameterType == DB.ParameterType.YesNo)
                    {
                        DA.SetData(paramName, param.AsInteger() != 0);
                    }
                    else
                    {
                        DA.SetData(paramName, param.AsInteger());
                    }
                    break;

                case DB.StorageType.Double:
                    DA.SetData(paramName, param.AsDoubleInRhinoUnits());
                    break;

                case DB.StorageType.ElementId:
                    DA.SetData(
                        paramName,
                        Types.Element.FromElementId(srcElement.Document, param.AsElementId())
                        );
                    break;
                }
            }

            return(valueFound);
        }
Пример #3
0
 // determines matching assets based on any builtin properties
 // that are marked exclusive
 protected bool MatchesPhysicalAssetType(DB.PropertySetElement psetElement)
 {
     foreach (var assetPropInfo in _assetData.GetAssetProperties())
     {
         foreach (var builtInPropInfo in
                  _assetData.GetAPIAssetBuiltInPropertyInfos(assetPropInfo))
         {
             if (builtInPropInfo.Exclusive &&
                 psetElement.get_Parameter(builtInPropInfo.ParamId) is null)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #4
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            // get input structural asset
            DB.PropertySetElement psetElement = default;
            if (!DA.GetData(ComponentInfo.Name, ref psetElement))
            {
                return;
            }

            var doc = Revit.ActiveDBDocument;

            using (var transaction = NewTransaction(doc))
            {
                // update the asset properties from input data
                try
                {
                    // check asset type
                    if (!MatchesPhysicalAssetType(psetElement))
                    {
                        AddRuntimeMessage(
                            GH_RuntimeMessageLevel.Error,
                            $"Incompatible asset type"
                            );
                        return;
                    }

                    transaction.Start();

                    // grab asset data from inputs
                    var assetData = CreateAssetDataFromInputs(DA);
                    UpdatePropertySetElementFromData(psetElement, assetData);

                    transaction.Commit();

                    // send the modified asset to output
                    DA.SetData(
                        ComponentInfo.Name,
                        psetElement
                        );
                }
                catch (Exception ex)
                {
                    transaction.RollBack();
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Revit API Error | {ex.Message}");
                }
            }
        }
Пример #5
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            DB.PropertySetElement psetElement = default;
            if (!DA.GetData(ComponentInfo.Name, ref psetElement))
            {
                return;
            }

            // check asset type
            if (!MatchesPhysicalAssetType(psetElement))
            {
                AddRuntimeMessage(
                    GH_RuntimeMessageLevel.Error,
                    $"Incompatible asset type"
                    );
                return;
            }

            SetOutputsFromPropertySetElement(DA, psetElement);
        }
Пример #6
0
        protected void SetOutputsFromPropertySetElement(IGH_DataAccess DA, DB.PropertySetElement psetElement)
        {
            foreach (var assetPropInfo in _assetData.GetAssetProperties())
            {
                // determine which output parameter to set the value on
                var paramInfo = _assetData.GetGHParameterInfo(assetPropInfo);
                if (paramInfo is null)
                {
                    continue;
                }

                // grab the value from the first valid builtin param and set on the ouput
                foreach (var builtInPropInfo in
                         _assetData.GetAPIAssetBuiltInPropertyInfos(assetPropInfo))
                {
                    if (SetOutputFromPropertySetElementParam(DA, psetElement, builtInPropInfo.ParamId, paramInfo.Name))
                    {
                        break;
                    }
                }
            }
        }
Пример #7
0
        protected void UpdatePropertySetElementFromData(DB.PropertySetElement psetElement, T assetData)
        {
            foreach (var assetPropInfo in _assetData.GetAssetProperties())
            {
                // skip name because it is already set
                if (assetPropInfo.Name == "Name")
                {
                    continue;
                }

                bool hasValue = assetData.IsMarked(assetPropInfo.Name);
                if (hasValue)
                {
                    object inputValue = assetPropInfo.GetValue(assetData);

                    foreach (var builtInPropInfo in
                             _assetData.GetAPIAssetBuiltInPropertyInfos(assetPropInfo))
                    {
                        psetElement.SetParameterValue(builtInPropInfo.ParamId, inputValue);
                    }
                }
            }
        }
Пример #8
0
 public StructuralAssetElement(DB.PropertySetElement asset) : base(asset)
 {
 }
Пример #9
0
        public static Dictionary <string, object> GetMaterialProperties(string materialname)
        {
            Revit.Elements.Material mat = Revit.Elements.Material.ByName(materialname);

            RVT.Material material = (RVT.Material)mat.InternalElement;


            // Get the active Document
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            string appearancename = "None";
            List <Autodesk.Revit.DB.Parameter> appearances = new List <Autodesk.Revit.DB.Parameter>();

            if (material.AppearanceAssetId != Autodesk.Revit.DB.ElementId.InvalidElementId)
            {
                RVT.AppearanceAssetElement appearance = (RVT.AppearanceAssetElement)document.GetElement(material.AppearanceAssetId);
                appearancename = appearance.Name;

                foreach (RVT.Parameter parameter in appearance.Parameters)
                {
                    if (!appearances.Contains(parameter))
                    {
                        appearances.Add(parameter);
                    }
                }
            }

            string thermalname = "None";
            List <Autodesk.Revit.DB.Parameter> thermals = new List <Autodesk.Revit.DB.Parameter>();

            if (material.ThermalAssetId != Autodesk.Revit.DB.ElementId.InvalidElementId)
            {
                RVT.PropertySetElement thermal = (RVT.PropertySetElement)document.GetElement(material.ThermalAssetId);
                thermalname = thermal.Name;

                foreach (RVT.Parameter parameter in thermal.Parameters)
                {
                    if (!thermals.Contains(parameter))
                    {
                        thermals.Add(parameter);
                    }
                }
            }

            string structuralname = "None";
            List <Autodesk.Revit.DB.Parameter> structurals = new List <Autodesk.Revit.DB.Parameter>();

            if (material.StructuralAssetId != Autodesk.Revit.DB.ElementId.InvalidElementId)
            {
                RVT.PropertySetElement structural = (RVT.PropertySetElement)document.GetElement(material.StructuralAssetId);
                structuralname = structural.Name;

                foreach (RVT.Parameter parameter in structural.Parameters)
                {
                    if (!structurals.Contains(parameter))
                    {
                        structurals.Add(parameter);
                    }
                }
            }

            return(new Dictionary <string, object>
            {
                { "Name", material.Name },
                { "Id", material.Id.IntegerValue },
                { "Category", material.MaterialCategory },
                { "Class", material.MaterialClass },
                { "Transparency", material.Transparency },
                { "Smoothness", material.Smoothness },
                { "Shininess", material.Shininess },
                { "Color", material.Color },
                { "Appearance Name", appearancename },
                { "Appearance Parameters", appearances },
                { "Structural Name", structuralname },
                { "Structural Parameters", structurals },
                { "Thermal Name", thermalname },
                { "Thermal Parameters", thermals },
            });
        }
 public ThermalAssetElement(DB.PropertySetElement asset) : base(asset)
 {
 }
Пример #11
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            if (!Parameters.Document.GetDataOrDefault(this, DA, "Document", out var doc))
            {
                return;
            }

            // get required input (name, class)
            string name = default;

            if (!DA.GetData("Name", ref name))
            {
                return;
            }

            DB.ThermalMaterialType materialType = default;
            if (!DA.GetData("Type", ref materialType))
            {
                return;
            }

            using (var transaction = NewTransaction(doc))
            {
                try
                {
                    // check naming conflicts with other asset types
                    DB.PropertySetElement psetElement = FindPropertySetElement(doc, name);
                    if (psetElement != null && psetElement.Id != DB.ElementId.InvalidElementId)
                    {
                        if (!MatchesPhysicalAssetType(psetElement))
                        {
                            AddRuntimeMessage(
                                GH_RuntimeMessageLevel.Error,
                                $"Thermal asset with same name exists already. Use a different name for this asset"
                                );
                            return;
                        }
                    }

                    transaction.Start();

                    // delete existing matching psetelement
                    if (psetElement != null && psetElement.Id != DB.ElementId.InvalidElementId)
                    {
                        doc.Delete(psetElement.Id);
                    }

                    // creaet asset from input data
                    var thermalAsset = new DB.ThermalAsset(name, materialType);

                    // we need to apply the behaviour here manually
                    // otherwise the resultant DB.PropertySetElement will be missing parameters
                    DB.StructuralBehavior behaviour = default;
                    if (DA.GetData("Behaviour", ref behaviour))
                    {
                        thermalAsset.Behavior = behaviour;
                    }
                    else
                    {
                        thermalAsset.Behavior = DB.StructuralBehavior.Isotropic;
                    }

                    // set the asset on psetelement
                    psetElement = DB.PropertySetElement.Create(doc, thermalAsset);

                    // grab asset data from inputs
                    var assetData = CreateAssetDataFromInputs(DA);
                    UpdatePropertySetElementFromData(psetElement, assetData);

                    // send the new asset to output
                    DA.SetData(
                        ComponentInfo.Name,
                        psetElement
                        );
                }
                catch (Exception ex)
                {
                    transaction.RollBack();
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Revit API Error | {ex.Message}");
                }

                transaction.Commit();
            }
        }
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            if (!Parameters.Document.GetDataOrDefault(this, DA, "Document", out var doc))
            {
                return;
            }

            // get required input (name, class)
            string name = default;

            if (!DA.GetData("Name", ref name))
            {
                return;
            }

            DB.ThermalMaterialType materialType = default;
            if (!DA.GetData("Type", ref materialType))
            {
                return;
            }

            // check naming conflicts with other asset types
            DB.PropertySetElement psetElement = FindPropertySetElement(doc, name);
            if (psetElement != null && !MatchesPhysicalAssetType(psetElement))
            {
                AddRuntimeMessage(
                    GH_RuntimeMessageLevel.Error,
                    $"Thermal asset with same name exists already. Use a different name for this asset"
                    );
                return;
            }

            StartTransaction(doc);

            // TODO: reuse psetElement if suitable
            // delete existing matching psetelement
            if (psetElement != null)
            {
                doc.Delete(psetElement.Id);
            }

            // create asset from input data
            var thermalAsset = new DB.ThermalAsset(name, materialType);

            // we need to apply the behaviour here manually
            // otherwise the resultant DB.PropertySetElement will be missing parameters
            var behaviour = DB.StructuralBehavior.Isotropic;

            DA.GetData("Behaviour", ref behaviour);

            // set the asset on psetelement
            psetElement = DB.PropertySetElement.Create(doc, thermalAsset);

            // grab asset data from inputs
            var assetData = CreateAssetDataFromInputs(DA);

            UpdatePropertySetElementFromData(psetElement, assetData);

            // send the new asset to output
            DA.SetData(ComponentInfo.Name, new Types.ThermalAssetElement(psetElement));
        }