iLogic code to refresh the HoleFeature in Inventor 2023

iLogic code to refresh the HoleFeature in Inventor 2023

f_slezakQ4FV2
Explorer Explorer
503 Views
2 Replies
Message 1 of 3

iLogic code to refresh the HoleFeature in Inventor 2023

f_slezakQ4FV2
Explorer
Explorer

Hello 🙂


I have adjusted the core hole diameters of our “thread.xls”. This is necessary because we have sheets with threads manufactured from STEP files.


The core hole diameters are created correctly for new designs. However, the core hole diameters in old parts are not adjusted according to the new “thread.xls”.


I had hoped that “rebuld all” would update the threads. However, this does not work.
Only when I change the size of the thread and then change it back the new core hole diameter is updated.
I have already started to write an iLogic script. However, it fails because I want to update all existing holes in the part.

 

Can you help me with a suitable For Each loop?

 

Dim ThreadMem = Feature.ThreadDesignation("Bohrung1")
Feature.ThreadDesignation("Bohrung1") = "M3x0.5"
Feature.ThreadDesignation("Bohrung1") = ThreadMem

 

0 Likes
Accepted solutions (2)
504 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @f_slezakQ4FV2.  There are two main types of features that can involve threads (HoleFeature, and ThreadFeature).  I'm not sure if that/those iLogic shortcut snippet(s) will work the way you want for a HoleFeature, but they may.  Below are some links to the online documentation for those iLogic shortcut tools/methods:

Feature (ICadFeature Interface) 

ICadFeature.ThreadClass Property (String) 

ICadFeature.ThreadClass Property (Object, String) 

ICadFeature.ThreadDesignation Property (String) 

ICadFeature.ThreadDesignation Property (Object, String) 

ICadFeature.ThreadType Property (String) 

ICadFeature.ThreadType Property (Object, String) 

One of these two below are required when you need to set more than one property at a time.

ICadFeature.SetThread Method (String, String, String, String) 

ICadFeature.SetThread Method (Object, String, String, String, String) 

However, those are all specific to the iLogic add-in, and are not really designed to effect every feature in a part by themselves, because they require you to specify the feature by its name, instead of the feature object itself.  The 'original/primary' way to do these same tasks is with the Inventor API tools/properties.

HoleFeature.Tapped 

HoleFeature.TapInfo (returns an Object, not a String, and is where most detailed data is kept)

ThreadFeature.SetThreadDepth (method)

ThreadFeature.DirectionReversed (Read/Write Property)

ThreadFeature.FullDepth (Read/Write Property)

ThreadFeature.ThreadDepth (ReadOnly)

ThreadFeature.ThreadInfo (returns an Object, not a String, and is where most detailed data is kept)

Below is just some 'starter' code for use in an iLogic rule for trying to make these changes using Inventor API code.  Once it gets to the 'TapInfo or ThreadInfo' property, that property returns one type of object, or another, depending on if it was tapered or not (StandardThreadInfo or TaperedThreadInfo or HoleTapInfo).  That object will have tons of properties, covering all possible aspects of the thread specifications that you can change.  Then, once you have made those changes to that object, you will need to set that object back as the new value of that TapInfo or ThreadInfo property, because it is a Read/Write property.

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
	If oPDoc Is Nothing Then Return
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oThreadFeats As ThreadFeatures = oPDef.Features.ThreadFeatures
	For Each oTF As ThreadFeature In oThreadFeats
		If oTF.ThreadInfoType = ThreadTypeEnum.kStandardThread Then
			Dim oSTI As StandardThreadInfo = oTF.ThreadInfo
			'set/change its properties (to many to list here)
		Else
			Dim oTTI As TaperedThreadInfo = oTF.ThreadInfo
			'set/change its properties (to many to list here)
		End If
	Next oTF
	Dim oHoleFeats As HoleFeatures = oPDef.Features.HoleFeatures
	For Each oHF As HoleFeature In oHoleFeats
		If Not oHF.Tapped Then Continue For
		'if regular, straight tapped hole, then use HoleTapInfo
		Dim oHTI As HoleTapInfo = oHF.TapInfo
		'make changes to HoleTapInfo object properties here
		'too many properties to list here
		
		'If tapered threads, then use TaperedThreadInfo
		'Dim oTTI As TaperedThreadInfo = oHF.TapInfo
	Next oHF
	oPDoc.Update2(True)
	'oPDoc.Save()
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 3 of 3

jnowel
Advocate
Advocate
Accepted solution

@f_slezakQ4FV2,

 

Below code can be inserted into lines 19-25 of the sample code above by @WCrihfield 
It should 'rebuild' the new tap info based on the current tap into details

This would get the information from your *new* 'thread.xls' file as specified in your Design Data folder.
If you are doing edits on the thread.xls file while Inventor is in session, you may need to restart Inventor for it to take effect.

		If TypeOf oHF.TapInfo Is HoleTapInfo Then
			
			'if regular, straight tapped hole, then use HoleTapInfo
			Dim oHTI As HoleTapInfo = oHF.TapInfo
			'make changes to HoleTapInfo object properties here
			'too many properties to list here
			oHF.TapInfo = oHoleFeats.CreateTapInfo(oHTI.RightHanded, oHTI.ThreadType, oHTI.ThreadDesignation, _
									oHTI.Class, oHTI.FullTapDepth, oHTI.ThreadDepth.Expression)
									
		ElseIf TypeOf oHF.TapInfo Is TaperedThreadInfo Then
			
			'If tapered threads, then use TaperedThreadInfo
			Dim oTTI As TaperedThreadInfo = oHF.TapInfo
			oHF.TapInfo = oHoleFeats.CreateTaperedTapInfo(oTTI.RightHanded, oTTI.ThreadType, oTTI.ThreadDesignation)
			
		End If

 

0 Likes