insert part if iFeature exist

insert part if iFeature exist

martinhoos
Advocate Advocate
630 Views
6 Replies
Message 1 of 7

insert part if iFeature exist

martinhoos
Advocate
Advocate

Hi to all,

i am looking for a code that work with an assembly. If there exists a pipe with an iFeature named "LongPilot_EXT"  with Diameter Ø16 insert a specified part. I dont know how i shouldt do that.  😞

The iFeature has 4 various Diameters (but only one in each pipi) and so we have 4 various parts the we insert.

Maybe there i someone who has a code like this

Thanks alot

Regards from germany

Martin

 

 

0 Likes
Accepted solutions (1)
631 Views
6 Replies
Replies (6)
Message 2 of 7

HideoYamada
Advisor
Advisor

Hello martinhoos,

 

Here is sample code.

This code shows width of the slot iFeature.

Option Explicit

Const iFeatureTemplate = "End_mill_straight"
Const iFeatureParameterPrompt = "Enter Diameter"

Sub test()
    Dim aCompDef As AssemblyComponentDefinition
    Set aCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    Dim occ As ComponentOccurrence
    
    For Each occ In aCompDef.Occurrences
        If TypeOf occ.Definition Is PartComponentDefinition Then
            Dim pCompDef As PartComponentDefinition
            Set pCompDef = occ.Definition
            Debug.Print pCompDef.Document.DisplayName
            Dim iFt As iFeature
            For Each iFt In pCompDef.Features.iFeatures
                Dim template As String
                template = GetBaseName(iFt.iFeatureTemplateDescriptor.LastKnownSourceFileName)
                If template = iFeatureTemplate Then
                    Dim iFtInput As iFeatureInput
                    For Each iFtInput In iFt.iFeatureDefinition.iFeatureInputs
                        If TypeOf iFtInput Is iFeatureParameterInput Then
                            Dim iFtParamInput As iFeatureParameterInput
                            Set iFtParamInput = iFtInput
                            If iFtParamInput.Prompt = iFeatureParameterPrompt Then
                                MsgBox "Part : " & occ.Name & vbCr & _
                                    "Diameter : " & iFtParamInput.Value & " cm"
                            End If
                        End If
                    Next iFtInput
                End If
            Next iFt
        End If
    Next occ
End Sub

Function GetBaseName(fullPath As String)
    ' You need add the "Microsoft Scripting Runtime" to the reference setting.
    ' If you cannot use this reference with some reason, you must write a code by yourself.
    Dim objFSO As New FileSystemObject
    
    GetBaseName = objFSO.GetBaseName(fullPath)
End Function

Capture.PNG

 

The model files are attached to this message also.

This macro is stored in the Module1 of Assembly1.iam

 

If what iFeature is used is known, you can know what part should be placed.

 

Good luck!

 

=====

Freeradical

 Hideo Yamada

 

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

martinhoos
Advocate
Advocate

Hello Hideo Yamada,

thank you for the reply. I couldt not check your cad-data, because i work with Inventor 2015. Your code stopps at:

 

Dim objFSO As New FileSystemObject

 

Maybe i do not have "Microsoft Scripting Runtime"

 

it will be easier for me to get a code written with ilogic

 

thanks alot

Regards Martin

0 Likes
Message 4 of 7

martinhoos
Advocate
Advocate

Hello Hideo Yamada,

i changed only one line:  Const iFeatureTemplate = "LongPilot_EXT"

 

The code runs, but nothing happens...

 

1.JPG2.JPG

 

 

Where is my mistake?

Regards Martin

 

0 Likes
Message 5 of 7

HideoYamada
Advisor
Advisor

Try this :

MSR.png

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 6 of 7

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 


@martinhoos wrote:

Hello Hideo Yamada,

i changed only one line:  Const iFeatureTemplate = "LongPilot_EXT"

 

The code runs, but nothing happens...


You should set iFeatureParameterPrompt also.

The macro identifies the parameter by the prompt message.

InkedPrompt_LI.jpg

Set the string shown in the red circle to iFeatureParameterPrompt.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
Message 7 of 7

martinhoos
Advocate
Advocate

Hello Hideo Yamada,

thanks again for your reply. The code runs! 

Very best regards grom germany

Martin

 

0 Likes