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: 

Make holefeature based on sketchline and offset

1 REPLY 1
Reply
Message 1 of 2
juliengoertz
104 Views, 1 Reply

Make holefeature based on sketchline and offset

Hello,

 

I made some code to create a rectangular pattern based on the directions of sketchlines. Now i would like to create the hole that needs to be used in the pattern based on the same lines. So ideally i would create a point based on the sketchlines + offset which i then use to make a hole, which i then use to create the pattern. But i can't find any inspiration to do this. Is there anyone that could help me a bit?
The situation is as follows. The green lines in the following screenshot is my selectionset, from which i can get the sketchlines. The placed point is where i would like to have my point which i can use to make a hole. Which i would like to be placed automatically: 

juliengoertz_0-1717581173611.png

 

Thanks in advance!

1 REPLY 1
Message 2 of 2
A.Acheson
in reply to: juliengoertz

Hi @juliengoertz 

If i am doing any of this part automation I generally like to go into the API samples and check if there is anything that fits the bill. In this case I search part and hole feature sample. You can pick what you need from the sample when you convert to VB.NET ...

Below is the VBA code.

Public Sub HoleSample()
    ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                 ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
                    
    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
    
    ' Create a new sketch on the X-Y work plane.
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))

    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry
    
    ' Create a rectangle on the sketch.
    Call oSketch.SketchLines.AddAsTwoPointRectangle( _
                                        oTransGeom.CreatePoint2d(0, 0), _
                                        oTransGeom.CreatePoint2d(6, 4))
                                        
    ' Create the profile.
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid
    
    ' Create an extrusion.
    Dim oExtrudeDef As ExtrudeDefinition
    Set oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kJoinOperation)
    Call oExtrudeDef.SetDistanceExtent("2 cm", kNegativeExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
    
    ' Create a new sketch to contain the points that define the hole centers.
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))
    
    ' Create an object collection for the hole center points.
    Dim oHoleCenters As ObjectCollection
    Set oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Add two points as hole centers.
    oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(1, 1))
    oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(5, 1))
    
    ' Create the hole feature.
    Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent( _
                            oHoleCenters, "1 cm", kPositiveExtentDirection)

    ' Define tap information.

    Dim oHoleTapInfo As HoleTapInfo
    Set oHoleTapInfo = oCompDef.Features.HoleFeatures.CreateTapInfo( _
                            True, "ANSI Unified Screw Threads", _
                            "7/16-14 UNC", "1B", False, "1 cm")
                            
    ' Create a new sketch for the tapped hole centers.
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3))
    
    ' Create a new object collection for the hole center points.
    Set oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Add two points as hole centers.
    oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(1, 3))
    oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(5, 3))
    
    ' Create the hole feature.
    Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent( _
                            oHoleCenters, oHoleTapInfo, kPositiveExtentDirection)
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report