setting fastener size using API

setting fastener size using API

mostafamahmoudseddek94
Advocate Advocate
418 Views
3 Replies
Message 1 of 4

setting fastener size using API

mostafamahmoudseddek94
Advocate
Advocate

 

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

Dim oHoleF As HoleFeatures
Set oHoleF = oDoc.ComponentDefinition.Features.HoleFeatures


oHoleF.Item(3).ClearanceInfo.FastenerSize = "M10"
    MsgBox (oHoleF.Item(3).ClearanceInfo.FastenerType)

Hello, I am new to the API 

through this code, I am trying to set the fastener size to be a specific value based on a specific parameter. the programming/API Help informed that the "FastenerSize" is a read-write property to set or get the fastener size so how can I use this method to set the fastener size, Although using this code introduces error for me " Run-time error 445, Object doesn't support this action".

noting that this is the only thing in the hole feature that will change as shown in the figure below and all other choices will be constant with a different configuration of the model.

Capturerr.PNG

 

thanks 

 

0 Likes
419 Views
3 Replies
Replies (3)
Message 2 of 4

HideoYamada
Advisor
Advisor

Hi,

 

You have to create new HoleClearanceInfo and then replace target ClearanceInfo with new one.

 

Sub main()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oHoleF As HoleFeatures
    Set oHoleF = oDoc.ComponentDefinition.Features.HoleFeatures
    
    Dim oHole As HoleFeature
    Set oHole = oHoleF.Item(3)
    
    Dim oOriginal As HoleClearanceInfo
    Set oOriginal = oHole.ClearanceInfo
    
    Dim oChanged As HoleClearanceInfo
    Set oChanged = oHoleF.CreateClearanceInfo(oOriginal.FastenerStandard, oOriginal.FastenerType, "M10", oOriginal.FastenerFitType)
    oHole.ClearanceInfo = oChanged
    MsgBox (oHoleF.Item(1).ClearanceInfo.FastenerType)
End Sub

See also :

https://modthemachine.typepad.com/my_weblog/2019/07/new-apis-in-inventor-20201.html

 

Ah, it is written in the above blog that this API is added to Inventor 2020.1.

If you use Inventor 2019, it will be difficult to change the parameter...

 

=====

Freeradical

 Hideo Yamada

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 4

mostafamahmoudseddek94
Advocate
Advocate

Hi,

Thanks for your code.

yes, you are right!!, the code did not run.

But for beginner person like me, how Can I know that I need to construct a new clearance info.!!, I mean I did searching in the Inventor Programming help and no indication for this also, I used Watch window too and the type of massage error has no information.

Thanks.

0 Likes
Message 4 of 4

HideoYamada
Advisor
Advisor

Hi,

 


@mostafamahmoudseddek94 wrote:

how Can I know that I need to construct a new clearance info.!!


Let's Google!!

https://www.google.com/search?q=HoleClearanceInfo+inventor

 

Capture.PNG

 

Or ask in this forum!

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes