Inventor VBA: Set Thread Depth

Inventor VBA: Set Thread Depth

tonythm
Advocate Advocate
872 Views
15 Replies
Message 1 of 16

Inventor VBA: Set Thread Depth

tonythm
Advocate
Advocate

Hello All,

 

I have problem with SetThreadDepth for bolt (as attached file).  Everyone can help me write the code to choose StartEdge  on my model.

Or how to do can edit thread from FullThreadDepth = True into False, that thread depth still working. 

 

 

Thanks,

 

Thong

0 Likes
873 Views
15 Replies
Replies (15)
Message 2 of 16

WCrihfield
Mentor
Mentor

Try this code in an external iLogic rule.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Part Documents.",vbOK, "WRONG DOCUMENT TYPE")
	Return
End If

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

Dim oUParams As UserParameters = oDef.Parameters.UserParameters

Dim oThreadFeat As ThreadFeature = oDef.Features.ThreadFeatures.Item(1)
Dim oStartEdge As Edges = oThreadFeat.StartEdge
If oThreadFeat.FullDepth = True Then
	oThreadFeat.FullDepth = False
	oThreadFeat.SetThreadDepth(oUParams.Item("GEL"),oStartEdge)
ElseIf oThreadFeat.FullDepth = False Then
	Dim oThreadDepthParam As Parameter = oThreadFeat.ThreadDepth
	Dim oThreadDepth As Double = oThreadDepthParam.Value
	oThreadFeat.FullDepth = True
End If

 

Or try it this way for an local (saved inside the document) iLogic rule.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

Dim oThreadFeat As ThreadFeature = oDef.Features.ThreadFeatures.Item(1)
Dim oStartEdge As Edges = oThreadFeat.StartEdge
If oThreadFeat.FullDepth = True Then
	oThreadFeat.FullDepth = False
	oThreadFeat.SetThreadDepth(GEL,oStartEdge)
ElseIf oThreadFeat.FullDepth = False Then
	Dim oThreadDepthParam As Parameter = oThreadFeat.ThreadDepth
	Dim oThreadDepth As Double = oThreadDepthParam.Value
	oThreadFeat.FullDepth = True
End If

This code will toggle FullDepth On if it is currently Off, or it will toggle it Off if it is currently On.

Then, if turns FullDepth Off, it will maintain the same StartEdge and set the ThreadDepth to your Parameter.

If it turns the FullDepth On, it just captures the Parameter it was using when it was set to a specific length.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@tonythm,

 

To address this issue, a change request (INVGEN-39188) is created with engineering team.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 16

tonythm
Advocate
Advocate

Hello CHANDRA SHEKAR GOPAL,

 

When they are available to fix this error please let me know.

 

Thanks,

 

Thong

0 Likes
Message 5 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@tonythm,

 

We will let you know once it is fixed.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@tonythm,

 

Meanwhile, try below workaround.

 

Sub test()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim oThread As ThreadFeature
    Set oThread = oDoc.ComponentDefinition.Features.ThreadFeatures(1)

    ' Adam
    oThread.FullDepth = True

    ' move End of Part above to edit the feature
    oThread.SetEndOfPart False

    Dim oStartEdge As Edge
    Set oStartEdge = oDoc.ComponentDefinition.SurfaceBodies(1).Edges(24)

    oDoc.SelectSet.Select oStartEdge

    ' set the thread to full depth to workaround an issue
    'oThread.FullDepth = True

    oThread.SetThreadDepth 4, oStartEdge

    oDoc.ComponentDefinition.SetEndOfPartToTopOrBottom False
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 7 of 16

tonythm
Advocate
Advocate

Hi @chandra.shekar.g 

 

I tried but is not work.

I think, before set thread depth, need call full depth is False.

As Object Browser in VBA below:

 

"Member of Inventor.ThreadFeature
Property that gets and sets whether the threads extend the full length of the cylinder or cone. If True, they extend the full length. If False, the depth is controlled by the value of the ThreadDepth property."

 

As Inventor API help below, about ThreadDepth:

 

Property that returns the parameter that controls the depth of the thread. Even though the parameter for the thread depth is always created and accessible through this property, it is only used in the case where the FullDepth property is False.
Message 8 of 16

JarFu
Autodesk
Autodesk

@chandra.shekar.g,

 

I guess you intended to use "oThread.SetEndOfPart True" as True means Before, please have a check.



Jar Fu
SW Engineer
Inventor QA
Autodesk, Inc.
0 Likes
Message 9 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@JarFu,

 

You mean oThread.SetEndOfPart should be True?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 16

tonythm
Advocate
Advocate

Hi @chandra.shekar.g 

 

Do you have any updates?

0 Likes
Message 11 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@tonythm,

 

Try below changes

Sub test()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim oThread As ThreadFeature
    Set oThread = oDoc.ComponentDefinition.Features.ThreadFeatures(1)

    ' Adam
    oThread.FullDepth = True

    ' move End of Part above to edit the feature
    oThread.SetEndOfPart True

    Dim oStartEdge As Edge
    Set oStartEdge = oDoc.ComponentDefinition.SurfaceBodies(1).Edges(24)

    oDoc.SelectSet.Select oStartEdge

    ' set the thread to full depth to workaround an issue
    'oThread.FullDepth = True

    oThread.SetThreadDepth 4, oStartEdge

    oDoc.ComponentDefinition.SetEndOfPartToTopOrBottom False
End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 12 of 16

tonythm
Advocate
Advocate

Hi @chandra.shekar.g 

 

How to determine the SurfaceBodies and StartEdges on this model? or any model?

Can you show me any material? I don't know about this. Please

 

Dim oStartEdge As Edge
    Set oStartEdge = oDoc.ComponentDefinition.SurfaceBodies(1).Edges(24)

 

0 Likes
Message 13 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@tonythm,

 

Usually, StartEdge is available in ThreadFeature object. Please explain startedge with sample image.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 14 of 16

tonythm
Advocate
Advocate

Hi @chandra.shekar.g 

 

There are a couple of cases where startedge is selected incorrectly as in the attached image.

Inventor.JPG

0 Likes
Message 15 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@tonythm,

 

Please provide non confidential part file and mention the expected edge and actual edge in a image.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 16 of 16

tonythm
Advocate
Advocate

Hi @chandra.shekar.g 

 

When I changed the length of some files, the same error occurred.

0 Likes