check export parameter box from main assembly to all parts

check export parameter box from main assembly to all parts

Anonymous
Not applicable
1,457 Views
8 Replies
Message 1 of 9

check export parameter box from main assembly to all parts

Anonymous
Not applicable

I want to check the export parameter box in all part of my weldment frame assembly. I have square tube of different length and same size. want to export depth, width, and thickness parameter for all tube in one operation and after that I also want to change custom parameter properties format of all parts. I want to do it from top assembly without opening any part.

 

Is there any way to do it? I can't open each part every time and export parameter and change custom properties for all the parts. It will take too much time for larger assemblies.

 

Thanks in advance.

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

HideoYamada
Advisor
Advisor

Hello pds9,

 

Open weld doc and run this vba code.

The parameters named "G_W", "G_H" or "G_T" in all sub part will be checked for export.

Option Explicit

Public Sub SetExportAllSubPart()
    Dim ParamNamesToExport() As Variant
    ParamNamesToExport = Array("G_W", "G_H", "G_T")
    
    Dim thisDoc As AssemblyDocument
    Set thisDoc = ThisApplication.ActiveEditDocument
    
    Dim occ As ComponentOccurrence
    
    For Each occ In thisDoc.ComponentDefinition.Occurrences
        If TypeOf occ.Definition Is PartComponentDefinition Then
            Dim partCompDef As PartComponentDefinition
            Set partCompDef = occ.Definition
            Dim param As Parameter
            For Each param In partCompDef.Parameters
                SetExport param, ParamNamesToExport
            Next
        End If
    Next
End Sub

Private Sub SetExport(param As Parameter, ByRef names() As Variant)
    Dim name As Variant
    For Each name In names
        If param.name = name And param.ParameterType = kUserParameter And param.ExposedAsProperty = False Then
            param.ExposedAsProperty = True
            Exit For
        End If
    Next
End Sub

I hope this code will help you.

 

=====

Freeradical

 Hideo Yamada

 

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

Anonymous
Not applicable

Thanks Hideo for reply,

 

But after adding code inventor shows Sub Main error. Attached is the error image.

 

Can you please show me how to fix this error because I am new to inventor iLogic, so do not know much about it.

 

Thank You.

0 Likes
Message 4 of 9

HideoYamada
Advisor
Advisor

Hello pds9,

 

Are you run with iLogic?

If so, try run the code with VBA.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 5 of 9

Anonymous
Not applicable

Thanks Hideo the code works in VBA.

 

Can you please add additional lines to this code for change custom parameter format. Like on and off trailing and leading zeros and some like that.

 

For me I want to change the trailing zeros check mark off for all parameters. So, I only get integer dimension values when it is applicable.

 

Thank you for this code.

0 Likes
Message 6 of 9

HideoYamada
Advisor
Advisor
Accepted solution

Hello pds9,

 

Replace Sub SetExport() with this :

Private Sub SetExport(param As Parameter, ByRef names() As Variant)
    Dim name As Variant
    
    For Each name In names
        If param.name = name And param.ParameterType = kUserParameter And param.ExposedAsProperty = False Then
            param.ExposedAsProperty = True
            '
            param.CustomPropertyFormat.ShowUnitsString = True
            param.CustomPropertyFormat.ShowLeadingZeros = True
            param.CustomPropertyFormat.ShowTrailingZeros = False
            '
            Exit For
        End If
    Next
End Sub

Does this code work fine?

 

=====

Freeradical

 Hideo Yamada

 

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

Anonymous
Not applicable

Hi Hideo,

 

Code now works fine with everything. Problem solved.

 

Thank you for your support.

0 Likes
Message 8 of 9

jpdemers
Explorer
Explorer

Hi,

I'm new to Ilogic and I'm trying to use this vba code to export the "Thickness" FX parameter but it doesn't work.

Well, I don't really know how to do it.

I'm not sure I use VBA the right way.

Can you help me out?

Thanks.

0 Likes
Message 9 of 9

HideoYamada
Advisor
Advisor

Hello,

 


@jpdemers wrote:

Hi,

I'm new to Ilogic and I'm trying to use this vba code to export the "Thickness" FX parameter but it doesn't work.

Well, I don't really know how to do it.

I'm not sure I use VBA the right way.

Can you help me out?

Thanks.


Try this rule :

option Explicit on
Imports System.Collections.Generic
Public Sub Main
	Dim paramNamesToExport = New List(Of String) From {"Thickness"}

	For Each occ As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
		If TypeOf occ.Definition Is PartComponentDefinition Then
			Dim partCompDef As PartComponentDefinition = occ.Definition
			For Each param In partCompDef.Parameters
				SetExport(param, paramNamesToExport)
			Next param
		End If		
	Next occ
End Sub

Private Sub SetExport(param As Parameter, names As List(Of String))
	For Each name In names
		If param.Name = name And param.ParameterType = ParameterTypeEnum.kUserParameter And param.ExposedAsProperty = False Then
			param.ExposedAsProperty = True
'			MessageBox.Show(name)
			Exit For
		End If
	Next name
End Sub

 

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