One-click for all components

One-click for all components

deffysalfauzi
Enthusiast Enthusiast
1,041 Views
17 Replies
Message 1 of 18

One-click for all components

deffysalfauzi
Enthusiast
Enthusiast

Please help.

 

I have many structural parts in an assembly/subassembly file. How to activate the code for each part in the assembly/subassembly and update it every time the size changes.

 

In the future, I hope this code can also be implemented for all structural parts & sheet metal in assembly.

 

'Structural shapes, i.e : Angle Bars
iProperties.Value("Custom", "Height") = Round(G_H,0)
iProperties.Value("Custom", "Thickness") = Round(G_T,0)
iProperties.Value("Custom", "Length") = Round(G_L,0)
iProperties.Value("Project", "Description") = "=Angle Bar - <Material>, <Height>x<Height>x<Thickness> x <Length> mm"

'Sheet Metal
iProperties.Value("Custom", "Thickness") = Round(Thickness,1)
iProperties.Value("Custom", "Length") = Round(SheetMetal.FlatExtentsLength,0)
iProperties.Value("Custom", "Width") = Round(SheetMetal.FlatExtentsWidth, 0)
iProperties.Value("Custom", "Weight") = Round(iProperties.Mass, 2)
iProperties.Value("Project", "Description") = "=<Material>, <Thickness> x <Length> x <Width> mm"

 

0 Likes
1,042 Views
17 Replies
Replies (17)
Message 2 of 18

AndrewHumiston
Advocate
Advocate

are you asking to do a mass update of all parts in an assembly, targeting those specific custom iproperties?

 

can you attach a sample file of a pack and go, with a few items of each type in the file for testing pleases.

0 Likes
Message 3 of 18

daltonNYAW9
Advocate
Advocate

Instead of creating custom iproperties for "Sheet metal width" you could just use the default ones
<Sheet Metal Width>, <Sheet Metal Area>, <Flat Pattern Area>
Also, you could just add the "G_H", etc to your custom iproperties without making new values.
Try this: (minimum testing)

Dim oADoc As AssemblyDocument = ThisDoc.Document
For Each oPartDoc As PartDocument In oADoc.AllReferencedDocuments.OfType(Of PartDocument)
	If oADoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oPartDoc).Count = 0 Then Continue For
	
	If oPartDoc.PropertySets.Count = 6
		'custom content center part
		If oPartDoc.PropertySets("ContentCenter")("IsCustomPart").Value = True


			'create family property or add to cc template table
			'add family name as custom property
			Dim familyName As String = oPartDoc.PropertySets("Content Library Component Properties")("Family").Value
			Dim oFamilyProp As Inventor.Property
			Try
				oFamilyProp = oPartDoc.PropertySets(4).Item("Family")
			Catch
				oFamilyProp = oPartDoc.PropertySets(4).Add("", "Family")
			End Try

			'set family value
			Select Case familyName
				Case "ANSI AISC (Square)"
					oFamilyProp.Value = "Angle Bar"
				Case "angle"

			End Select

			'get all parameters you want displayed as custom properties
			Dim oParamG_H As Inventor.Parameter = oPartDoc.ComponentDefinition.Parameters.Item("G_H")
			Dim oParamG_T As Inventor.Parameter = oPartDoc.ComponentDefinition.Parameters.Item("G_T")
			Dim oParamG_L As Inventor.Parameter = oPartDoc.ComponentDefinition.Parameters.Item("G_L")
			For Each item As Inventor.Parameter In {oParamG_H, oParamG_T, oParamG_L }
				With item
					.ExposedAsProperty = True
					.CustomPropertyFormat.Units = "mm"
					.CustomPropertyFormat.ShowUnitsString = True
					.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
				End With
			Next
		
		'update description
		oPartDoc.PropertySets(3)("Description").Value = "=<Family> - <Material>, <Height>x<Height>x<Thickness> x <Length> mm"
		End If
	ElseIf oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		'sheet metal part
		'add thickness to custom properties
		Dim oParamThick As Inventor.Parameter = oPartDoc.ComponentDefinition.Parameters.Item("Thickness")
		With oParamThick
			.ExposedAsProperty = True
			.CustomPropertyFormat.Units = "mm"
			.CustomPropertyFormat.ShowUnitsString = False
			.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
		End With

		'update rounding of sheet metal lengths
		oPartDoc.UnitsOfMeasure.LengthDisplayPrecision = 0
		oPartDoc.Rebuild

		'add weight property
		Dim oMassProp As Inventor.Property
		Try
			oMassProp = oPartDoc.PropertySets(4).Item("Weight")
			oMassProp.Value = Round(oPartDoc.ComponentDefinition.MassProperties.Mass, 2)
		Catch
			oMassProp = oPartDoc.PropertySets(4).Add("", "Weight")
			oMassProp.Value = Round(oPartDoc.ComponentDefinition.MassProperties.Mass, 2)
		End Try

		'update description
		oPartDoc.PropertySets(3)("Description").Value = "=<Material>, <Thickness> x <Sheet Metal Length> x <Sheet Metal Width>"
	End If
