countersunk hole to a regular hole with the diameter of the outer edge

countersunk hole to a regular hole with the diameter of the outer edge

tim_van_den_brande
Participant Participant
945 Views
12 Replies
Message 1 of 13

countersunk hole to a regular hole with the diameter of the outer edge

tim_van_den_brande
Participant
Participant

Hi all,

 

i found this rule and it helped me a lot (bottom) but now we changed to another punchmachine and now we need to make a big hole with a pre punch and headpunch tightens the hole to the correct diameter when making the countersink. So what i'm looking for now is a rule that changes a countersink hole to a regular hole with the diameter of the biggest diameter .

For example we make holes VS 4,8 and we pre punch them with diameter 7 and head punch them with 9,4 under 45° . the result is a countersunk hole with inner diameter 4,8 . so in the ipt file we need a countersink hole with inner diameter 4,8 and outer diameter 7, than it looks OK for the architects and also our machine program can do its thing.

Is there a way to change the rule below, because the rule below deletes the countersink but changes it to the smallest diameter (innerdiameter) and i need the biggest diameter.

 

If the person who made the code below reeds this thank you , i don't know where i fount it but thank you. I hope it is possible with minor adjustments.

 

I'm a beginner with i logic but allready know how usefull it is and i really hope somebody can help me out with this.

 

Thank in advance

 

Dim a As Application
a = ThisApplication
Dim b As PartDocument
b = a.ActiveDocument
Dim c As HoleFeature
c = b.ComponentDefinition.Features.HoleFeatures.Item(1)
Dim trm As TransactionManager
trm = a.TransactionManager
Dim tr As Transaction
tr = trm.StartTransaction(b, "Undo this")
'Suppress all chamfers and fillets
Dim oEachF As PartFeature
'iterare each feature


'Make drilled holes from countersinkholes and counterboreholes
For Each c In b.ComponentDefinition.Features.HoleFeatures
If c.HoleType = kCountersinkHole Then
c.SetDrilled
End If
Next
For Each c In b.ComponentDefinition.Features.HoleFeatures
If c.HoleType = kCounterBoreHole Then
c.SetDrilled
End If
Next
tr.End

0 Likes
Accepted solutions (1)
946 Views
12 Replies
Replies (12)
Message 2 of 13

A.Acheson
Mentor
Mentor

Hi @tim_van_den_brande 

In the hole feature object API help here

You need to save the Dia of countersink before you delete. 

 

CSinkDiameter property Help

Syntax

HoleFeature.CSinkDiameter() As Parameter

 

Then from the parameter get the model value

Parameter.ModelValue Property Syntax

Parameter.ModelValue() As Double

 

 

Dim csinkDia As Double = c.CSinkDiameter.ModelValue
MesssgeBox.Show(c.CSinkDiameter.ModelValue)

 

 

Then you want to change the hole feature diameter to the Dia of countersink previously stored. 

Hole Feature Diameter Property

Syntax

HoleFeature.HoleDiameter() As Parameter

 

Now set the hole Dia 

 

 c.HoleDiameter.ModelValue = csinkDia

 

 

Hopefully you can follow this and implement in you existing code. I would start by just sending the value to messagebox and check it matches then do the same for the hole then set the value of the new hole feature.

 

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

tim_van_den_brande
Participant
Participant

i'm gonna try it, i'm really new with ilogic so i hope i will get it right and than i will mark your reply as solution.

0 Likes
Message 4 of 13

tim_van_den_brande
Participant
Participant

i have no idea what i'm doing 

0 Likes
Message 5 of 13

tim_van_den_brande
Participant
Participant

I even tried CHATGPT for the first time and she tried but couldn't do it

 

0 Likes
Message 6 of 13

A.Acheson
Mentor
Mentor

Hi @tim_van_den_brande 

No need for chat gpt. Here is the first line in the right place. What do you get?  You need a counter sink hole to be in the test part. 

Dim a As Application
a = ThisApplication
Dim b As PartDocument
b = a.ActiveDocument
Dim c As HoleFeature
c = b.ComponentDefinition.Features.HoleFeatures.Item(1)
Dim trm As TransactionManager
trm = a.TransactionManager
Dim tr As Transaction
tr = trm.StartTransaction(b, "Undo this")
'Suppress all chamfers and fillets
Dim oEachF As PartFeature
'iterare each feature


'Make drilled holes from countersinkholes and counterboreholes
For Each c In
b.ComponentDefinition.Features.HoleFeatures
    If c.HoleType = kCountersinkHole Then
       Dim csinkDia As Double = c.CSinkDiameter.ModelValue
       MessageBox.Show(c.CSinkDiameter.ModelValue)
 
       'c.SetDrilled
    End If
Next
For Each c In b.ComponentDefinition.Features.HoleFeatures
    'If c.HoleType = kCounterBoreHole Then
        'c.SetDrilled
    'End If
Next
tr.End

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 13

WCrihfield
Mentor
Mentor
Accepted solution

Here is another example code I was working on at the same time, just for reference.  It works OK for me.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisDoc.Document
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oHoleFeat As HoleFeature = oPDef.Features.HoleFeatures.Item(1)
	If oHoleFeat.HoleType = HoleTypeEnum.kCounterSinkHole Then
		Dim dDia As Double = oHoleFeat.CSinkDiameter.Value
		Logger.Info("dDia = " & dDia.ToString)
		oHoleFeat.SetDrilled
		Logger.Info("oHoleFeat.HoleDiameter.Value = " & oHoleFeat.HoleDiameter.Value)
		oHoleFeat.HoleDiameter.Value = dDia
		Logger.Info("oHoleFeat.HoleDiameter.Value = " & oHoleFeat.HoleDiameter.Value)
	End If
	If oPDoc.RequiresUpdate Then oPDoc.Update2(True)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 13

tim_van_den_brande
Participant
Participant

@A.Acheson 

tim_van_den_brande_1-1694408935591.png

 

This is what i have in our sheet metal that we get from our upstairs designers, but our software recognizes this as countersunk hole but then changes it to 2 cirkels a triangle and a cross and than doesn't know what to do with it. We need to put our tools on it manually and this means delete everything draw new circle and then put a pre punch tool and a head tool on it. to make it easier for the programmer of our other software , i'm now trying to change the countersunk hole in inventor to a regular hole with the outside diameter . for example the hole in the screen shot has a small Ø of 4,8mm and a big Ø of 7mm (because the pre punch is 7 mm and the hole after both tools punched it will be 4,8mm again ) I have the code to change countersunk to regular hole but with the small Ø 4,8 as result . I tried the code you wrote but i get an error in line 1. 

0 Likes
Message 9 of 13

tim_van_den_brande
Participant
Participant

@WCrihfield 

 

tim_van_den_brande_1-1694408935591.png

 

This is what i have in our sheet metal that we get from our upstairs designers, but our software recognizes this as countersunk hole but then changes it to 2 cirkels a triangle and a cross and than doesn't know what to do with it. We need to put our tools on it manually and this means delete everything draw new circle and then put a pre punch tool and a head tool on it. to make it easier for the programmer of our other software , i'm now trying to change the countersunk hole in inventor to a regular hole with the outside diameter . for example the hole in the screen shot has a small Ø of 4,8mm and a big Ø of 7mm (because the pre punch is 7 mm and the hole after both tools punched it will be 4,8mm again ) I have the code to change countersunk to regular hole but with the small Ø 4,8 as result . I tried the code you wrote but it doesn't do anything to the hole. 

0 Likes
Message 10 of 13

A.Acheson
Mentor
Mentor

If error is in line 1 then likely it doesn't know what application object your using. 

Try this

Dim a As Inventor.Application

Or forget about declaring the application which isn't necessary and go straight to getting the document like this

 

Dim b As PartDocument
b = ThisApplication.ActiveDocument

 Or like this

Dim b As PartDocument
b = ThisDoc.Document

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 11 of 13

tim_van_den_brande
Participant
Participant

@A.Acheson 

 

that fixed the first error but now i get this

Rule Compile Errors in Rule32, in Part5

Error on Line 6 : a is niet gedeclareerd. Het item is mogelijk niet toegankelijk als gevolg van het bijbehorende beveiligingsniveau.

 

But i also got a code that works from @WCrihfield 

But also thank you very much for your time, if you want you can send me a your solution and i will be glad to test it and if it works also mark your code as a solution.

0 Likes
Message 12 of 13

tim_van_den_brande
Participant
Participant

@WCrihfield 

 

It was actually the code that you gave me in another post that is the sollution.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/suppress-countersunk-holes/m-p/12222...

 

0 Likes
Message 13 of 13

tim_van_den_brande
Participant
Participant

@WCrihfield 

 

UPDATE : Never mind (the question below ) i tested it again and also works fine, i think i did something wrong the first time.

 

 

One more question,  i made punchtools from countersunk holes , so the other people can easily take a punch tool with correct dimentions to make the holes instead of open the hole feature and change alle dimensions, i assume the code you gave me in the other post won't work then?

Is there a way that it would work as well? because it is a ifeature with the same dimensions as the countersunk hole but isen't recognised as countersunk hole i thinK?

0 Likes