adding value to custom iproperties in parts from assembly document

adding value to custom iproperties in parts from assembly document

sachin_kumar6CZM2
Contributor Contributor
387 Views
7 Replies
Message 1 of 8

adding value to custom iproperties in parts from assembly document

sachin_kumar6CZM2
Contributor
Contributor

Hello Everyone,

I have to add certain custom iproperties to my part. All parts are sheet metals( comprises of 3mm and 4mm Aluminium sheets) and are assembled in an assembly. I don't want to open each part file and add the value /run the rule. I am looking for a i logic rule which can be run from the assembly file and will add the required custom i properties value to the appropriate parts. below is the code I created, but It is not working. Could anyone please help me to crack this.

Sub Main
'Gets the Active Document
oDoc = ThisDoc.Document

'Saves this document
oDoc.Save

'Checks if the active document is an assembly
If oDoc.DocumentType = kAssemblyDocumentObject
	'Gets the assembly occurrences
	Dim oOccs As ComponentOccurrences
	oOccs = oDoc.ComponentDefinition.Occurrences
	'Call the subprocedure to traverse the assembly
	Call TraverseAssembly(oOccs)
End If

End Sub

'***************
Public Sub TraverseAssembly(oOccs As ComponentOccurrences)
 
  Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
	
  Select Case Thickness
	  
  Case 3
	  If iProperties.Value("Project", "Description") = "3mm Aluminium Coping" Then
	  
	  
   iProperties.Value("Custom", "Finish Spec Code") = "F11A"
iProperties.Value("Custom", "Finish Specification") = "RAL 7022 Umbra Grey  - 30% Gloss YL280F"
iProperties.Value("Custom", "Material definition") = "MP101 - G0030"
iProperties.Value("Project", "Checked By") = "NAC"
iProperties.Value("Project", "Revision Number") = "00"
iProperties.Value("Project", "Project")="56U0XXXX-BA"

	Else
	iProperties.Value("Custom", "Finish Spec Code") = "F01Z"
iProperties.Value("Custom", "Finish Specification") = "MILL"
iProperties.Value("Custom", "Material definition") = "MP101 - G0030"
iProperties.Value("Project", "Checked By")= "NAC"
iProperties.Value("Project", "Revision Number") = "00"
iProperties.Value("Project", "Project")="56U0XXXX-BA"	
		
		End If
		
	Case 4
		
			iProperties.Value("Custom", "Finish Spec Code") = "F01Z"
iProperties.Value("Custom", "Finish Specification") = "MILL"
iProperties.Value("Custom", "Material definition") = "MP101 - G0040"
iProperties.Value("Project", "Checked By") = "NAC"
iProperties.Value("Project", "Revision Number") = "00"
iProperties.Value("Project", "Project") = "56U0XXXX-BA"
iProperties.Value("Project", "Description")="4mm Aluminium Strap"

End Select



		If oOcc.DefinitionDocumentType = kAssemblyDocumentObject
			Call TraverseAssembly(oOcc.SubOccurrences)
		End If
	
Next
End Sub 

 

0 Likes
Accepted solutions (1)
388 Views
7 Replies
Replies (7)
Message 2 of 8

clutsa
Collaborator
Collaborator
Are you getting an error or just not seeing the results you expect?
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 8

sachin_kumar6CZM2
Contributor
Contributor

Hi@clutsa

I am not getting any error in Ilogic compiler. But not seeing any results. Its like the rule is doing nothing

 

0 Likes
Message 4 of 8

clutsa
Collaborator
Collaborator

Looks like you just need to add the sub component to the iProperties...

 

Sub Main
'Gets the Active Document
oDoc = ThisDoc.Document

'Saves this document
oDoc.Save

'Checks if the active document is an assembly
If oDoc.DocumentType = kAssemblyDocumentObject
	'Gets the assembly occurrences
	Dim oOccs As ComponentOccurrences
	oOccs = oDoc.ComponentDefinition.Occurrences
	'Call the subprocedure to traverse the assembly
	Call TraverseAssembly(oOccs)
