Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
A.Acheson
in reply to: dkrenz7SLFV

Here is a rule that seems to work consistently. This rule will update the factory iPart located in either the workspace of location that is not a library and where the factory iPart is writeable. 

 

To add more iProperties just add another inputbox, sub routine call and adjust the column title requiring editing.

	 ChangeFactoryValue(oPartDoc, "Part Number", PartNo)'Adjust string value "Part Number"

Working Rule:

Sub Main
	
	Dim PartNo As String = InputBox("Prompt", "Part Number", "Default Entry")
	
	Dim Desc As String = InputBox("Prompt", "Description", "Default Entry")
	
	Dim oAssyDoc As AssemblyDocument = ThisDoc.Document

	Dim oPartoOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part")
	
	If oPartoOcc Is Nothing Then 
		Exit Sub
    ElseIf oPartoOcc.Definition.Type = ObjectTypeEnum.kPartComponentDefinitionObject
	   
	 Dim oPartDoc As PartDocument = oPartoOcc.Definition.Document
	'Adjust the inputs to the factory table
	 ChangeFactoryValue(oPartDoc, "Part Number", PartNo)'Adjust string value "Part Number"
	 ChangeFactoryValue(oPartDoc, "Description", Desc)
 
    Else
		MsgBox("Not a Part Exiting.", vbExclamation, "Occurrence Check") 
	 	Exit Sub
	End If
	oAssyDoc.Update
	
End Sub



Sub ChangeFactoryValue(oPartDoc As PartDocument, ColHeader As String, CellValue As String)

    Dim oCompDef As PartComponentDefinition 
	Dim oFactoryDoc As PartDocument

	If oPartDoc.ReferencedDocumentDescriptors.Count = 0 Then
		MsgBox("Chosen document is not a factory.", vbExclamation,"Document Check")
		Exit Sub
	Else
		oCompDef = oPartDoc.ReferencedDocumentDescriptors(1).ReferencedDocument.ComponentDefinition
	
		If oCompDef.IsiPartFactory = False Then
    		MsgBox ("Chosen document is not a factory. factory check", vbExclamation,"Document Check")
    		Exit Sub
		ElseIf oCompDef.IsiPartFactory = True
	 		oFactoryDoc = oPartDoc.ReferencedDocumentDescriptors(1).ReferencedDocument
		End If
	End If

	Dim sFileName As String = IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)
	
    Dim oFactory As iPartFactory = oCompDef.iPartFactory
 	
	Dim iRow As Integer
	For iRow = 1 To oFactory.TableRows.Count
		If oFactory.FileNameColumn.Item(iRow).Value = sFileName Then
			Exit For
		End If
	Next
    For Each oEachCol As iPartTableColumn In oFactory.TableColumns
		Try
		If oEachCol.DisplayHeading = ColHeader Then
			Try
			oEachCol.Item(iRow).Value = CellValue
			Catch
				MsgBox ("Problem updating factory, It could be in a Library and Read Only", vbExclamation,"Document Check")
			End Try
		End If
		Catch
		End Try
	Next

	oFactoryDoc.Rebuild

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan