iLogic change threadsize - not updating depths

iLogic change threadsize - not updating depths

jaapschreuder
Contributor Contributor
1,873 Views
16 Replies
Message 1 of 17

iLogic change threadsize - not updating depths

jaapschreuder
Contributor
Contributor

Dear all,

 

as stated in the title, after changing the threadsize by iLogic, the depths are not updated to the thread.xls file as it would if I've done it manually.

 

Is there a workaround for this?

 

The function I'm using is;

Feature.SetThread("FeatureName", "ISO Metric profile Compagny", "M6x1", "6H")

 

Thank you in advance for helping out!

0 Likes
Accepted solutions (2)
1,874 Views
16 Replies
Replies (16)
Message 2 of 17

WCrihfield
Mentor
Mentor

Have you tried creating the feature manually the way you want it, then using the following lines of code to retrieve the correct strings to use in the 'SetThread' Sub?

MsgBox("ThreadClass = " & Feature.ThreadClass("FeatureName"))

MsgBox("ThreadDesignation = " & Feature.ThreadDesignation("FeatureName"))

MsgBox("ThreadType = " & Feature.ThreadType("FeatureName"))

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 17

jaapschreuder
Contributor
Contributor

Yes already did this,

 

The threadtype is updated to the type I want, only the depths are not updated the way it does when I do it manually

0 Likes
Message 4 of 17

WCrihfield
Mentor
Mentor

Is that thread.xls file 'Linked' to your model file?  It the Parameter that the ThreadFeature's Depth is using greyed out, so it can only be changed from the Excel file?  Or is the part a Content Center part, iPart, etc?  Are you referencing this Excel file within the same rule, and extracting the String from a specified Cell address using GoExcel?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 17

jaapschreuder
Contributor
Contributor

The thread.xls file is the file where the threads are specified.
It is a common xls file where it gets the correct dimensions.

If I change the value in the hole feature, the depths are updated after the table - and that is what I would like to achieve.

0 Likes
Message 6 of 17

ianteneth
Advocate
Advocate

Hi @jaapschreuder,

 

The default Inventor Thread.xls doesn't appear to have a "Thread Depth" column for ISO Metric external threads (See screenshot below). Did you manually add that column? When you "do it manually", where in the spreadsheet does the "Thread Depth" value come from?

 

Annotation 2020-04-27 094521.png

0 Likes
Message 7 of 17

jaapschreuder
Contributor
Contributor

Hi  Aneely,

 

working on the inside threads at the moment, and there the Thread Depth and Thread Runouts are specified.
Combined the represent the drilling depth. And here is the information coming from.

 

When selecting the "most efficient" bolt I found out the bolthole had weird dimensions - although in the hole feature itself it is showing the right specifications, and only haven't updated the thread depths (keeps the depths that are used before thread changing in the rule)

Selecting a 'wrong' size and then to the desired size - all dimensions are as expected.

 

 

 

 

 

 

Drilling_depth.jpg

0 Likes
Message 8 of 17

jaapschreuder
Contributor
Contributor

Anyone having an idea how to make it work?

I can't believe it is giving me this much trouble 😞

0 Likes
Message 9 of 17

WCrihfield
Mentor
Mentor

Not sure if its any help, but here's some iLogic code to extract all available info from the Thread Feature.

Get Thread Info (Hole Feature that is threaded or a Thread Feature) - iLogic 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 17

ianteneth
Advocate
Advocate

Still working on this, but to help others here is a test part with an embedded rule and also the code.

 

FYI, in the future it is best to include stuff like this in your original post, that way others can test it quickly. Also, the Autodesk representatives will probably ask you for this before they help anyways.

 

The original hole is an M5 with a depth of 10mm. The new depth after running this code should be 16mm. I am using the default thread spreadsheet.

 

