ilogic to convert circles to holes

ilogic to convert circles to holes

FProcp
Collaborator Collaborator
4,451 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,452 Views
72 Replies
Replies (72)
Message 21 of 73

FProcp
Collaborator
Collaborator

This routine (by Jane) often seems to fail.

Could somebody please tell me why it doesn't always work?

It works sometimes and not other times.

 

Circ_2_hole_01.jpg

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

GeorgK
Advisor
Advisor

Great program. Is it possible to add countersunk holes?

0 Likes
Message 23 of 73

FProcp
Collaborator
Collaborator

Unfortunately No.

Not countersunk holes Smiley Sad

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

Anonymous
Not applicable

Trying to run janes first code...I get an error on the last line... the actual hole creation..

 

oHole = doc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD,oSk.SketchCircles(1).Radius*2, partfeatureextentdirectionenum.kSymmetricExtentDirection)

anyone else have this issue?

 

cheers

 

0 Likes
Message 25 of 73

FProcp
Collaborator
Collaborator

The sample file that I sent Jane has Ø14 holes, Ø18 holes and Ø28 holes.

I think Janes program will only work with plate that contains only those three hole sizes.

Am I right Jane?

We need to change it to work with all hole sizes within a certain range.

 

Ilogii.JPG

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

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @FProcp,

 

Try the following iLogic code for all hole sizes.

 

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 oRadiusList As ArrayList = New ArrayList 
Dim oCircle As SketchCircle
For Each oCircle In oSK.SketchCircles	
	If oRadiusList.Contains(Math.Round(oCircle.Radius, 3)) = False Then		
		oRadiusList.Add(Math.Round(oCircle.Radius, 3))
	End If	
Next

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

For j = 0 To oRadiusList.Count - 1
	For Each oCircle In oSK.SketchCircles 
		If Math.Round(oCircle.Radius, 3).ToString = oRadiusList.Item(j).ToString Then
			oCircleCol(j).Add(oCircle)
		End If
	Next
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)

'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 oRadiusList.Count - 1
    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

Please feel free to contact if there is any queries,

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 27 of 73

FProcp
Collaborator
Collaborator
Thanks, I will try soon.
Franco
GMT +08:00
0 Likes
Message 28 of 73

FProcp
Collaborator
Collaborator

The testing I've done so far has been great. It works every time.

Will test some more tomorrow.

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

Anonymous
Not applicable

Chandra,

 

how easy is it to modify this for non sheet metal parts?

 

 

0 Likes
Message 30 of 73

FProcp
Collaborator
Collaborator

My requirement is for sheet metal and I couldn't think of an application where it would be useful outside of sheet metal.

I think it should work fine though.

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

FProcp
Collaborator
Collaborator

How difficult would it be to place the hole diameter in the name of the hole feature to one decimal place?

For example re-name the Ø14.3 hole to "HoleD14.3".

 

Part_Holes.jpg

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

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @FProcp,

 

Try the following iLogic code to rename hole feature.

 

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 oRadiusList As ArrayList = New ArrayList 
Dim oCircle As SketchCircle
For Each oCircle In oSK.SketchCircles	
	If oRadiusList.Contains(Math.Round(oCircle.Radius, 3)) = False Then		
		oRadiusList.Add(Math.Round(oCircle.Radius, 3))
	End If	
Next

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

For j = 0 To oRadiusList.Count - 1
	For Each oCircle In oSK.SketchCircles 
		If Math.Round(oCircle.Radius, 3).ToString = oRadiusList.Item(j).ToString Then
			oCircleCol(j).Add(oCircle)
		End If
	Next
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)

'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 oRadiusList.Count - 1
    oTempCol.Clear
    Dim dDiameter As Double
    For Each oCircle In oCircleCol(i)
        oTempCol.Add (oCircle.CenterSketchPoint)
    Next
	
    dDiameter = oCircleCol(i).Item(1).Radius * 2
	dDiameter = Math.Round(dDiameter, 2)
    oPD = oDoc.ComponentDefinition.Features.HoleFeatures.CreateSketchPlacementDefinition(oTempCol)
    Dim oHole As HoleFeature
	oHole = oDoc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD, dDiameter, kSymmetricExtentDirection)		
	oHole.Name = "HoleD" + dDiameter.ToString
Next

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 33 of 73

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

Can you please provide sample non sheet metal parts? I will do feasibility study.

 

Please makes sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 34 of 73

FProcp
Collaborator
Collaborator

This works great.

But, the feature name is slightly wrong as the number needs to be multiplied by x10.

For example the feature "HoleD1.8" should be "Hole18" because it's a Ø18 hole.

Besides that it is excellent.

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

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @FProcp,

 

Try this now.

 

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 oRadiusList As ArrayList = New ArrayList 
Dim oCircle As SketchCircle
For Each oCircle In oSK.SketchCircles	
	If oRadiusList.Contains(Math.Round(oCircle.Radius, 3)) = False Then		
		oRadiusList.Add(Math.Round(oCircle.Radius, 3))
	End If	
Next

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

