ilogic to convert circles to holes

ilogic to convert circles to holes

FProcp
Collaborator Collaborator
4,443 Views
72 Replies
Message 1 of 73

ilogic to convert circles to holes

FProcp
Collaborator
Collaborator

Does anyone know of an iLogic code that can convert circles to holes?

 

We receive plate models from others and the holes are drawn as circles and then extruded as through cuts.

 

I would like to be able to convert all circles in the plate (possibly under a certain diameter) to proper holes.

 

Has anyone done this before?

Franco
GMT +08:00
0 Likes
4,444 Views
72 Replies
Replies (72)
Message 2 of 73

JaneFan
Autodesk
Autodesk

Hello Franc,

 

It is feasible.

Were the Extrusions with cut through the circles created in assembly file, or part files? The solution is different accordingly. But anyway, we can delete the extrusions with keepting the consumed sketches, and then create hole feature based on the retained sketch circles.

Take a part file as example: the file has one simple extrusion block, and the second extrusion is created based on a sketch circle with cut operation, add the following code into iLogic to convert the second extrusion to a hole feature:

 

Dim doc As PartDocument 
doc = ThisDoc.Document

Dim oExtrude As ExtrudeFeature
oExtrude = doc.ComponentDefinition.Features.ExtrudeFeatures(2)
Dim oSk As PlanarSketch 
oSk = oExtrude.Definition.Profile.Parent 

oExtrude.Delete(True)

Dim objCol As ObjectCollection 
objCol = ThisApplication.TransientObjects.CreateObjectCollection 
objCol.Add (oSk.SketchCircles(1).CenterSketchPoint)

Dim oPD As HolePlacementDefinition 
oPD = doc.ComponentDefinition.Features.HoleFeatures.CreateSketchPlacementDefinition(objCol)
Dim oHole As HoleFeature
oHole = doc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD,oSk.SketchCircles(1).Radius*2, partfeatureextentdirectionenum.kSymmetricExtentDirection)

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 73

dgreatice
Collaborator
Collaborator

Hi Jane,

 

Maybe you must ask to, are the sketch is difference or same sketch with base feature.

 

I have 2 difference sample :

1. TestPart1.ipt create from face feature in sheet metal. the result are cut using Cut feature (not extrusion feature)

2. TestPart2.ipt create from Extrude Feature, the result are cut using Extrusion Feature.

 

But I'm using VBA macro, i cant convert this code to iLogic code.

- already delete "set" in illogic code

- I know issue about CommandManager at illogic code.

- already add at top Line "ThisAppilcation.UserInterfaceManager.UserInteractionDisabled = False", but still showing error

Capture.JPG

 

This my example code only run at VBA macro:

 

Public Sub CreateHole()
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    Dim CMDMan As CommandManager
    Set CMDMan = ThisApplication.CommandManager
    Dim oSketch As Sketch
    Set oSketch = CMDMan.Pick(kSketchObjectFilter, "Select Sketch")
    Dim oProjLine As SketchLine
   
        For Each oProjLine In oSketch.SketchLines
            If oProjLine.Reference = True Then
            oProjLine.Construction = True
            End If
        Next
   
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid
   
    If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        Dim oSMCD As SheetMetalComponentDefinition
        Set oSMCD = oPartDoc.ComponentDefinition
        Dim oSMFeat As SheetMetalFeatures
        Set oSMFeat = oSMCD.Features
        Dim oCutDef As CutDefinition
        Set oCutDef = oSMFeat.CutFeatures.CreateCutDefinition(oProfile)
        oCutDef.SetThroughAllExtent (kNegativeExtentDirection)
        Dim oCutFeature As CutFeature
        Set oCutFeature = oSMFeat.CutFeatures.Add(oCutDef)
    Else
        Dim oPCD As PartComponentDefinition
        Set oPCD = oPartDoc.ComponentDefinition
        Dim oFeat As PartFeatures
        Set oFeat = oPCD.Features
        Dim oExtrudeDef As ExtrudeDefinition
        Set oExtrudeDef = oFeat.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
        oExtrudeDef.SetThroughAllExtent kSymmetricExtentDirection
        Dim oExtrude As ExtrudeFeature
        Set oExtrude = oFeat.ExtrudeFeatures.Add(oExtrudeDef)
    End If
