Selecting Parts in Assembly and Filling in IProperties

Selecting Parts in Assembly and Filling in IProperties

ddimarco6AWM9
Contributor Contributor
1,022 Views
3 Replies
Message 1 of 4

Selecting Parts in Assembly and Filling in IProperties

ddimarco6AWM9
Contributor
Contributor

Hello,

I'm trying to write an ilogic code that will allow me to select parts within an assembly then update the Iproperties of the the selected parts. I found this code to select the parts and run a rule on the selected parts.

Sub Main()
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence
'Dim sRuleName As String = "IPROPERTY UPDATE"
Line1 :
'''Pick part occurrence
oPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part")
	If oPart Is Nothing Then
		Exit Sub
	Else
		Dim oFileName As String = oPart.Definition.Document.FullFileName
		Dim oDoc As PartDocument = ThisApplication.Documents.Open(oFileName)
		iLogicVb.RunExternalRule("IPROPERTY UPDATE")

'		auto = iLogicVb.Automation
'			Try
'			auto.RunRuleExternalRule(oDoc, sRuleName)

'			Catch
'				MessageBox.Show("Cannot find a rule with the name " & sRuleName & "." & vbLf & "Please try again.", "Open and run")
'			End Try
		'''Close the document with SAVE (as False), without SAVE (As True)
		oDoc.Close(False)
	
		Question = MessageBox.Show("Repeat Command?", "Open and run", MessageBoxButtons.OKCancel)
		If Question = vbOK Then
			''Repeat command
			GoTo Line1
		Else
			Exit Sub
		End If
	End If
End Sub  

However if the commented code is uncommented and the iLogicVb.RunExternalRule("IPROPERTY UPDATE") is commented the message box pops up saying the rule can't be found. If the commented and uncommented are switched the select parts code will run as well as the iproperty update from within the select parts but the iproperties of the selected part don't update. What am I doing wrong? I feel like I'm missing something simple.

 

Thank you in advance for the help.

0 Likes
1,023 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor

You should be able to jump directly from the occurrence being selected to the iproperties of the occurrence. Passing document objects via external rules can prove difficult and a little unnecessary. 

 

From the occurrence you can get to the document by ComponentOccurrence.Definition.Document

Then to each iproperty through propertysets

Sub Main
Dim
oPartoOcc As ComponentOccurrence Line1 : '''Pick part occurrence oPartoOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select Part")
If oPartoOcc Is Nothing Then Exit Sub
Else
Dim oPartDoc as PartDocument
oPartDoc = oPartoOcc.Definition.Document
iProps(oPartDoc)
End If
End Sub

Sub iProps(oDoc As Document) 'Gain Access to properties using API Property Sets 'Dim DesignProp As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties") 'Dim oPn As [Property] = DesignProp.Item("Part Number") 'Dim oDesc As [Property] = DesignProp.Item("Description") 'Dim oVen As [Property] = DesignProp.Item("Vendor") 'Dim oAut As [Property] = DesignProp.Item("Authority") 'Dim oStat As [Property] = DesignProp.Item("User Status") 'Dim SumProp As PropertySet = oDoc.PropertySets.Item("Inventor Summary Information") 'Dim oCom As [Property] = SumProp.Item("Comments") 'Dim oSub As [Property] = SumProp.Item("Subject") Dim CustomProp As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties") Dim oCustomiprop As [Property] Try oCustomiprop = CustomProp.Item("CustomipropName") Catch oCustomiprop = CustomProp.Add("", "CustomipropName") End Try Try oCustomiprop.Value = "Hello" Catch End Try End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

ddimarco6AWM9
Contributor
Contributor

Thank you for the reply. I can get the code to add custom iproperties, but I'm still having trouble filling in the iproperties under the project tab. I want to be able to set the description equal to the part number, the revision number equal to IR and the designer equal to the inventor username.

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

You will need to reference the Property sets item for the project tab and then reference the property item for the property. Here is the project tab and the article  in mod the machine will list the others. 

Dim DesignProp As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties") 'project tab 
	Dim oPn As [Property] = DesignProp.Item("Part Number")
	Dim oDesc As [Property] = DesignProp.Item("Description")
'Description equals to part Number
oDesc.Value = oPn.Value

 

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