Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modifying a Cylinder using Inventor API C#

3 REPLIES 3
Reply
Message 1 of 4
lokit.khemka
382 Views, 3 Replies

Modifying a Cylinder using Inventor API C#

lokit.khemka
Participant
Participant

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.

0 Likes

Modifying a Cylinder using Inventor API C#

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.

Tags (1)
3 REPLIES 3
Message 2 of 4

Michael.Navara
Advisor
Advisor

You can't modify surface body directly in this way, but you can use ThickenFeature for this.

0 Likes

You can't modify surface body directly in this way, but you can use ThickenFeature for this.

Message 3 of 4
lokit.khemka
in reply to: lokit.khemka

lokit.khemka
Participant
Participant

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.

0 Likes

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.

Message 4 of 4

Michael.Navara
Advisor
Advisor

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

 

0 Likes

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.

Post to forums  

Autodesk Design & Make Report