End Sub

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 4 of 73

FProcp
Collaborator
Collaborator

We receive dxf files from our clients for plasma/gas cutting.

I open the dxf files with AutoCAD and then copy the profile to Inventor.

In Inventor I extrude the profile to the plate thickness required using the Face command.

All the holes come across from the original dxf as circles.

After the Sheet-Metal part is created, I would like to convert all the circles to true holes.

Thank you so much for your help.

Franco
GMT +08:00
0 Likes
Message 5 of 73

dgreatice
Collaborator
Collaborator

Did you try Code from Jane or me?

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 6 of 73

FProcp
Collaborator
Collaborator

Your solution turned the circles in the sketch to extruded circles. Thanks.

 

But, I want the extruded circles to be converted to true hole features.

They need to become hole feature because I need to change some of the holes to counter-sunk holes.

 

With the hole feature command I can easily do this.

Franco
GMT +08:00
0 Likes
Message 7 of 73

dgreatice
Collaborator
Collaborator

Did you know valid size of each hole? or all hole are same size for each circle size?

size of circle doesn't same with hole size. You must choose size and type of holes for your design.

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 8 of 73

JaneFan
Autodesk
Autodesk

So please try with my code to convert the extrude feature a hole features, just modifying the code according to your requirement or logic, or use HoleFeatures.AddCSinkByThroughAllExtent() method according to your need. 

To check more about the arguments in this method, Just navigate to VBA environment of Inventor, click Object browser to see the objects and methods/properties details, or navigating to API help documentation in this way: 

 

Help1.jpg




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 9 of 73

FProcp
Collaborator
Collaborator

The holes are to be the same size as each circle size.

 

Sometimes the dxf file sent to us may show circles for the counter-sink in the same place as the hole.

 

I normally remove the holes representing countersinking when it is open in AutoCAD (I usually change them to a different layer and then turn it off).

 

It would be nice if the code could turn double circles (on the same centre) to counter-sunk holes Smiley Wink

 

Holes_in_dxf.jpg

Franco
GMT +08:00
0 Likes
Message 10 of 73

FProcp
Collaborator
Collaborator

Thanks Jane,

 

Can you please post a sample part file with the code.

I am having trouble getting your solution to work.

Franco
GMT +08:00
0 Likes
Message 11 of 73

JaneFan
Autodesk
Autodesk

Hey Franc, 

 

It would be helpful to provide your inventor model and what you want to achieve so that we can help you more efficiently. 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 12 of 73

FProcp
Collaborator
Collaborator

I have attached a sample plate model.

I would like all circles that are less that Ø50mm to be converted to holes.

Franco
GMT +08:00
0 Likes
Message 13 of 73

JaneFan
Autodesk
Autodesk

Hi Franc, 

 

with the model you attached, I wrote following code to meet the requirement, and please adjust the code for your further need. 

Before running the code, please delete the face feature you create manually, use the code to create face feature.

With running the code: 

SeparateHole.png

Dim oDoc As PartDocument
oDoc = ThisDoc.Document
Dim oSK As PlanarSketch
oSK = oDoc.ComponentDefinition.Sketches(1)
Dim objCol As ObjectCollection
objCol = ThisApplication.TransientObjects.CreateObjectCollection

'Store the large circles whose diameter are larger then 50mm
Dim oLarCircles As ObjectCollection
oLarCircles = ThisApplication.TransientObjects.CreateObjectCollection

For Each oskarc In oSK.SketchArcs
    objCol.Add(oskarc)
Next
For Each oskline In oSK.SketchLines
    objCol.Add (oskline)
Next

Dim oCircleCol(2) As ObjectCollection
For i = 0 To 2
    oCircleCol(i) = ThisApplication.TransientObjects.CreateObjectCollection
