I have the following code for obtaining the cylindrical faces in the open geometry. I want to modify the radius of the cylinder. How should I proceed with this?
public static void HoleList(Inventor.Application mApplication)
{
PartDocument doc = (PartDocument)mApplication.ActiveDocument;
PartComponentDefinition PartCompDef = doc.ComponentDefinition;
SurfaceBody body = PartCompDef.SurfaceBodies[1];
int holeCount = 0;
int count = body.Faces.Count;
foreach (Face face in body.Faces)
{
if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
{
holeCount++;
Cylinder cylinder = (Cylinder)face.Geometry;
double ddepth = 0.0;
if (cylinder.AxisVector.Z == 1 || cylinder.AxisVector.Z == -1)
{
ddepth = System.Math.Abs(System.Math.Abs(face.Vertices[1].Point.Z) - System.Math.Abs(face.Vertices[2].Point.Z)) * 10;
}
else if (cylinder.AxisVector.Y == 1)
{
ddepth = System.Math.Abs(System.Math.Abs(face.Vertices[1].Point.Y) - System.Math.Abs(face.Vertices[2].Point.Y)) * 10;
}
else if (cylinder.AxisVector.X == 1)
{
ddepth = System.Math.Abs(System.Math.Abs(face.Vertices[1].Point.X) - System.Math.Abs(face.Vertices[2].Point.X)) * 10;
}
double diameter = 2 * cylinder.Radius;
Console.WriteLine("Diameter: " + cylinder.Radius * 2 * 10 + " mm" + "\t" + "Depth: " + ddepth + " mm");
foreach(Edge edge in face.Edges)
{
Console.WriteLine(edge.StartVertex.Point.X + " " + edge.StartVertex.Point.Y + " " + edge.StartVertex.Point.Z);
Console.WriteLine(edge.StopVertex.Point.X + " " + edge.StopVertex.Point.Y + " " + edge.StopVertex.Point.Z);
}
}
}
}
}
Any help will be greatly appreciated. Thank you.
I have the following code for obtaining the cylindrical faces in the open geometry. I want to modify the radius of the cylinder. How should I proceed with this?
public static void HoleList(Inventor.Application mApplication)
{
PartDocument doc = (PartDocument)mApplication.ActiveDocument;
PartComponentDefinition PartCompDef = doc.ComponentDefinition;
SurfaceBody body = PartCompDef.SurfaceBodies[1];
int holeCount = 0;
int count = body.Faces.Count;
foreach (Face face in body.Faces)
{
if (face.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
{
holeCount++;
Cylinder cylinder = (Cylinder)face.Geometry;
double ddepth = 0.0;
if (cylinder.AxisVector.Z == 1 || cylinder.AxisVector.Z == -1)
{
ddepth = System.Math.Abs(System.Math.Abs(face.Vertices[1].Point.Z) - System.Math.Abs(face.Vertices[2].Point.Z)) * 10;
}
else if (cylinder.AxisVector.Y == 1)
{
ddepth = System.Math.Abs(System.Math.Abs(face.Vertices[1].Point.Y) - System.Math.Abs(face.Vertices[2].Point.Y)) * 10;
}
else if (cylinder.AxisVector.X == 1)
{
ddepth = System.Math.Abs(System.Math.Abs(face.Vertices[1].Point.X) - System.Math.Abs(face.Vertices[2].Point.X)) * 10;
}
double diameter = 2 * cylinder.Radius;
Console.WriteLine("Diameter: " + cylinder.Radius * 2 * 10 + " mm" + "\t" + "Depth: " + ddepth + " mm");
foreach(Edge edge in face.Edges)
{
Console.WriteLine(edge.StartVertex.Point.X + " " + edge.StartVertex.Point.Y + " " + edge.StartVertex.Point.Z);
Console.WriteLine(edge.StopVertex.Point.X + " " + edge.StopVertex.Point.Y + " " + edge.StopVertex.Point.Z);
}
}
}
}
}
Any help will be greatly appreciated. Thank you.
You can't modify surface body directly in this way, but you can use ThickenFeature for this.
You can't modify surface body directly in this way, but you can use ThickenFeature for this.
Hi. Can you provide a simple code example for this? I am new to this and I am unable to get ThickenFeature to work with the code.
Hi. Can you provide a simple code example for this? I am new to this and I am unable to get ThickenFeature to work with the code.
This is simple iLogic sample how to create ThicknessFeature from all cylindrical faces
Sub Main()
Dim part As PartDocument = ThisDoc.Document
Dim partDef As PartComponentDefinition = part.ComponentDefinition
'Iterate all faces in first surface body
For Each face As Face In partDef.SurfaceBodies(1).Faces
'Check if face is cylindrical face
Dim cylinder As Cylinder = TryCast(face.Geometry, Cylinder)
If cylinder Is Nothing Then Continue For
'Get radius for future use. Not used yet
Dim radius As Double = cylinder.Radius
'Build face collection for each face
Dim faceCollection As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection()
faceCollection.Add(face)
'Set offset/thickness distance. It can depend on current radius
Dim distance As Double = 0.1 ' 1 mm
'Create thickness feature
Dim thicknessFeature = partDef.Features.ThickenFeatures.Add(
faceCollection,
distance,
PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
PartFeatureOperationEnum.kJoinOperation,
False)
Next
End Sub
This is simple iLogic sample how to create ThicknessFeature from all cylindrical faces
Sub Main()
Dim part As PartDocument = ThisDoc.Document
Dim partDef As PartComponentDefinition = part.ComponentDefinition
'Iterate all faces in first surface body
For Each face As Face In partDef.SurfaceBodies(1).Faces
'Check if face is cylindrical face
Dim cylinder As Cylinder = TryCast(face.Geometry, Cylinder)
If cylinder Is Nothing Then Continue For
'Get radius for future use. Not used yet
Dim radius As Double = cylinder.Radius
'Build face collection for each face
Dim faceCollection As FaceCollection = ThisApplication.TransientObjects.CreateFaceCollection()
faceCollection.Add(face)
'Set offset/thickness distance. It can depend on current radius
Dim distance As Double = 0.1 ' 1 mm
'Create thickness feature
Dim thicknessFeature = partDef.Features.ThickenFeatures.Add(
faceCollection,
distance,
PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
PartFeatureOperationEnum.kJoinOperation,
False)
Next
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.