Next
0 Likes
Message 4 of 18

deffysalfauzi
Enthusiast
Enthusiast

@AndrewHumiston please check the picture below, thank you.

@daltonNYAW9 This is the result of the code you created :

 

Spoiler

Screenshot 2024-07-19 233939.pngScreenshot 2024-07-19 234004.pngScreenshot 2024-07-19 234046.pngScreenshot 2024-07-19 234104.png

 

 

This is the expected result (for Rules or External Rules) :

It's very tiring, if you create 1 rule for each structural part with hundreds of parts, so I expect that with 1 rule at the top level assembly I can create a custom iProperties & Project Description.

Screenshot 2024-07-20 000645.png

 

The code I used for 1 file Angle Bars : 

 

'Structural shapes, i.e : Angle Bars
iProperties.Value("Custom", "Height") = Round(G_H,0)
iProperties.Value("Custom", "Thickness") = Round(G_T,0)
iProperties.Value("Custom", "Length") = Round(G_L,0)
iProperties.Value("Project", "Description") = "=Angle Bar - <Material>, <Height>x<Height>x<Thickness> x <Length> mm"

 

Screenshot 2024-07-19 235553.pngScreenshot 2024-07-19 235623.png

 

The code I used for 1 sheet metal :

 

'Sheet Metal
iProperties.Value("Custom", "Thickness") = Round(Thickness,1)
iProperties.Value("Custom", "Length") = Round(SheetMetal.FlatExtentsLength,0)
iProperties.Value("Custom", "Width") = Round(SheetMetal.FlatExtentsWidth, 0)
iProperties.Value("Custom", "Weight") = Round(iProperties.Mass, 2)
iProperties.Value("Project", "Description") = "=<Material>, <Thickness> x <Length> x <Width> mm"

 

Screenshot 2024-07-19 235734.pngScreenshot 2024-07-19 235758.png

0 Likes
Message 5 of 18

daltonNYAW9
Advocate
Advocate

@deffysalfauzi
You will have to develop some of this yourself. The case statement is meant to filled out with all of the content center family names. You could also edit your cc directly to have names such as "Angle Bar" to add to the iproperties.

Change the line that changes the description to this:
You will need to add "G_W" as well for uneven angles/tube in the future

oPartDoc.PropertySets(3)("Description").Value = "=<Family> - <Material>, <G_H>x<G_H>x<G_T> x <G_L> mm"

 
The sheet metal one probably didn't work because there wasn't already a flat pattern. You could add some lines to create a flat pattern, and a temp view to maintain the assembly environment.
Something like this:

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim tempview As Inventor.View = oADoc.Views.Add
tempview.Activate

'for loop
'sheet metals

'create flat pattern
	If oPartDoc.ComponentDefinition.HasFlatPattern = False
		Try
			oSMCD.Unfold
			oSMCD.FlatPattern.ExitEdit
		Catch
			Continue For
		End Try
	End If


'next

tempview.Close



0 Likes
Message 6 of 18

daltonNYAW9
Advocate
Advocate

Heres a revised version:

Dim oADoc As AssemblyDocument = ThisDoc.Document

Dim tempview As Inventor.View = oADoc.Views.Add
tempview.Activate

