Copy hole settings

Copy hole settings

GeorgK
Advisor Advisor
3,359 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,360 Views
24 Replies
Replies (24)
Message 2 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

I don't have a solution for populating the fields in the default Hole Dialog.

 

You should be able to use the API to get properties of one hole feature and set the same values on a different hole feature.

 

Is your requirement to include user interaction and the use of the clip board? Maybe a solution would be to get the values and then present the user with a custom dialog.

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

the idea was to give the user the possibility to copy the hole settings and paste them to an other hole or to have a new dialog with the settings open to change the values.

 

Georg

0 Likes
Message 4 of 25

bshbsh
Collaborator
Collaborator

This "copies" hole parameters from a source hole to multiple target holes:

Public Sub CopyHoleSettings()
    Dim InvDoc As Document
    Set InvDoc = ThisApplication.ActiveEditDocument
    Dim SourceHole As Object
    Dim TargetHole As Object
    Dim More As Boolean
    Set SourceHole = ThisApplication.CommandManager.Pick(kPartFeatureFilter, "Select SOURCE hole! (ESC to abort)")
    If (Not SourceHole Is Nothing) Then
        If SourceHole.Type = kHoleFeatureObject Then
            Set TargetHole = Nothing
            More = True
            Do Until More = False
                Set TargetHole = ThisApplication.CommandManager.Pick(kPartFeatureFilter, "Select TARGET hole! (ESC to abort)")
                If (Not TargetHole Is Nothing) Then
                    If TargetHole.Type = kHoleFeatureObject Then
                        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 = kDistanceExtent Then
                            If SourceHole.FlatBottom = True Then
                                Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.Value, SourceHole.Extent.Direction, True)
                            Else
                                Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.Value, SourceHole.Extent.Direction, Fales, 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
                            TargetHole.Tapped = True
                        Else
                            TargetHole.Tapped = False
                            TargetHole.HoleDiameter.Value = SourceHole.HoleDiameter.Value
                        End If
                        InvDoc.Update
                    End If
                Else
                    More = False
                End If
            Loop
        End If
    End If
End Sub

Needs a little more error checking and stuff. Also, ToFace extent holes may or may not work, depending on where the target hole is in relation to the ToFace. G-Threads won't work either since they don't have a Class. (Autodesk should really fix this.)

0 Likes
Message 5 of 25

GeorgK
Advisor
Advisor

@bshbsh This is very promising code to start with.

 

@wayne.brill How could I fix the problem with G-Threads?

 

Thank you very much.

0 Likes
Message 6 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

I am not sure what is being asked for related to G-Threads.

 

Do you have a part file that has holes that have these types of threads and there is not a way to access them or something about them from the API? If so please upload the Inventor file I can use research.

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 25

GeorgK
Advisor
Advisor

Hello,

 

@bshbsh: I tried the code but I get the following error:

 

Run-time error 5 - Invalid procedure call or argument.

 

Call TargetHole.SetToFaceExtent(SourceHole.Extent.ToEntity.Item(1), SourceHole.Extent.ExtendToFace)

 

Thank you Georg

0 Likes
Message 8 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

It may help to understand why the error occurs by debugging and finding what these objects are:

 SourceHole.Extent.ToEntity.Item(1) and  SourceHole.Extent.ExtendToFace

 

I could research this. Can you upload an assembly that is getting the Invalid procedure call when the code is run? If you have modified code different from what bshbsh provided on this thread please provide your modified code too.

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 9 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

attached is a plate where I get the error.

 

Thank you

 

Georg

0 Likes
Message 10 of 25

bshbsh
Collaborator
Collaborator

I can't open your file, I'm still on IV2014.

ToFace Extents are difficult to handle and my code didn't even try to do it. See my comment below the code: "Also, ToFace extent holes may or may not work, depending on where the target hole is in relation to the ToFace."

Let's say your source hole is on the top side of a plate and drilled with extent to the bottom face of the plate. Say, you try to copy the hole parameters to a hole that is drilled into the bottom face, with extent to the top face. This copy will fail, since my simple and dumb code would try to apply the same extent (aka bottom face) to the bottom hole, which would result in an invalid extent and a 0 depth hole. Similarly, if you try to copy an "extent hole" to another hole that is say perpendicular to the extent of the source, it will be invalid. Or if the extent is further down the model tree then the target hole - it will fail too, since the extent object doesn't exist at that point in the model tree.

 

Also there's some typos and mistakes in my code: "Fales" is obviously "False", and the two lines with "TargetHole.Tapped=" have to be removed.

0 Likes
Message 11 of 25

GeorgK
Advisor
Advisor

Hello bshbsh,

 

I did the modification. But I could not get it to run. Is it possible to get the extend for the different types?

 

It works only for a simple hole.

 

Georg

0 Likes
Message 12 of 25

GeorgK
Advisor
Advisor

Maybe it is better to replace the hole with a new one.....

 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button65.Click
Dim m_inventorApp As Inventor.Application = Nothing

' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
MsgBox(ex.Message)
End Try


' Create a transaction.
Dim oTransMgr As TransactionManager
oTransMgr = m_inventorApp.TransactionManager
Dim oTrans As Transaction
oTrans = oTransMgr.StartTransaction(m_inventorApp.ActiveDocument, "Replace hole")

Dim oSketch As PlanarSketch = Nothing
Dim oDoc As PartDocument
oDoc = m_inventorApp.ActiveDocument

' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oHoles As HoleFeatures
oHoles = oDoc.ComponentDefinition.Features.HoleFeatures
Dim oHole As HoleFeature

For Each oHole In oHoles

oDoc.SelectSet.Clear()
oDoc.SelectSet.Select(oHole)

Dim oHoleCenter As Point
Dim oSketchPoint As SketchPoint

Dim oCollection As ObjectCollection
oCollection = m_inventorApp.TransientObjects.CreateObjectCollection

If TypeOf oHole.HoleCenterPoints.Item(1) Is SketchPoint Then
' Get the sketch point.
oSketchPoint = oHole.HoleCenterPoints.Item(1)

' Get the position of the sketch point in model space.
oSketch = oSketchPoint.Parent
oHoleCenter = oSketch.SketchToModelSpace(oSketchPoint.Geometry)


'Dim oSketchpoint As SketchPoint
For Each oSketchPoint In oHole.Sketch.SketchPoints
If oSketchPoint.HoleCenter Then
Call oCollection.Add(oSketchPoint)
End If
Next

'Löschen
oHole.Delete(True)
Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oCollection, "10 mm", PartFeatureExtentDirectionEnum.kPositiveExtentDirection)

oDoc.Update()
Else

oHoleCenter = oHole.HoleCenterPoints.Item(1)
MsgBox(oHoleCenter.X & "; " & oHoleCenter.Y & "; " & oHoleCenter.Z)

' How to replace the hole without sketch?

End If

Next

oTrans.End()
End Sub




How could I replace the holes without sketch?

 

It should be possible to replace each hole-type with another hole-type.

0 Likes
Message 13 of 25

GeorgK
Advisor
Advisor

@wayne.brillDid you found a solution for the problem?

0 Likes
Message 14 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

I am finding that replacing a hole can be problematic. I started with your example that uses AddDrilledByThroughAllExtent() and the ipt file attached to a previous post in this thread.

 

I have made edits that create a new PointHolePlacementDefinition with HoleFeatures.CreatePointPlacementDefinition() so that it can create holes with values from holes that use a Point or WorkPoint. (I believe this is what you meant by "How could I replace the holes without sketch?" 

 

My code creates new HoleFeatures but the newly created HoleFeatures created by AddDrilledByThroughAllExtent()  have a health of "kDriverLostHealth" - 11780 - Object is driven by data from other Object(s), and one or more of them have been disconnected

 

Is this the problem you are getting?

 

Thanks,

Wayne

 

 

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 15 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

with the code from @bshbsh

Public Sub CopyHoleSettings()
.....



and the code of mine I get the error to loose the health. The holes could not be replaced in every position. Is there any fix to solve the problem?

Is it possible to replace it directly or to delete the hole, save the position and place a new hole at the same place?

 

This error occurs also when I modify the hole to SetThroughAllExtent. I could read the PartFeatureExtentDirectionEnum and set it to the new hole or the same hole.

 

 

Same problem in this solution:

Public Sub ModifY_Hole()
        Dim m_inventorApp As Inventor.Application = Nothing

        ' Try to get an active instance of Inventor
        Try
            m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


        ' Create a transaction.
        Dim oTransMgr As TransactionManager
        oTransMgr = m_inventorApp.TransactionManager
        Dim oTrans As Transaction
        oTrans = oTransMgr.StartTransaction(m_inventorApp.ActiveDocument, "Replace hole")

        Dim oSketch As PlanarSketch = Nothing
        Dim oDoc As PartDocument
        oDoc = m_inventorApp.ActiveDocument

        ' Set a reference to the component definition.
        Dim oCompDef As PartComponentDefinition
        oCompDef = oDoc.ComponentDefinition

        Dim oCollection As ObjectCollection
        oCollection = m_inventorApp.TransientObjects.CreateObjectCollection

        Dim ohole As HoleFeature
        ohole = m_inventorApp.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select hole feature")

        ohole.SetCBore("10 mm", "2.5 mm")

        oTrans.End()
    End Sub



It should be possible to copy the settings from one hole to another hole - in part or assembly environment.

Thanks

Georg

0 Likes
Message 16 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

I would suggest not deleting the holes but modifying them instead.

 

I would like to comment on this statement from one of your previous posts:

>> >>
I tried the code but I get the following error:
Run-time error 5 - Invalid procedure call or argument.
Call TargetHole.SetToFaceExtent(SourceHole.Extent.ToEntity.Item(1), SourceHole.Extent.ExtendToFace)
<< <<


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.

 

Hole_Edge_Reference_WB.jpg

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 17 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

is it possible that you share your code, which works with the reference lines?

 

Thank you

 

Georg

0 Likes
Message 18 of 25

wayne.brill
Collaborator
Collaborator

Hi Georg,

 

Here is the code I used with an update to the ipt you provided previously. (attached) 

 

This VBA code gets through all of the holes in the updated ipt without error. Not sure if it is doing everything you want however.  (the code is an update from the code provided by bshbsh)

 

Public Sub Modify_Holes()
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    Dim SourceHole As Object
    Dim TargetHole As HoleFeature 'Object
   ' Dim More As Boolean
    'Set SourceHole = ThisApplication.CommandManager.Pick(kPartFeatureFilter, "Select SOURCE hole! (ESC to abort)")
    
    Dim oHoles As HoleFeatures
    Set oHoles = invDoc.ComponentDefinition.Features.HoleFeatures
    
    Set SourceHole = oHoles("Hole11")
    
   If (Not SourceHole Is Nothing) Then
   If SourceHole.Type = kHoleFeatureObject Then
   
   For Each TargetHole In oHoles
          ' Debug.Print SourceHole.name
           Debug.Print TargetHole.name
           ' Set TargetHole = Nothing
           ' More = True
           ' Do Until More = False
                'Set TargetHole = ThisApplication.CommandManager.Pick(kPartFeatureFilter, "Select TARGET hole! (ESC to abort)")
                'If (Not TargetHole Is Nothing) Then
               ' If SourceHole.name <> TargetHole.name Then
                    If TargetHole.Type = kHoleFeatureObject Then
                        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 = kDistanceExtent Then
                            If SourceHole.FlatBottom = True Then
                                Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.value, SourceHole.Extent.Direction, True)
                            Else
                                Call TargetHole.SetDistanceExtent(SourceHole.Extent.Distance.value, SourceHole.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
                            TargetHole.Tapped = True
                        Else
                            TargetHole.Tapped = False
                            TargetHole.HoleDiameter.value = SourceHole.HoleDiameter.value
                        End If
                        
                        invDoc.Update
                    End If
'                Else
'                    More = False
                'End If
           ' Loop
        Next
        End If
    End If
End Sub

 

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 19 of 25

GeorgK
Advisor
Advisor

Hello Wayne,

 

thank you very much for the update. Thats nearly the solution. The problem is that if I use Hole33 the direction is not correct for every hole. Is there a workaround to get the right direction?

 

Bohrung9.jpg

 

Thanks

 

Georg

0 Likes
Message 20 of 25

GeorgK
Advisor
Advisor

I get another error with hole13. If the targethole has a thread then the code does not work.

0 Likes