Extract type of a part when it is either a bolt, nut or washer

Extract type of a part when it is either a bolt, nut or washer

Anonymous
Not applicable
842 Views
9 Replies
Message 1 of 10

Extract type of a part when it is either a bolt, nut or washer

Anonymous
Not applicable

Hi,

 

is there any ilogic or iproperty from which I can extract that the part is either a bolt or nut or washer? The description property by default does not give like for example 'washer', instead it gives the standard code of the washer.

 

Thanks.

 

Anas.

0 Likes
Accepted solutions (1)
843 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Well, there is few things you could check, if all the items in a group are going to be one of those three choices.  You could check (by code) if the part contains any threads (one way or the other), and if it doesn't it must be a washer.  If it does have threads, you can check the thread 'Class', which will tell you if they are external threads or internal threads.  Then obviously internal threads mean its a nut, while external threads means it is a bolt.  Does that sound like a process that would work for you?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

Anonymous
Not applicable

Yeah, I find this quite doable. Can you guide me to writing the ilogic?

0 Likes
Message 4 of 10

WCrihfield
Mentor
Mentor

OK. I threw this together in iLogic. See if this will work for you.

Keep in mind that this is just a test which searches for threads that were either created as a tapped hole feature, or as a ThreadFeature, so if your model only has physically modeled threads, and neither of the other two, it may not work properly.  For now I'm just using MsgBox to return the result of the test, but this could be put into its own Function, to return a String (like "Bolt", "Nut", "Washer", "Unknown").

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition

'Build a list of Strings that represent all the Class identifiers for Internal threads and a List for External threads.
Dim oInList As New List(Of String) 'for every internal thread Class
oInList.Add("1B") : oInList.Add("2B") : oInList.Add("3B") : oInList.Add("6H") : oInList.Add("7H")
Dim oExList As New List(Of String) 'for every external thread Class
oInList.Add("1A") : oInList.Add("2A") : oInList.Add("3A") : oInList.Add("6g") : oInList.Add("4g6g") : oInList.Add("7e")
Dim oClass As String
Dim oThreadFound As Boolean = False
Dim oClassFound As Boolean = False
Dim oInternal As Boolean = False
Dim oFeats As PartFeatures = oPDef.Features
Dim oThreadInfo As HoleTapInfo
If oFeats.HoleFeatures.Count > 0 Then
	'It has to be either a Nut or a Washer, depending on how they were modeled
	'But if the Nut or Washer were created as an extrude feature that already had the hole included, then there won't be any HoleFeatures..
	For Each oHole As HoleFeature In oFeats.HoleFeatures
		If oHole.HoleType = HoleTypeEnum.kDrilledHole And oHole.Tapped Then
			oThreadFound = True
			oThreadInfo = oHole.TapInfo
			For Each oClass In oInList
				If oThreadInfo.Class = oClass Then 'It is an internal thread, and so it is a Nut
					oClassFound = True
					oInternal = True
				End If
			Next
			For Each oClass In oExList
				If oThreadInfo.Class = oClass Then 'It is an internal thread, and so it is a Nut
					oClassFound = True
					oInternal = False
				End If
			Next
			If oClassFound = False Then
				MsgBox("The Class of the hole's threads did not match any value of either list.", vbOKOnly, "INCONCLUSIVE")
			End If
		End If
	Next
End If
If oFeats.ThreadFeatures.Count > 0 Then
	For Each oTFeat As ThreadFeature In oFeats.ThreadFeatures
		oInternal = oTFeat.ThreadInfo.Internal
		oThreadFound = True
	Next
End If

If oThreadFound = False Then
	MsgBox("No threads found in this part, so it must be a Washer.", vbOKOnly + vbInformation, " ")
	Return
End If

If oInternal = True Then
	MsgBox("The part has internal threads, so it must be a Nut.", vbOKOnly + vbInformation, " ")
ElseIf oInternal = False Then
	MsgBox("The part has external threads, so it must be a Bolt.", vbOKOnly + vbInformation, " ")
End If

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 10

Anonymous
Not applicable

ok cool. I will adjust it to my specifications and see what it gives.

0 Likes
Message 6 of 10

_dscholtes_
Advocate
Advocate

@Anonymous Do the nuts, bolts and washers come from content center? Then the family name could be a clue.

0 Likes
Message 7 of 10

Anonymous
Not applicable

Yeah they come from content center.

0 Likes
Message 8 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

You could use this rule:

Sub Main
	Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick _
	(kAssemblyLeafOccurrenceFilter, "Pick occurrence")
	If oOcc.DefinitionDocumentType <> _
		kPartDocumentObject Then
		MsgBox("The occurrence is not a CC part.")
		Exit Sub
	End If
	Dim oOccDef As PartComponentDefinition = oOcc.Definition
	If Not oOccDef.IsContentMember Then
		MsgBox("The occurrence is not a CC part.")
		Exit Sub
	End If
	Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
	Dim propSet As PropertySet = oOccDef.Document.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")
	Dim familyId As Inventor.Property = propSet.Item("FamilyId")
	Dim oContentFamily As ContentFamily = oContentCenter.GetContentObject("v3#" & familyId.Value & "#")
	Dim oContentNode As ContentTreeViewNode
	oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners")
	For Each oNode As ContentTreeViewNode In oContentNode.ChildNodes
		If SearchNode(oNode, oContentFamily) Then MsgBox(oNode.DisplayName)
	Next
End Sub
Function SearchNode(oNode As ContentTreeViewNode, oFamily As ContentFamily) As Boolean
	Dim FamFound As Boolean = False

	For Each oFam As ContentFamily In oNode.Families
		If oFam Is oFamily
			FamFound = True
			Return True
		End If
	Next
	If oNode.ChildNodes.Count > 0
		For Each oChild As ContentTreeViewNode In oNode.ChildNodes
			If SearchNode(oChild, oFamily) = True
				FamFound = True
				Return True
			End If
		Next
	End If
	Return FamFound
End Function

The rule will return which node in "Fasteners" the occurrence comes from:

SearchCC.PNG

Message 9 of 10

Anonymous
Not applicable

Thanks very much. This is what I wanted to do.

0 Likes
Message 10 of 10

JhoelForshav
Mentor
Mentor

You're welcome @Anonymous 

Please don't forget to accept my reply as solution then 🙂