For Each oPartDoc As PartDocument In oADoc.AllReferencedDocuments.OfType(Of PartDocument)
	If oADoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oPartDoc).Count = 0 Then Continue For

	If oPartDoc.PropertySets.Count = 6
		'custom content center part
		If oPartDoc.PropertySets("ContentCenter")("IsCustomPart").Value = True


			'create family property or add to cc template table
			'add family name as custom property
			Dim familyName As String = oPartDoc.PropertySets("Content Library Component Properties")("Family").Value
			Dim oFamilyProp As Inventor.Property
			Try
				oFamilyProp = oPartDoc.PropertySets(4).Item("Family")
			Catch
				oFamilyProp = oPartDoc.PropertySets(4).Add("", "Family")
			End Try

			'set family value
			Select Case familyName
				Case "ANSI AISC (Square)"
					oFamilyProp.Value = "Angle Bar"
				Case "angle"

			End Select

			'get all parameters you want displayed as custom properties
			Dim olist As New List(Of Inventor.Parameter)
			Dim oParamG_H As Inventor.Parameter
			Dim oParamG_W As Inventor.Parameter
			Dim oParamG_T As Inventor.Parameter
			Dim oParamG_L As Inventor.Parameter
			Try
				oParamG_H = oPartDoc.ComponentDefinition.Parameters.Item("G_H")
				olist.Add(oParamG_H)
			Catch : End Try : Try
				oParamG_W = oPartDoc.ComponentDefinition.Parameters.Item("G_W")
				olist.Add(oParamG_W)
			Catch : End Try : Try
				oParamG_T = oPartDoc.ComponentDefinition.Parameters.Item("G_T")
				olist.Add(oParamG_T)
			Catch : End Try : Try
				oParamG_L = oPartDoc.ComponentDefinition.Parameters.Item("G_L")
				olist.Add(oParamG_L)
			Catch : End Try
			For Each item As Inventor.Parameter In olist
				With item
					.ExposedAsProperty = True
					.CustomPropertyFormat.Units = "mm"
					.CustomPropertyFormat.ShowUnitsString = False
					.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
				End With
			Next

			'update description
			oPartDoc.PropertySets(3)("Description").Value = "=<Family> - <Material>, <G_H> x <G_H> x <G_T> x <G_L> mm"
		End If
	ElseIf oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		'sheet metal part
		Dim oSMCD As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
		If oSMCD.HasFlatPattern = False
			Try
				oSMCD.Unfold
				oSMCD.FlatPattern.ExitEdit
			Catch
				Continue For
			End Try

		End If
		'add thickness to custom properties
		Dim oParamThick As Inventor.Parameter = oPartDoc.ComponentDefinition.Parameters.Item("Thickness")
		With oParamThick
			.ExposedAsProperty = True
			.CustomPropertyFormat.Units = "mm"
			.CustomPropertyFormat.ShowUnitsString = False
			.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
		End With

		'update rounding of sheet metal lengths
		oPartDoc.UnitsOfMeasure.LengthDisplayPrecision = 0
		oPartDoc.Rebuild

		'add weight property
		Dim oMassProp As Inventor.Property
		Try
			oMassProp = oPartDoc.PropertySets(4).Item("Weight")
			oMassProp.Value = Round(oPartDoc.ComponentDefinition.MassProperties.Mass, 2)
		Catch
			oMassProp = oPartDoc.PropertySets(4).Add("", "Weight")
			oMassProp.Value = Round(oPartDoc.ComponentDefinition.MassProperties.Mass, 2)
		End Try

		'update description
		oPartDoc.PropertySets(3)("Description").Value = "=<Material>, <Thickness> x <Sheet Metal Length> x <Sheet Metal Width>"
	End If
Next

tempview.Close
0 Likes
Message 7 of 18

deffysalfauzi
Enthusiast
Enthusiast

@daltonNYAW9 Thank you, I'm very happy for your respons.

 

This is the result with the code you created.

The ‘<Family>’ does not appear in the description (structural shapes)

Screenshot 2024-07-20 081404.png

.

.

Thickness, Length & Height (=G_H = Width in BoM) does not appear in the custom

Screenshot 2024-07-20 081454.png

.

.

Perfect, but can the thickness be made x,x leading zero, ie :

0,5 --> 0,5

1,0 --> 1

1,5 --> 1,5

Screenshot 2024-07-20 083257.png

.

.

I need this all : Thickness, Length & Width

Screenshot 2024-07-20 083018.png

.

.

This is the reason why I need Custom iProperties earlier.

Screenshot 2024-07-20 083056.png

.

.

Thank you for helping, I was assisted by Google Translate, and I hope you can create the code.

 

0 Likes
Message 8 of 18

daltonNYAW9
Advocate
Advocate

The best way to do this would be to edit your content center tables for the structural shapes you want. And add a line that maps to the "Description" property. This would require less coding.
ex:

daltonNYAW9_1-1721651456279.png

Then you could manually add the custom iproperties to the template and upload it back to content center

daltonNYAW9_2-1721651778478.png

Then link them to your custom iproperties your custom iproperties

daltonNYAW9_3-1721651930824.png

 

Finally, upload the template back to your content center

daltonNYAW9_4-1721652005231.png


You will likely need to have code for updating the sheet metal parts, but doing this first would be preferable.

