Update G_L property for all part files in assembly

Update G_L property for all part files in assembly

Anonymous
Not applicable
602 Views
3 Replies
Message 1 of 4

Update G_L property for all part files in assembly

Anonymous
Not applicable

I am trying to update value of G_L for every part in an assembly

 

illogic searches each part for parameter G_L and if the value = 914, then I want to update it to 950.

 

the code comes up with error 'cant find parameter G_L'

 

this is it:

 

any help?

 

Version:1.0 StartHTML:00000145 EndHTML:00003082 StartFragment:00000294 EndFragment:00003050 StartSelection:00000294 EndSelection:00000294SyntaxEditor Code Snippet

'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
 
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
     'look at only part files
     If partDoc.DocumentType = kPartDocumentObject Then

          Dim userParam As UserParameter
          For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
                If Parameter("G_L") = 914 Then
					
					Parameter("G_L") = 950
                   
                 End If
           Next
     partDoc.Update
     End If
Next

iLogicVb.UpdateWhenDone = True

 Sandy

0 Likes
Accepted solutions (1)
603 Views
3 Replies
Replies (3)
Message 2 of 4

AlexFielder
Advisor
Advisor
Accepted solution

I just re-read your OP and noticed that although you are looping through the userparameters in the correct fashion, the reason the code doesn't find and change the relevant parameter is because these lines:

If Parameter("G_L") = 914 Then
	Parameter("G_L") = 950
End If

are looking for the "G_L" parameter in the parent assembly.

You can get it to work like this:

'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
 
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
	'look at only part files
	If partDoc.DocumentType = kPartDocumentObject Then
		Dim userParam As UserParameter
		For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
			If userParam.Name = "G_L" Then
				If userParam.Expression = "914 mm" Then
					userParam.Expression = "950 mm"
				Else
					MessageBox.Show("User param is: " & userParam.Value)
				End If
			End If
'			If Parameter("G_L") = 914 Then
'				Parameter("G_L") = 950
'			End If
		Next
		partDoc.Update
	End If
Next

iLogicVb.UpdateWhenDone = True

Obviously your units will likely be different, but I think you get the idea.

 

🙂

0 Likes
Message 3 of 4

Anonymous
Not applicable

Would also like the thickness (G_T) to update depending on the (G_H) value....

 

Ive tried adding this into the code but unsuccessfully...!

 

Version:1.0 StartHTML:00000145 EndHTML:00004161 StartFragment:00000294 EndFragment:00004129 StartSelection:00000294 EndSelection:00000294SyntaxEditor Code Snippet

'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
 
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
	'look at only part files
	If partDoc.DocumentType = kPartDocumentObject Then
		Dim userParam As UserParameter
		For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
			
			If userParam.Name = "G_H" Then
				If userParam.Expression = "1165 mm" Then
					userParam.Expression = "1160.5 mm" 
				End If
			End If
			
			If "G_H" = "1160.5 mm" Then
				If userParam.Expression = "G_T"
					userParam.Expression = "10 mm"
				End If 
			End If
			
		Next
		partDoc.Update
	End If
Next

iLogicVb.UpdateWhenDone = True

Thanks,

Sandy

 

0 Likes
Message 4 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Try below iLogic code to update "G_T" value based on "G_H".

 

'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument

Dim update_GT As Boolean
update_GT = False 

'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
	'look at only part files
	If partDoc.DocumentType = kPartDocumentObject Then
		Dim userParam As UserParameter
		For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
			
			If userParam.Name = "G_H" Then
				If userParam.Expression = "1165 mm" Then
					userParam.Expression = "1160.5 mm" 
					update_GT = True 
				End If
			End If 			
		Next
		For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
			If userParam.Name = "G_T" Then
				If update_GT = True Then
 					userParam.Expression = "10 mm"
 					update_GT = False
 				End If
 			End If
		Next
		partDoc.Update
	End If
Next

iLogicVb.UpdateWhenDone = True

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network