' Get active part. Assume a part is opened.
Dim part As PartDocument = ThisApplication.ActiveDocument
' Get first hole feature in the active part.
Dim hole As HoleFeature = part.ComponentDefinition.Features.HoleFeatures(1)

' Change the thread. Depth is not updated with this command.
Feature.SetThread("Hole1", "ISO Metric profile", "M8x1", "6H")

 

 

Message 11 of 17

ianteneth
Advocate
Advocate

Here is a hacked together way to update the hole depth manually. This isn't the ideal way, but it seems to work for me. I am not sure what the rest of your code looks like, so you may have to tweak the beginning  where you are getting the hole object. Instead of searching for the hole feature by name like you used to, for this to work you have to find the hole feature object in the part. If you want to post the rest of your code I could hopefully help you fit this into it.

 

Also, note that I had to hard code the path to the thread.xls file. I am using Inventor 2020 so you may have to change that.

 

' Get active part. Assume a part is opened.
Dim part As PartDocument = ThisApplication.ActiveDocument
' Get first hole feature in the active part.
Dim hole As HoleFeature = part.ComponentDefinition.Features.HoleFeatures(1)
' The thread designation to change the hole to.
' *******CHANGE THIS LINE *******
Dim newThreadDesignation As String = "M6x1"
' The thread class to change the hole to.
' *******CHANGE THIS LINE *******
Dim newThreadClass As String = "6H"
' The path to the thread.xls spreadsheet.
' Change to match your setup.
' *******CHANGE THIS LINE *******
Dim spreadSheetFilePath As String = "C:\Users\Public\Documents\Autodesk\Inventor 2020\Design Data\XLS\en-US\thread.xls"
' The sheet name in the thread.xls spreadsheet for the 
' thread standard you want.
' *******CHANGE THIS LINE *******
Dim spreadSheetSheetName As String = "ISO Metric profile"

' Change the hole to the new thread; except the depth.
Feature.SetThread(hole.Name, spreadSheetSheetName, newThreadDesignation, newThreadClass)

' Get the correct thread depth from the thread.xls spreadsheet.
' The column titles are on row 3 for "Thread Designation" and "Class"
GoExcel.TitleRow = 3
' Get the row that matches the new thread values.
' ie. the row with M5x0.8 6H.
Dim row As Integer = GoExcel.FindRow(spreadSheetFilePath, spreadSheetSheetName, "Thread Designation", "=", newThreadDesignation, "Class", "=", newThreadClass)
' Get the thread depth value at that row. Thread Depth column is column V.
Dim spreadSheetThreadDepth As String = GoExcel.CellValue("V" & row)

' Convert the thread depth from the thread.xls spreadsheet to a number.
Dim spreadSheetThreadDepthDouble As Double
Double.TryParse(spreadSheetThreadDepth, spreadSheetThreadDepthDouble)

' Update the hole thread depth in the model. 
' The depth is in mm in the spreadsheet. 
' Inventor uses cm internally; so divide by 10.
hole.TapInfo.ThreadDepth.Value = (spreadSheetThreadDepthDouble / 10)

 

Message 12 of 17

jaapschreuder
Contributor
Contributor
Accepted solution
Sub main
	DateCreated
	ThreadFileLocation
	ThreadFileUpdateDate = IO.File.GetCreationTime(ThreadFileLocation)
	SetThread
End Sub


Public Function DateCreated
Dim strFileName As String = ThisDoc.Document.FullFileName
Dim oFS As Object 
oFS = CreateObject("Scripting.FileSystemObject")
Dim oDate As String = oFS.GetFile(strFileName).DateCreated
	Return oDate
End Function


Public Function ThreadFileLocation
Dim Thread As String = ThisApplication.DesignProjectManager.ActiveDesignProject.DesignDataPath
	For Each File As String In IO.Directory.GetFiles(Thread, "*.xls", IO.SearchOption.AllDirectories)
 		 	If IO.Path.GetFileName(File) = "thread.xls" Then
			oFilePath = IO.Path.GetFullPath(File)
			Return oFilePath
			End If
	Next
