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.StructuralAssetClass assetClass = default; if (!DA.GetData("Type", ref assetClass)) { return; } // check naming conflicts with other asset types var 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 structAsset = new DB.StructuralAsset(name, assetClass); // 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)) { structAsset.Behavior = behaviour; } else { structAsset.Behavior = DB.StructuralBehavior.Isotropic; } // set the asset on psetelement psetElement = DB.PropertySetElement.Create(doc, structAsset); // grab asset data from inputs var assetData = CreateAssetDataFromInputs(DA); UpdatePropertySetElementFromData(psetElement, assetData); // send the new asset to output DA.SetData(ComponentInfo.Name, new Types.StructuralAssetElement(psetElement)); }