Message 9 of 18

deffysalfauzi
Enthusiast
Enthusiast

Wow... straight to the content center. Amazing.

Screenshot (7).png

 

But, how to "upload the template back to content center", Can you provide the steps? I don’t know how to do it.

0 Likes
Message 10 of 18

daltonNYAW9
Advocate
Advocate

There are some good youtube videos on it.
Its been a while since I've messed with it, but here are some notable problems we had:
1. Create a custom configurable library and copy the ones you want changed there
2. We had a problem with the table parameters updating with model changes, especially for the length paramters 0,001. So we made the length a custom iproperty and made the descreption an equation

daltonNYAW9_0-1721667155561.png

3. Keep the family properties... > family description field blank

daltonNYAW9_1-1721667250468.png

Good luck with this haha

Message 11 of 18

deffysalfauzi
Enthusiast
Enthusiast

Amazing, I need your help, one more time. Almost done.

 

Can you fix the code below, especially in the sheet metal section :

'https://forums.autodesk.com/t5/inventor-programming-ilogic/one-click-for-all-components/m-p/12908444...

Dim oADoc As AssemblyDocument = ThisDoc.Document

Dim tempview As Inventor.View = oADoc.Views.Add
tempview.Activate

For Each oPartDoc As PartDocument In oADoc.AllReferencedDocuments.OfType(Of PartDocument)
If oADoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oPartDoc).Count = 0 Then Continue For

If oPartDoc.PropertySets.Count = 6
'custom content center part
If oPartDoc.PropertySets("ContentCenter")("IsCustomPart").Value = True

'get all parameters you want displayed as custom properties
Dim olist As New List(Of Inventor.Parameter)
Dim oParamG_H As Inventor.Parameter
Dim oParamG_W As Inventor.Parameter
Dim oParamG_T As Inventor.Parameter
Dim oParamG_L As Inventor.Parameter
Try
oParamG_H = oPartDoc.ComponentDefinition.Parameters.Item("G_H")
olist.Add(oParamG_H)
Catch : End Try : Try
oParamG_W = oPartDoc.ComponentDefinition.Parameters.Item("G_W")
olist.Add(oParamG_W)
Catch : End Try : Try
oParamG_T = oPartDoc.ComponentDefinition.Parameters.Item("G_T")
olist.Add(oParamG_T)
Catch : End Try : Try
oParamG_L = oPartDoc.ComponentDefinition.Parameters.Item("G_L")
olist.Add(oParamG_L)
Catch : End Try
For Each item As Inventor.Parameter In olist
With item
.ExposedAsProperty = True
.CustomPropertyFormat.Units = "mm"
.CustomPropertyFormat.ShowUnitsString = False
.CustomPropertyFormat.ShowLeadingZeros = True
.CustomPropertyFormat.ShowTrailingZeros = False
.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kOneDecimalPlacePrecision
End With
Next

'update description
oPartDoc.PropertySets(3)("Description").Value = "=<Family> - <Material> - <G_H> x <G_W> x <G_T> - <G_L> mm"
End If

ElseIf oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
'sheet metal part
Dim oSMCD As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
If oSMCD.HasFlatPattern = False
Try
oSMCD.Unfold
oSMCD.FlatPattern.ExitEdit
Catch
Continue For
End Try

End If

'Sheet Metal custom properties :
'Thickness = G_T
'SheetMetal Flat Extents Height = G_H
'SheetMetal Flat Extents Width = G_W
'example in project description : Steel - 1,5 x 100 x 105,5 mm

add thickness To custom properties
Dim oParamThick As Inventor.Parameter = oPartDoc.ComponentDefinition.Parameters.Item("Thickness")
With oParamThick
.ExposedAsProperty = True
.CustomPropertyFormat.Units = "mm"
.CustomPropertyFormat.ShowUnitsString = False
.CustomPropertyFormat.ShowLeadingZeros = True
.CustomPropertyFormat.ShowTrailingZeros = False
.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kOneDecimalPlacePrecision
End With
Next
'update rounding of sheet metal lengths
oPartDoc.UnitsOfMeasure.LengthDisplayPrecision = 0
oPartDoc.Rebuild

'add weight property
Dim oMassProp As Inventor.Property
Try
oMassProp = oPartDoc.PropertySets(4).Item("Weight")
oMassProp.Value = Round(oPartDoc.ComponentDefinition.MassProperties.Mass, 2)
Catch
oMassProp = oPartDoc.PropertySets(4).Add("", "Weight")
oMassProp.Value = Round(oPartDoc.ComponentDefinition.MassProperties.Mass, 2)
End Try

