Skip to content

Commit

Permalink
fix(revit): adds null checks for analytical model in revit 2022 and b… (
Browse files Browse the repository at this point in the history
#1931)

fix(revit): adds null checks for analytical model in revit 2022 and below
  • Loading branch information
teocomi authored Nov 26, 2022
1 parent 0535300 commit cdfe001
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,25 @@ private Element1D AnalyticalStickToSpeckle(AnalyticalModelStick revitStick)
var stickFamily = (Autodesk.Revit.DB.FamilyInstance)revitStick.Document.GetElement(revitStick.GetElementId());
var section = stickFamily.Symbol.GetStructuralSection();

var speckleSection = GetSectionProfile(section);
SectionProfile speckleSection = null;
if (section != null)
speckleSection = GetSectionProfile(section);



var materialType = stickFamily.StructuralMaterialType;
var structMat = (DB.Material)stickFamily.Document.GetElement(stickFamily.StructuralMaterialId);
if (structMat == null)
structMat = (DB.Material)stickFamily.Document.GetElement(stickFamily.Symbol.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM).AsElementId());
var materialAsset = ((PropertySetElement)structMat.Document.GetElement(structMat.StructuralAssetId)).GetStructuralAsset();

var name = stickFamily.Document.GetElement(stickFamily.StructuralMaterialId).Name;
Structural.Materials.StructuralMaterial speckleMaterial = GetStructuralMaterial(materialType, materialAsset, name);
Structural.Materials.StructuralMaterial speckleMaterial = null;
if (structMat.StructuralAssetId != ElementId.InvalidElementId)
{
var materialAsset = ((PropertySetElement)structMat.Document.GetElement(structMat.StructuralAssetId)).GetStructuralAsset();
var name = stickFamily.Document.GetElement(stickFamily.StructuralMaterialId).Name;
speckleMaterial = GetStructuralMaterial(materialType, materialAsset, name);
}


prop.profile = speckleSection;
prop.material = speckleMaterial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,89 +158,94 @@ private Element2D AnalyticalSurfaceToSpeckle(AnalyticalModelSurface revitSurface
memberType = MemberType2D.Wall;
}

var materialAsset = ((PropertySetElement)structMaterial.Document.GetElement(structMaterial.StructuralAssetId)).GetStructuralAsset();
var materialType = structMaterial.MaterialClass;

Structural.Materials.StructuralMaterial speckleMaterial = null;
switch (materialType)
if (structMaterial.StructuralAssetId != ElementId.InvalidElementId)
{
case "Concrete":
var concreteMaterial = new Concrete
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name,
materialType = Structural.MaterialType.Concrete,
grade = null,
designCode = null,
codeYear = null,
elasticModulus = materialAsset.YoungModulus.X,
compressiveStrength = materialAsset.ConcreteCompression,
tensileStrength = 0,
flexuralStrength = 0,
maxCompressiveStrain = 0,
maxTensileStrain = 0,
maxAggregateSize = 0,
lightweight = materialAsset.Lightweight,
poissonsRatio = materialAsset.PoissonRatio.X,
shearModulus = materialAsset.ShearModulus.X,
density = materialAsset.Density,
thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X,
dampingRatio = 0
};
speckleMaterial = concreteMaterial;
break;
case "Steel":
var steelMaterial = new Steel
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name,
materialType = Structural.MaterialType.Steel,
grade = materialAsset.Name,
designCode = null,
codeYear = null,
elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter
yieldStrength = materialAsset.MinimumYieldStress, // Newtons per foot meter
ultimateStrength = materialAsset.MinimumTensileStrength, // Newtons per foot meter
maxStrain = 0,
poissonsRatio = materialAsset.PoissonRatio.X,
shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter
density = materialAsset.Density, // kilograms per cubed feet
thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin
dampingRatio = 0
};
speckleMaterial = steelMaterial;
break;
case "Wood":
var timberMaterial = new Timber
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name,
materialType = Structural.MaterialType.Timber,
grade = materialAsset.WoodGrade,
designCode = null,
codeYear = null,
elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter
poissonsRatio = materialAsset.PoissonRatio.X,
shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter
density = materialAsset.Density, // kilograms per cubed feet
thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin
species = materialAsset.WoodSpecies,
dampingRatio = 0
};
timberMaterial["bendingStrength"] = materialAsset.WoodBendingStrength;
timberMaterial["parallelCompressionStrength"] = materialAsset.WoodParallelCompressionStrength;
timberMaterial["parallelShearStrength"] = materialAsset.WoodParallelShearStrength;
timberMaterial["perpendicularCompressionStrength"] = materialAsset.WoodPerpendicularCompressionStrength;
timberMaterial["perpendicularShearStrength"] = materialAsset.WoodPerpendicularShearStrength;
speckleMaterial = timberMaterial;
break;
default:
var defaultMaterial = new Structural.Materials.StructuralMaterial
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name
};
speckleMaterial = defaultMaterial;
break;
}
var materialAsset = ((PropertySetElement)structMaterial.Document.GetElement(structMaterial.StructuralAssetId)).GetStructuralAsset();
var materialType = structMaterial.MaterialClass;

