Getting Geometry Details
This example shows how the internal information(total number of indices and vertices) of CAD model varies with respect to different level of details.
Creating advanced curves
Get all the parts from station.
Declare typesafe List of Part type variable.
Iterate through all the GraphicComponent element in station's GraphicComponentCollection. If GraphicComponent is of Part Type then add the component in collection of Parts.
Iterate through the collection of parts.
Check the selected level of detail for part element. Based on selected level of detail get the MeshPart Instance.
Declare Int32 type variables to calculate the total no of indices and total no of vertices.
Iterate through the collection of MeshBody.
- Iterate through the collection of MeshFace and calculate the total no of indices and total no of vertices.
Display no of indices and no of vertices for each part.
Solution
Get all the parts from station.
List<Part> partCollection= GetCADFromStation(); MeshPart meshPart = null; DetailLevels partLevelOfDetail = default(DetailLevels);
Declare typesafe List of Part type variable.
List<Part> partCollection = new List<Part>();
Iterate through all the GraphicComponent element in station's GraphicComponentCollection. If GraphicComponent is of Part Type then add the component in collection of Parts.
foreach (GraphicComponent component in station.GraphicComponents) { if (component is Part) { partCollection.Add((Part)component); } }
Iterate through the collection of parts.
foreach (Part part in partCollection)
Check the selected level of detail for part element. Based on selected level of detail get the MeshPart Instance.
if (part.Mesh[DetailLevels.Medium] != null) { //Gives the MeshPart Instance reference for Medium Detail Level meshPart = part.Mesh[DetailLevels.Medium]; //Sets partLevelOfDetail to medium Detail level partLevelOfDetail=DetailLevels.Medium; } else if (part.Mesh[DetailLevels.Coarse] != null) { //Gives the MeshPart Instance reference for Coarse Detail Level meshPart = part.Mesh[DetailLevels.Coarse]; //Sets partLevelOfDetail to Coarse Detail level partLevelOfDetail=DetailLevels.Coarse; } else if (part.Mesh[DetailLevels.Fine] != null) { //Gives the MeshPart Instance reference for Fine Detail Level meshPart = part.Mesh[DetailLevels.Fine]; //Sets partLevelOfDetail to Fine Detail level partLevelOfDetail=DetailLevels.Fine; }
Declare Int32 type variables to calculate the total no of indices and total no of vertices.
//Maintains the total no of indices for each iterated part int totalNoOfIndices=0; //Maintains the total no of vertices for each iterated part int totalNoOfVertices = 0;
Iterate through the collection of MeshBody.
foreach (MeshBody meshBody in meshPart.Bodies)
- Iterate through the collection of MeshFace and calculate the total no of indices and total no of vertices.
foreach (MeshFace meshFace in meshBody.Faces) { totalNoOfIndices += meshFace.TriangleIndices.Count; totalNoOfVertices += meshFace.Vertices.Count; }
- Iterate through the collection of MeshFace and calculate the total no of indices and total no of vertices.
Display no of indices and no of vertices for each part.
//Display no of indices for each part Logger.AddMessage(new LogMessage( String.Format("Total number of Indices for {0} part with {1} Level of details is {2}" , part.Name ,partLevelOfDetail.ToString(),totalNoOfIndices.ToString()) , LogMessageSeverity.Information)); //Display no of vertices for each part Logger.AddMessage(new LogMessage( String.Format("Total number of Vertices for {0} part with {1} Level of details is {2}" , part.Name ,partLevelOfDetail.ToString() ,totalNoOfVertices.ToString()) , LogMessageSeverity.Information));
Example
This function returns type-safe collection of all the Part objects in station.
private static List<Part> GetCADFromStation()
{
List<Part> partCollection = new List<Part>();
Station station = Project.ActiveProject as Station;
foreach (GraphicComponent component in station.GraphicComponents)
{
if (component is Part)
{
partCollection.Add((Part)component);
}
}
return partCollection;
}
This function shows the number of indices and vertices for the imported CAD model with different level of details.
private static void ImportCADreltoLOD()
{
//Get all the parts from station
List<Part> partCollection= GetCADFromStation();
MeshPart meshPart = null;
DetailLevels partLevelOfDetail = default(DetailLevels);
//Iterate through the collection of parts
foreach (Part part in partCollection)
{
//Check the selected level of detail for part element
//Based on selected level of detail get the MeshPart Instance
if (part.Mesh[DetailLevels.Medium] != null)
{
//Gives the MeshPart Instance reference for Medium Detail Level
meshPart = part.Mesh[DetailLevels.Medium];
//Sets partLevelOfDetail to medium Detail level
partLevelOfDetail=DetailLevels.Medium;
}
else if (part.Mesh[DetailLevels.Coarse] != null)
{
//Gives the MeshPart Instance reference for Coarse Detail Level
meshPart = part.Mesh[DetailLevels.Coarse];
//Sets partLevelOfDetail to Coarse Detail level
partLevelOfDetail=DetailLevels.Coarse;
}
else if (part.Mesh[DetailLevels.Fine] != null)
{
//Gives the MeshPart Instance reference for Fine Detail Level
meshPart = part.Mesh[DetailLevels.Fine];
//Sets partLevelOfDetail to Fine Detail level
partLevelOfDetail=DetailLevels.Fine;
}
//Maintains the total no of indices for each iterated part
int totalNoOfIndices=0;
//Maintains the total no of vertices for each iterated part
int totalNoOfVertices = 0;
foreach (MeshBody meshBody in meshPart.Bodies)
{
foreach (MeshFace meshFace in meshBody.Faces)
{
totalNoOfIndices += meshFace.TriangleIndices.Count;
totalNoOfVertices += meshFace.Vertices.Count;
}
}
//Display no of indices for each part
Logger.AddMessage(new LogMessage(
String.Format("Total number of Indices for {0} part with {1} Level of details is {2}" ,
part.Name ,partLevelOfDetail.ToString(),totalNoOfIndices.ToString()) ,
LogMessageSeverity.Information));
//Display no of vertices for each part
Logger.AddMessage(new LogMessage(
String.Format("Total number of Vertices for {0} part with {1} Level of details is {2}" ,
part.Name ,partLevelOfDetail.ToString() ,totalNoOfVertices.ToString()) ,
LogMessageSeverity.Information));
}
}
Required Namespaces
ABB.