Copy hole settings

Copy hole settings

GeorgK
Advisor Advisor
3,401 Views
24 Replies
Message 1 of 25

Copy hole settings

GeorgK
Advisor
Advisor

Hello together,

 

I am searching for a possibility to copy the hole dimensions and open the dialogbox with those settings or to copy the settings and paste it on an existing hole.

 

 

http://forums.autodesk.com/t5/inventor-ideas/copy-hole-properties/idi-p/5655082

 

 

Thanks

 

Georg

0 Likes
3,402 Views
24 Replies
Replies (24)
Message 21 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

Here is an update to the code that resolves the problem when copying hole 13 when the target hole has threads. (hole 40)

 

It also now uses the TargetHole.Extent.Direction instead of the SourceHole.Extent.Direction. Seems to get the correct results.

 

 

Public Sub Modify_Holes_2()
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    Dim SourceHole As Object
    Dim TargetHole As HoleFeature
   
    Dim oHoles As HoleFeatures
    Set oHoles = invDoc.ComponentDefinition.Features.HoleFeatures
    
   '  Set SourceHole = oHoles("Hole11")
    Set SourceHole = oHoles("Hole13")
   ' Set SourceHole = oHoles("Hole40")
    
   For Each TargetHole In oHoles
      ' Debug.Print SourceHole.name
       Debug.Print TargetHole.name
        
        If SourceHole.Tapped = False And TargetHole.Tapped = True Then
             TargetHole.Tapped = False
             TargetHole.HoleDiameter.value = SourceHole.HoleDiameter.value
        End If
                    
        If SourceHole.HoleType = kCounterBoreHole Then Call TargetHole.SetCBore(SourceHole.CBoreDiameter.value, SourceHole.CBoreDepth.value)
        If SourceHole.HoleType = kCounterSinkHole Then Call TargetHole.SetCSink(SourceHole.CSinkDiameter.value, SourceHole.CSinkAngle.value)
        If SourceHole.HoleType = kSpotFaceHole Then Call TargetHole.SetSpotFace(SourceHole.SpotFaceDiameter.value, SourceHole.SpotFaceDepth.value)
        If SourceHole.HoleType = kDrilledHole Then Call TargetHole.SetDrilled
        'If SourceHole.ExtentType = kThroughAllExtent Then Call TargetHole.SetThroughAllExtent(SourceHole.Extent.Direction)
        If SourceHole.ExtentType = kThroughAllExtent Then Call TargetHole.SetThroughAllExtent(TargetHole.Extent.Direction)

        If SourceHole.ExtentType = kDistanceExtent Then
            If SourceHole.FlatBottom = True Then
                'Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.value, SourceHole.Extent.Direction, True)
                Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.value, TargetHole.Extent.Direction, True)
            Else
                'Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.value, SourceHole.Extent.Direction, False, SourceHole.BottomTipAngle.value)
                Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.value, TargetHole.Extent.Direction, False, SourceHole.BottomTipAngle.value)
            End If
        End If
        
        If SourceHole.ExtentType = kToExtent Then
            Call TargetHole.SetEndOfPart(True)
            Call TargetHole.SetToFaceExtent(SourceHole.Extent.ToEntity.Item(1), SourceHole.Extent.ExtendToFace)
            Call invDoc.ComponentDefinition.SetEndOfPartToTopOrBottom(False)
        End If
        
        If SourceHole.Tapped = True Then
            If SourceHole.TapInfo.FullTapDepth = True Then
                TargetHole.TapInfo = invDoc.ComponentDefinition.Features.HoleFeatures.CreateTapInfo(SourceHole.TapInfo.RightHanded, SourceHole.TapInfo.ThreadType, SourceHole.TapInfo.ThreadDesignation, SourceHole.TapInfo.Class, True)
            Else
                TargetHole.TapInfo = invDoc.ComponentDefinition.Features.HoleFeatures.CreateTapInfo(SourceHole.TapInfo.RightHanded, SourceHole.TapInfo.ThreadType, SourceHole.TapInfo.ThreadDesignation, SourceHole.TapInfo.Class, False, SourceHole.TapInfo.ThreadDepth.value)
            End If
        End If
        
        invDoc.Update
    Next

End Sub

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 22 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

your code works in about 80% of the holes. I have to investigate it.

 

Thanks for your help.

 

Georg

0 Likes
Message 23 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

I could not reproduce the error in every hole type. The best way is to replace the hole by a new one. This process is very stable.

 

Georg

0 Likes
Message 24 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

 

you wrote:

It seems that if the reference lines are not set for a hole then changing the hole using the API can fail. Below is a screenshot to help explain. Try adding the reference edges to the holes and then running the CopyHoleSettings() code provided by bshbsh in a previous post. In my tests holes without the reference edges will fail but if I add the reference edges the code changes the hole without error.

 

 

Is there any workaround to modify the holes when the reference one / two or both are missing?

 

Is this a bug in the API?

 

Georg

0 Likes
Message 25 of 25

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi George,

 

Hoping that, workaround is given in the following forum discussion.

 

https://forums.autodesk.com/t5/inventor-customization/setthroughallextent-hole-klinearplacementtype/...

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes