Skip to content

Commit

Permalink
Fix null handling in FEMesh
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Taylor committed Aug 3, 2021
1 parent 8601565 commit 359f54e
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions Etabs_Adapter/CRUD/Read/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,17 @@ private List<FEMesh> ReadMesh(List<string> ids = null)

List<FEMesh> meshes = new List<FEMesh>();
Dictionary<string, Node> nodes = new Dictionary<string, Node>();
Dictionary<string, ISurfaceProperty> surfaceProps = ReadSurfaceProperty().ToDictionary(x => GetAdapterId<string>(x));

foreach (string id in ids)
{
FEMesh mesh = new FEMesh();

ETABSId etabsid = new ETABSId();
etabsid.Id = id;

List<string> meshNodeIds = new List<string>();

string propertyName = "";

m_model.AreaObj.GetProperty(id, ref propertyName);
ISurfaceProperty panelProperty = ReadSurfaceProperty(new List<string>() { propertyName })[0];

FEMesh mesh = new FEMesh() { Property = panelProperty };

//Get out the "Element" ids, i.e. the mesh faces
int nbELem = 0;
string[] elemNames = new string[0];
Expand Down Expand Up @@ -121,35 +117,50 @@ private List<FEMesh> ReadMesh(List<string> ids = null)

}

//Set mesh nodes
mesh.Nodes = meshNodeIds.Select(x => nodes[x]).ToList();
//Set mesh nodes - if there are no nodes, don't create the mesh.
if (nodes.Count != 0 && mesh.Faces.Count != 0)
{
mesh.Nodes = meshNodeIds.Select(x => nodes[x]).ToList();

string propertyName = "";

//Get local x-axis
double orientation = 0;
bool advanced = false;
m_model.AreaObj.GetLocalAxes(id, ref orientation, ref advanced);
m_model.AreaObj.GetProperty(id, ref propertyName);

Vector normal = mesh.Faces.First().Normal(mesh); //Assuming flat mesh, all normals equal
Vector localX = Convert.FromCSILocalX(normal, orientation);
mesh = mesh.SetLocalOrientations(localX);
if (propertyName != "None")
{
mesh.Property = surfaceProps[propertyName];
}

//Get local x-axis
double orientation = 0;
bool advanced = false;
m_model.AreaObj.GetLocalAxes(id, ref orientation, ref advanced);

Vector normal = mesh.Faces.First().Normal(mesh); //Assuming flat mesh, all normals equal
Vector localX = Convert.FromCSILocalX(normal, orientation);
mesh = mesh.SetLocalOrientations(localX);

//Label and story
string label = "";
string story = "";
if (m_model.AreaObj.GetLabelFromName(id, ref label, ref story) == 0)
{
etabsid.Label = label;
etabsid.Story = story;
}

// Get guid
string guid = null;
m_model.AreaObj.GetGUID(id, ref guid);
etabsid.PersistentId = guid;

//Label and story
string label = "";
string story = "";
if (m_model.AreaObj.GetLabelFromName(id, ref label, ref story) == 0)
SetAdapterId(mesh, etabsid);
meshes.Add(mesh);
}
else
{
etabsid.Label = label;
etabsid.Story = story;
BH.Engine.Reflection.Compute.RecordWarning("Mesh " + id.ToString() + " could not be pulled, because it contains no nodes");
}

// Get guid
string guid = null;
m_model.AreaObj.GetGUID(id, ref guid);
etabsid.PersistentId = guid;

SetAdapterId(mesh, etabsid);
meshes.Add(mesh);
}

return meshes;
Expand Down

0 comments on commit 359f54e

Please sign in to comment.