prop.material = speckleMaterial;
Structural.Materials.StructuralMaterial speckleMaterial = null;
switch (materialType)
{
case "Concrete":
var concreteMaterial = new Concrete
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name,
materialType = Structural.MaterialType.Concrete,
grade = null,
designCode = null,
codeYear = null,
elasticModulus = materialAsset.YoungModulus.X,
compressiveStrength = materialAsset.ConcreteCompression,
tensileStrength = 0,
flexuralStrength = 0,
maxCompressiveStrain = 0,
maxTensileStrain = 0,
maxAggregateSize = 0,
lightweight = materialAsset.Lightweight,
poissonsRatio = materialAsset.PoissonRatio.X,
shearModulus = materialAsset.ShearModulus.X,
density = materialAsset.Density,
thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X,
dampingRatio = 0
};
speckleMaterial = concreteMaterial;
break;
case "Steel":
var steelMaterial = new Steel
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name,
materialType = Structural.MaterialType.Steel,
grade = materialAsset.Name,
designCode = null,
codeYear = null,
elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter
yieldStrength = materialAsset.MinimumYieldStress, // Newtons per foot meter
ultimateStrength = materialAsset.MinimumTensileStrength, // Newtons per foot meter
maxStrain = 0,
poissonsRatio = materialAsset.PoissonRatio.X,
shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter
density = materialAsset.Density, // kilograms per cubed feet
thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin
dampingRatio = 0
};
speckleMaterial = steelMaterial;
break;
case "Wood":
var timberMaterial = new Timber
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name,
materialType = Structural.MaterialType.Timber,
grade = materialAsset.WoodGrade,
designCode = null,
codeYear = null,
elasticModulus = materialAsset.YoungModulus.X, // Newtons per foot meter
poissonsRatio = materialAsset.PoissonRatio.X,
shearModulus = materialAsset.ShearModulus.X, // Newtons per foot meter
density = materialAsset.Density, // kilograms per cubed feet
thermalExpansivity = materialAsset.ThermalExpansionCoefficient.X, // inverse Kelvin
species = materialAsset.WoodSpecies,
dampingRatio = 0
};
timberMaterial["bendingStrength"] = materialAsset.WoodBendingStrength;
timberMaterial["parallelCompressionStrength"] = materialAsset.WoodParallelCompressionStrength;
timberMaterial["parallelShearStrength"] = materialAsset.WoodParallelShearStrength;
timberMaterial["perpendicularCompressionStrength"] = materialAsset.WoodPerpendicularCompressionStrength;
timberMaterial["perpendicularShearStrength"] = materialAsset.WoodPerpendicularShearStrength;
speckleMaterial = timberMaterial;
break;
default:
var defaultMaterial = new Structural.Materials.StructuralMaterial
{
name = structMaterial.Document.GetElement(structMaterial.StructuralAssetId).Name
};
speckleMaterial = defaultMaterial;
break;
}


prop.material = speckleMaterial;
}
prop.name = revitSurface.Document.GetElement(revitSurface.GetElementId()).Name;
//prop.type = memberType;
//prop.analysisType = Structural.AnalysisType2D.Shell;
Expand Down

0 comments on commit cdfe001

Please sign in to comment.