For j = 0 To oRadiusList.Count - 1
	For Each oCircle In oSK.SketchCircles 
		If Math.Round(oCircle.Radius, 3).ToString = oRadiusList.Item(j).ToString Then
			oCircleCol(j).Add(oCircle)
		End If
	Next
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)

'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 oRadiusList.Count - 1
    oTempCol.Clear
    Dim dDiameter As Double
    For Each oCircle In oCircleCol(i)
        oTempCol.Add (oCircle.CenterSketchPoint)
    Next
	
    dDiameter = oCircleCol(i).Item(1).Radius * 2
	dDiameter = Math.Round(dDiameter, 2)
    oPD = oDoc.ComponentDefinition.Features.HoleFeatures.CreateSketchPlacementDefinition(oTempCol)
    Dim oHole As HoleFeature
	oHole = oDoc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD, dDiameter, kSymmetricExtentDirection)		
	dDiameter = dDiameter * 10
oHole.Name = "HoleD" + dDiameter.ToString Next

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 36 of 73

FProcp
Collaborator
Collaborator

That is excellent but could we please show one decimal place?

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

FProcp
Collaborator
Collaborator

I have attached a part file with just a sketch in it ready for processing.

 

Is this OK?

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

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @FProcp,

 

Try the following iLogic code for PartDocument.

 

 

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

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

Dim oRadiusList As ArrayList = New ArrayList 
Dim oCircle As SketchCircle
For Each oCircle In oSK.SketchCircles	
	If oRadiusList.Contains(Math.Round(oCircle.Radius, 3)) = False Then		
		oRadiusList.Add(Math.Round(oCircle.Radius, 3))
	End If	
Next

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

For j = 0 To oRadiusList.Count - 1
	For Each oCircle In oSK.SketchCircles 
		If Math.Round(oCircle.Radius, 3).ToString = oRadiusList.Item(j).ToString Then
			oCircleCol(j).Add(oCircle)
		End If
	Next
Next 

Dim oP1 As Profile
oP1 = oSK.Profiles.AddForSolid(False, objCol)
oD1 = oDoc.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(oP1, kNewBodyOperation)
oD1.SetDistanceExtent("6 mm", kSymmetricExtentDirection)
oF2 = oDoc.ComponentDefinition.Features.ExtrudeFeatures.Add(oD1)


'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 oRadiusList.Count - 1
    oTempCol.Clear
    Dim dDiameter As Double
    For Each oCircle In oCircleCol(i)
        oTempCol.Add (oCircle.CenterSketchPoint)
    Next
	
    dDiameter = oCircleCol(i).Item(1).Radius * 2
	dDiameter = Math.Round(dDiameter, 1)
    oPD = oDoc.ComponentDefinition.Features.HoleFeatures.CreateSketchPlacementDefinition(oTempCol)
    Dim oHole As HoleFeature
	oHole = oDoc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD, dDiameter, kSymmetricExtentDirection)		
	dDiameter = dDiameter * 10
	oHole.Name = "HoleD" + dDiameter.ToString
Next

Below iLogic code strictly for Sheet metal part. Because, FaceFeature is available only for sheet metal document.

 

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 oRadiusList As ArrayList = New ArrayList 
Dim oCircle As SketchCircle
For Each oCircle In oSK.SketchCircles	
	If oRadiusList.Contains(Math.Round(oCircle.Radius, 3)) = False Then		
		oRadiusList.Add(Math.Round(oCircle.Radius, 3))
	End If	
Next

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

For j = 0 To oRadiusList.Count - 1
	For Each oCircle In oSK.SketchCircles 
		If Math.Round(oCircle.Radius, 3).ToString = oRadiusList.Item(j).ToString Then
			oCircleCol(j).Add(oCircle)
		End If
	Next
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)

'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 oRadiusList.Count - 1
    oTempCol.Clear
    Dim dDiameter As Double
    For Each oCircle In oCircleCol(i)
        oTempCol.Add (oCircle.CenterSketchPoint)
    Next
	
    dDiameter = oCircleCol(i).Item(1).Radius * 2
	dDiameter = Math.Round(dDiameter, 1)
    oPD = oDoc.ComponentDefinition.Features.HoleFeatures.CreateSketchPlacementDefinition(oTempCol)
    Dim oHole As HoleFeature
	oHole = oDoc.ComponentDefinition.Features.HoleFeatures.AddDrilledByThroughAllExtent(oPD, dDiameter, kSymmetricExtentDirection)		
	dDiameter = dDiameter * 10
	oHole.Name = "HoleD" + dDiameter.ToString
Next

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,

 

 

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 39 of 73

FProcp
Collaborator
Collaborator

I've tried both the sheet metal version and the part version.

They both work really well.

The only issue is that the the holes are rounded off to zero decimal places.

The Ø14.3 circle becomes a Ø14 hole.

I could go through and fix these all up manually later but it would be nice it was correct with the code.

Thank you so much for your assistance.

 

Plate_Holes2.JPG

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

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @FProcp,

 

In both iLogic code, change from dDiameter = Math.Round(dDiameter, 1) to dDiameter = Math.Round(dDiameter, 2). It will work.

 

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network