check if hole has thread

check if hole has thread

Charlies_3D_T
Advocate Advocate
3,049 Views
8 Replies
Message 1 of 9

check if hole has thread

Charlies_3D_T
Advocate
Advocate

Hello,

 

Do one of you know how i can check with ilogic if the hole feature has thread? 

 

I want a code that checks if the hole is a normal hole or a threaded hole. 

 

Thanks for the help!

0 Likes
Accepted solutions (1)
3,050 Views
8 Replies
Replies (8)
Message 2 of 9

JelteDeJong
Mentor
Mentor

hi, does this work for you?

[iLogic]

Dim feature As PartFeature = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select a hole")

If (feature.Type <> ObjectTypeEnum.kHoleFeatureObject) Then
    MsgBox("This is not an hole feature")
End If

Dim hole As HoleFeature = feature
Dim info As HoleTapInfo = hole.TapInfo

If (info Is Nothing) Then
    MsgBox("This hole is not threaded")
Else
    MsgBox("This hole is thread: " + info.ThreadDesignation)
End If

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 9

Charlies_3D_T
Advocate
Advocate

@JelteDeJong 

 

Hello,

 

Not working like i want. 

 

I explained myself bad i think. 

 

I want the rule to be automaticaly so it goes true all the PartFeatures. And i detect if its a hole and a cut or extrude and does something then. 

 

With your rule i need to select a hole. I need for example the rule below when the hole is thread then i = i + 1. But when i try to adapt your code it's not working. 

 

For Each oFeature In oFeatures
	'check if its a hole
	If TypeOf oFeature Is ExtrudeFeature And oFeature.Suppressed = False And oFeature.Name.Contains("Hole") Then
		'increment one
		i = i + 1
	End If	
Next

 

0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor

Hi @Charlies_3D_T 

Do you just want to count how many faces in the part has threads?

Like this?

Dim pDoc As PartDocument = ThisDoc.Document
Dim i As Integer
For Each oBod As SurfaceBody In pDoc.ComponentDefinition.SurfaceBodies
	For Each oFace As Face In oBod.Faces
		If oFace.ThreadInfos IsNot Nothing Then i += 1
	Next
Next

Messagebox.Show("Threaded faces in part: " & i, "Number of threads")
Message 5 of 9

JelteDeJong
Mentor
Mentor
Accepted solution

If you need to find the features to changed them. then you could also use this code:

Dim doc As PartDocument = ThisDoc.Document
Dim features = doc.ComponentDefinition.Features

Dim numberOfThreadedHoleFeatures As Integer = 0
For Each hole As HoleFeature In features.HoleFeatures
    Dim info As HoleTapInfo = hole.TapInfo
    If (info IsNot Nothing) Then
        numberOfThreadedHoleFeatures = numberOfThreadedHoleFeatures + 1
        ' Your hole changing code go's here
    End If
Next
MsgBox("Number of holes with thread: " & numberOfThreadedHoleFeatures)

' you can skip this loop if you just want to count the number of tread features
For Each thread As ThreadFeature In features.ThreadFeatures
    ' Your thread changing code go's here
Next
MsgBox("Number of threadfeatures (on a extrude or cut feature): " _
		& features.ThreadFeatures.Count)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 6 of 9

Charlies_3D_T
Advocate
Advocate

@JelteDeJong 

 

Can i ask you if you want to take a look at an other problem? In this problem i want to have for example a assembly painted and then i need the color placed in a custom property inside this assembly so that when i make a drawing i can get the color on the drawing. 

 

I don't want to paint the parts because in real life you first assembly the welding assembly and after it goes to the painting stage. I hope you can help me. 

 

I have this rule for placing the color inside a property inside a part: 

 

Dim oDoc As Document
oDoc = ThisDoc.Document
 
If ThisDoc.Document.ActiveAppearance.DisplayName.Contains("RAL") then
 
iProperties.Value("Custom", "Color") = Left(ThisDoc.Document.ActiveAppearance.DisplayName, 8)

End If

 

Here is the link with my question: 

 

https://forums.autodesk.com/t5/inventor-customization/how-to-add-appearance-from-an-assembly-to-the-...

0 Likes
Message 7 of 9

tim11_manhhieu
Advocate
Advocate

Hi, when I type hole.TapInfo. (at the 2nd dot I press Ctrl+Space, but ThreadDesignation does not appear, I do not declare the info variable) (method 1)

but when I type like info. (at the 1st dot I press Ctrl+Space, ThreadDesignation appears, I declare the info variable) (method 2)

So how can I know when to do method 1 and when to do method 2 ?

 

Dim feature As PartFeature = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select a hole")

If (feature.Type <> ObjectTypeEnum.kHoleFeatureObject) Then
    MsgBox("This is not an hole feature")
End If

Dim hole As HoleFeature = feature
Dim info As HoleTapInfo = hole.TapInfo

If (info Is Nothing) Then
    MsgBox("This hole is not threaded")
Else
    MsgBox("This hole is thread: " + info.ThreadDesignation)
End If

 

 

 

 

0 Likes
Message 8 of 9

WCrihfield
Mentor
Mentor

Hi @tim11_manhhieu.  In this situation, we could first check the HoleFeature.Tapped property's value, to see if it is True, before we even get around to checking the HoleFeature.TapInfo property.  But when we bet to that TapInfo property, its value Type is 'Object', instead of something more specific, because it can return two different Types of objects (HoleTapInfo or TaperedThreadInfo).  Unfortunately, there is no direct property of the HoleFeature that tells us which one to expect.  So, if we do not already know which one to expect, we would have to check what Type of value it has first.  We can use an If...ElseIf...End If type statement, where we check if it is each Type, and when a match is found, set it as the value of the correct Type of variable.  But we would most likely want to declare both types of variables before the If statement starts, instead of within the If statement, that way we could continue using that variable after the If statement's end.  Since there are only 2 options, we can just use the 'TypeOf' operator to compare the Value with the expected Type in both cases.  Once we have determined which one we got, we can move on with the rest of our code, which accesses the unique properties of that specific Type.  Most times we already know what type to expect, because we only have one type of threads in our designs, which makes it simpler to deal with.

This is a common situation to encounter throughout the Inventor API (and elsewhere), so those tactics can be used in many different situations.  Perhaps the most common is the Inventor.Property object (AKA:  iProperty).  The Property.Value of all of them is Object (Variant Type is the VBA system's version of VB.NET's Object Type), instead of something more specific.  This is because they can hold a String, Boolean, Number, or Date...each is a different object type.  Since some of us interact with them so often, we just know which ones have which type of values, and plan on that.  But if we were new to them, and do not know what type of value to expect, we would need to do extra testing to determine the Type of each one.  When we create custom Properties, we set their Type simply by setting a value to them, then they adapt that value's Type.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 9

tim11_manhhieu
Advocate
Advocate

Always a very detailed explanation.

Thanks so much.

0 Likes