End If

End Sub

'***************
Public Sub TraverseAssembly(oOccs As ComponentOccurrences)
 
  Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
	'Logger.Debug("Thickness = {0}", Parameter(oOcc.Name, "Thickness"))
  Select Case Parameter(oOcc.Name, "Thickness")
	  
  Case 3
	  If iProperties.Value(oOcc.Name, "Project", "Description") = "3mm Aluminium Coping" Then
	  
	  
   iProperties.Value(oOcc.Name, "Custom", "Finish Spec Code") = "F11A"
iProperties.Value(oOcc.Name,"Custom", "Finish Specification") = "RAL 7022 Umbra Grey  - 30% Gloss YL280F"
iProperties.Value(oOcc.Name,"Custom", "Material definition") = "MP101 - G0030"
iProperties.Value(oOcc.Name,"Project", "Checked By") = "NAC"
iProperties.Value(oOcc.Name,"Project", "Revision Number") = "00"
iProperties.Value(oOcc.Name,"Project", "Project")="56U0XXXX-BA"

	Else
	iProperties.Value(oOcc.Name,"Custom", "Finish Spec Code") = "F01Z"
iProperties.Value(oOcc.Name,"Custom", "Finish Specification") = "MILL"
iProperties.Value(oOcc.Name,"Custom", "Material definition") = "MP101 - G0030"
iProperties.Value(oOcc.Name,"Project", "Checked By")= "NAC"
iProperties.Value(oOcc.Name,"Project", "Revision Number") = "00"
iProperties.Value(oOcc.Name,"Project", "Project")="56U0XXXX-BA"	
		
		End If
		
	Case 4
		
			iProperties.Value(oOcc.Name,"Custom", "Finish Spec Code") = "F01Z"
iProperties.Value(oOcc.Name,"Custom", "Finish Specification") = "MILL"
iProperties.Value(oOcc.Name,"Custom", "Material definition") = "MP101 - G0040"
iProperties.Value(oOcc.Name,"Project", "Checked By") = "NAC"
iProperties.Value(oOcc.Name,"Project", "Revision Number") = "00"
iProperties.Value(oOcc.Name,"Project", "Project") = "56U0XXXX-BA"
iProperties.Value(oOcc.Name,"Project", "Description")="4mm Aluminium Strap"

End Select



		If oOcc.DefinitionDocumentType = kAssemblyDocumentObject
			Call TraverseAssembly(oOcc.SubOccurrences)
		End If
	
Next
End Sub 

Edit I also changed what the select case was looking at to make sure you're looking at the sub component.

Have you ever used the logger.debug to return variables so you can interpret what the code is passing?

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 5 of 8

sachin_kumar6CZM2
Contributor
Contributor

Thanku for your help.

 

but i am getting the following error

sachin_kumar6CZM2_0-1728655309514.png

Where, "A1925B:1" is a subassembly which comprises of 3mm and 4mm Aluminium sheet part files .

0 Likes
Message 6 of 8

jnowel
Advocate
Advocate
Accepted solution

mine maybe is a longer route, but i have added some checks if the component occurrence is a sheetmetal or not.
Also, it can add a custom iproperty if it is missing/not yet defined yet in the part

Sub Main
	
'Gets the Active Document
oDoc = ThisApplication.ActiveDocument

'Saves this document
oDoc.Save

'Checks if the active document is an assembly
If oDoc.DocumentType = kAssemblyDocumentObject
	'Gets the assembly occurrences
	Dim oOccs As ComponentOccurrences
	oOccs = oDoc.ComponentDefinition.Occurrences
	'Call the subprocedure to traverse the assembly
	Call TraverseAssembly(oOccs)
End If

End Sub

'***************
Public Sub TraverseAssembly(oOccs As ComponentOccurrences)
 
	Dim oOcc As ComponentOccurrence
	
	For Each oOcc In oOccs
		
		If oOcc.Suppressed Then Continue For 'skip suppressed componenet occurrences
		
		'This needs to be before the Select Case so you can skip the
		'rules for the parts
		If oOcc.DefinitionDocumentType = kAssemblyDocumentObject
			Call TraverseAssembly(oOcc.SubOccurrences)
			Continue For 
		End If

		Dim oOccDoc As Document
		oOccDoc = oOcc.Definition.Document

		If Not (oOccDoc.DocumentType = kPartDocumentObject And oOccDoc.IsModifiable) Then Continue For 'check if part and is modifiable
		If Not (oOccDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then Continue For 'check if sheetmetal part
		
		Dim oSheetMetalCompDef As SheetMetalComponentDefinition
		oSheetMetalCompDef = oOccDoc.ComponentDefinition

		Dim oThickness As DoubleForEquals
		oThickness = CDbl(oSheetMetalCompDef.Thickness.Value) * 10 'get value and convert from cm to mm
			
		Dim oDesProp As PropertySet
		oDesProp = oOccDoc.PropertySets.Item("Design Tracking Properties")
		
		Dim oInvSumProp As PropertySet
		oInvSumProp = oOccDoc.PropertySets.Item("Inventor Summary Information")

		Select Case oThickness
			
			Case 3 'mm

				If oDesProp.Item("Description").Value = "3mm Aluminium Coping" Then
					
					Call Set_CustomiProp(oOccDoc, "Finish Spec Code", "F11A")
					Call Set_CustomiProp(oOccDoc, "Finish Specification", "RAL 7022 Umbra Grey  - 30% Gloss YL280F")
					Call Set_CustomiProp(oOccDoc, "Material definition", "MP101 - G0030")
					
					oInvSumProp.Item("Revision Number").Value = "00"
					
					oDesProp.Item("Checked By").Value = "NAC"
					oDesProp.Item("Project").Value = "56U0XXXX-BA"
					
				Else
					
					Call Set_CustomiProp(oOccDoc, "Finish Spec Code", "F01Z")
					Call Set_CustomiProp(oOccDoc, "Finish Specification", "MILL")
					Call Set_CustomiProp(oOccDoc, "Material definition", "MP101 - G0030")
					
					oInvSumProp.Item("Revision Number").Value = "00"
					
					oDesProp.Item("Checked By").Value = "NAC"
					oDesProp.Item("Project").Value =  "56U0XXXX-BA"
									
				End If
				
			Case = 4 'mm
				
				Call Set_CustomiProp(oOccDoc, "Finish Spec Code", "F01Z")
				Call Set_CustomiProp(oOccDoc, "Finish Specification", "MILL")
				Call Set_CustomiProp(oOccDoc, "Material definition", "MP101 - G0040")
				
				oInvSumProp.Item("Revision Number").Value = "00"
				
				oDesProp.Item("Checked By").Value = "NAC"
				oDesProp.Item("Project").Value = "56U0XXXX-BA"
				oDesProp.Item("Description").Value =   "4mm Aluminium Strap"
								
		End Select
				
	Next
	
End Sub 

Sub Set_CustomiProp(oDoc As Document, iPropName As String, iPropVal As String) 

	Try
		oDoc.PropertySets.Item("User Defined Properties").Item(iPropName).Value = iPropVal
	Catch
		 oDoc.PropertySets.Item("User Defined Properties").Add(iPropVal, iPropName)
	End Try
	
End Sub
	

 

 

0 Likes
Message 7 of 8

clutsa
Collaborator
Collaborator

Sorry I’m working off my cellphone right now because our network is down.

move your check for if it’s an assembly up before your select case and run the select case as an else .

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 8 of 8

sachin_kumar6CZM2
Contributor
Contributor

@jnowel , Thanku very much.. it worked perfectly.. 

learned a lot from your code.

 

0 Likes