End Function


Sub SetThread
Dim oDoc As PartDocument = ThisDoc.Document
Dim oHole As HoleFeature
For Each oHole In oDoc.ComponentDefinition.Features.HoleFeatures
	If oHole.Name.Contains("MonGaten") Then
		Dim oTreadType As String = "ISO Metric profile Compagny Voet"
		oThreadDes = Feature.ThreadDesignation(oHole.Name)
		GoExcel.TitleRow = 3
		i = GoExcel.FindRow(ThreadFileLocation, oThreadType, "Thread Designation", "=", oThreadDes)
		oClass = GoExcel.CurrentRowValue("Class")
		GoExcel.TitleRow = 2
		oThreadDepth = GoExcel.CurrentRowValue("Thread Depth")
		oDrillDepth = sThreadDepth + GoExcel.CurrentRowValue("Thread Runouts")
		ISOMetricProfileCompagnyVoet(oHole.Name,oThreadDes,sDrillDepth,sThreadDepth)
	End If
Next
End Sub

Public Sub ISOMetricProfileCompagnyVoet(ByRef oFeature As String, ByRef oThreadDes As String, ByRef oDrillDepth As String, ByRef oThreadDepth As String)
oDoc = ThisDoc.Document
Dim oHoleFeature As HoleFeature
oHoleFeature = oDoc.ComponentDefinition.Features.Item(oFeature)
Dim oTapInfo As HoleTapInfo
oTapInfo = oHoleFeature.TapInfo
oRightHand = True
oThreadStandard = "ISO Metric profile Compagny Voet"       
oClass = "6H"
oFullThread = False
oThreadDepth = "12 mm"
Dim oTappedInfo As HoleTapInfo
oTappedInfo = oDoc.ComponentDefinition.Features.HoleFeatures.CreateTapInfo _
(oRightHand, oThreadStandard, oThreadDes, oClass, oFullThread, oThreadDepth)
oHoleFeature.TapInfo = oTappedInfo
oHoleFeature.SetDistanceExtent(oDrillDepth, kPositiveExtentDirection, True)
oHoleFeature.TapInfo.ThreadDepth.Expression = oThreadDepth
End Sub
	
Message 13 of 17

jaapschreuder
Contributor
Contributor

Thank you ianteneth,

 

I got a similar solution in de post above.

Changing the thread depth is only a part of the total code.

Here you an also find another solution to the xls file - If you're interested in it!

 

 

Message 14 of 17

ianteneth
Advocate
Advocate

Great! Don't forget to mark your post as the solution.

0 Likes
Message 15 of 17

Guthery1
Enthusiast
Enthusiast

I see a solution given but couldn't you set the depth of your hole based off a plain from the surface you start the hole on?  Then you just need a simple parameter to drive to the depth you need it set too.  You might need to define a separate plain for each hole (depending on whether you want to control each hole independently).

 

I tried this on a part/assembly and it worked really well without super complex coding.

0 Likes
Message 16 of 17

jaapschreuder
Contributor
Contributor
Accepted solution

Thank you for replying, that seems a quite workaround since my goal is to centralise the standard depths.

 

My current workaround is a reference in an externalrule, where the original threadfile of inventor is requested.

Since there is no excel reference in this rule,  but accessed thru a *.dll file there are no interruptions working with all of the colleges with the same thread table.

 

The ilogic excell reference isn't the most stable one I occurred. 

Whole worktrue is accomplished with my colleague, so I might miss some details

0 Likes
Message 17 of 17

Guthery1
Enthusiast
Enthusiast

If you want to standardize the depths, you could make it a drop-down selection tool.  Then they can only use the depths you want them to use.  It might be beneficial to control what options you want to have based on an external rule so you can easily add options to existing projects.  This could help avoid the issues that sometimes exist when referencing an outside Excel doc.

0 Likes