'update description
oPartDoc.PropertySets(3)("Description").Value = "=<Material> - <G_T> x <G_W> x <G_H> mm"
End If
Next

tempview.Close

0 Likes
Message 12 of 18

deffysalfauzi
Enthusiast
Enthusiast

“Please, how do I export sheet metal extent to custom properties?”

0 Likes
Message 13 of 18

AndrewHumiston
Advocate
Advocate

are you using ilogic? 

 

you need to first set up  a rule to export the vaules to a parameter then, you'll check the 'export' option for each parameter.

 

here is the rule i use in sheetmetal files to get my exported extents values:

Imports Inventor.UnitsTypeEnum
 
Dim oPartDoc As Document
Dim oPartCompDef As PartComponentDefinition
Dim oParams As Parameters
Dim oUserParams As UserParameters
 
oPartDoc = ThisDoc.Document
oPartCompDef = oPartDoc.ComponentDefinition
oParams = oPartCompDef.Parameters
oUserParams = oParams.UserParameters
 
Try
oTester = oUserParams("extents_width")
Catch
oUserParams.AddByExpression("extents_width", "1", kInchLengthUnits)
Parameter.Param("extents_width").ExposedAsProperty = True
Parameter.Param("extents_width").Expression = SheetMetal.FlatExtentsWidth
End Try
 
Try
oTester = oUserParams("extents_length")
Catch
oUserParams.AddByExpression("extents_length", "1", kInchLengthUnits)
Parameter.Param("extents_length").ExposedAsProperty = True
Parameter.Param("extents_length").Expression = SheetMetal.FlatExtentsLength
End Try
 
extents_width = SheetMetal.FlatExtentsWidth
extents_length = SheetMetal.FlatExtentsLength
 
my Event triggers:
AMHumiston_0-1722516067597.png

Exported Values:

AMHumiston_1-1722516095720.png

 

i hope this helps!

0 Likes
Message 14 of 18

deffysalfauzi
Enthusiast
Enthusiast

The problem is, I have over 500 IPT and IAM files (frames, sheet metal parts, and assemblies). It seems like it would take a significant amount of time to edit each sheet metal part individually. Therefore, I need to find a way to automate this process using iLogic to shorten the time required. I apologize if this seems complex. Thank you for your efforts in assisting me.

0 Likes
Message 15 of 18

AndrewHumiston
Advocate
Advocate

Easy Fix!

 

use your event trigger and store the rule externally.

 

AndrewHumiston_0-1722519944012.png

then any part you open will be wrapped up with the extents information

0 Likes
Message 16 of 18

daltonNYAW9
Advocate
Advocate

@deffysalfauzi 
Are you just wanting the the custom iproperties to have the correct names?
You can use a try/catch to try and create new custom iproperties

'thickness -> G_T
Try
	oMassProp = oPartDoc.PropertySets(4).Item("G_T")
	oMassProp.Value = Round(oPartDoc.ComponentDefinition.Thickness.Value, 1)

Catch
	oMassProp = oPartDoc.PropertySets(4).Add("", "G_T")
	oMassProp.Value = Round(oPartDoc.ComponentDefinition.Thickness.Value, 1)

End Try

'thick
Try
	oTProp = oPartDoc.PropertySets(4).Item("Thick")
	oTProp.Value = "=<G_T>"
Catch
	oTProp = oPartDoc.PropertySets(4).Add("", "Thick")
	oTProp.Value = "=<G_T>"
End Try

'width
Try
	oMassProp = oPartDoc.PropertySets(4).Item("G_W")
	oMassProp.Value = Round(oPartDoc.ComponentDefinition.FlatPattern.Width, 0)
Catch
	oMassProp = oPartDoc.PropertySets(4).Add("", "G_W")
	oMassProp.Value = Round(oPartDoc.ComponentDefinition.FlatPattern.Width, 0)
End Try

 

You could bypass a lot of coding if you changed the template file to include "Thickness" parameter and utilize the hidden custom iproperty <Sheet Metal Width>. It would just add an extra "mm" to ur description format

0 Likes
Message 17 of 18

daltonNYAW9
Advocate
Advocate

@AndrewHumiston 
I havn't messed with global rules much, but u still need to add the "trigger" for every part, right?

0 Likes
Message 18 of 18

AndrewHumiston
Advocate
Advocate

Afternoon,

 

you can add per file, or per file type, see attached screen shot. I hope this helps.

 

AndrewHumiston_0-1722885122031.png

 

0 Likes