Next

Dim oCircle As SketchCircle
For Each oCircle In oSK.SketchCircles
'Please modify the radius value according to your need
    If oCircle.Radius > 2.5 Then
       oLarCircles.Add( oCircle)
    Else
        If Abs(oCircle.Radius - 0.7) < 0.001 Then
            oCircleCol(0).Add(oCircle)
        ElseIf Abs(oCircle.Radius - 0.9) < 0.001 Then
            oCircleCol(1).Add (oCircle)
        ElseIf Abs(oCircle.Radius - 1.4) < 0.001 Then
            oCircleCol(2).Add (oCircle)
        End If
    End If
Next

 Dim oP1 As Profile
 oP1 = oSK.Profiles.AddForSolid(False, objCol)
 Dim oD1 As FaceFeatureDefinition
 oD1 = oDoc.ComponentDefinition.Features.FaceFeatures.CreateFaceFeatureDefinition(oP1)
 'Create first face feature including the whole block
 Dim oF1 As FaceFeature
 oF1 = oDoc.ComponentDefinition.Features.FaceFeatures.Add(oD1)

'Cut the large circles with Extrusion 
oSK.Shared = True
Dim oP2 As Profile
oP2 = oSK.Profiles.AddForSolid(False, oLarCircles)
oD2 = oDoc.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(oP2, kCutOperation)
oF2 = oDoc.ComponentDefinition.Features.ExtrudeFeatures.Add(oD2)

'Create hole feature for the rest center point of the circles
Dim oTempCol As ObjectCollection
oTempCol = ThisApplication.TransientObjects.CreateObjectCollection
Dim oPD As HolePlacementDefinition
For i = 0 To 2
    oTempCol.Clear
    Dim dDiameter As Double
    For Each oCircle In oCircleCol(i)
        oTempCol.Add (oCircle.CenterSketchPoint)
     Next
     dDiameter = oCircleCol(i).Item(1).Radius * 2
     oPD = oDoc.ComponentDefinition.Features.HoleFeatures.CreateSketchPlacementDefinition(oTempCol)
    Call oDoc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD, dDiameter, kSymmetricExtentDirection)
Next

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 14 of 73

FProcp
Collaborator
Collaborator

Thank you so much Jane.

This looks excellent Smiley Surprised

Franco
GMT +08:00
0 Likes
Message 15 of 73

dgreatice
Collaborator
Collaborator

No Counter Sink Hole?

 

hmm...

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 16 of 73

FProcp
Collaborator
Collaborator
The example I sent does not have counter-sunk holes.

But I am so amazed with what Jane has done.

It would be amazing if it could recognise counter sunk holes. Let us see what is possible.
Franco
GMT +08:00
0 Likes
Message 17 of 73

FProcp
Collaborator
Collaborator

Why is it that if I delete the face feature, then go into the block (with-in the sketch) to add some extra holes and then re-run your code, the new holes are ignored?

 

I also tried to add some other cut-outs, such as slots and rectangles in the sketch, and they were ignored too?

I also tried to add some double holes to represent counter-sink holes, but nothing happened!

 

Will this code only work for the original dxf copied in and nothing else?

I don't mind if this is the case because I normally don't edit the dxf profile after it is in Inventor, but I was just wondering?

Franco
GMT +08:00
0 Likes
Message 18 of 73

FProcp
Collaborator
Collaborator

I tried creating a new file and importing a different dxf profile but it did NOT work.

What is happening to me?

Franco
GMT +08:00
0 Likes
Message 19 of 73

FProcp
Collaborator
Collaborator

I did another trial test this morning and it worked OK (except for the counter-sunk holes).

I think I need to try to understand this ilogic code better so I will know what it is doing.

Franco
GMT +08:00
0 Likes
Message 20 of 73

JaneFan
Autodesk
Autodesk

Yes, it would be helpful to understand the logic in the code and adjust it as different need accordingly. 🙂 Good luck!




Jane Fan
Inventor/Fusion QA Engineer
0 Likes