Item("Design Tracking Properties") & Item("Inventor User Defined Properties")

Item("Design Tracking Properties") & Item("Inventor User Defined Properties")

tomislav.peran
Advocate Advocate
1,860 Views
3 Replies
Message 1 of 4

Item("Design Tracking Properties") & Item("Inventor User Defined Properties")

tomislav.peran
Advocate
Advocate

Hello,

 

Can somebody check/clarify the comments I have added to this rule?

I know what is this code doing but Try - Catch block confuses me...

 

Tom

 

'Define opened document as this document
Dim openDoc As Document
openDoc = ThisDoc.Document 
'Define file as document
Dim docFile As Document
'opened document needs to be assembly in order for code to work
If openDoc.DocumentType = 12291 Then    
	'for each file that exist in opened assembly
	For Each docFile In openDoc.AllReferencedDocuments
		'if file is not Read Only 
		If docFile.IsModifiable = True Then
			'Get the quantity of the file/component currently being looked in the assembly
			Dim qty As Integer = openDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(docFile).Count
			'Get the value in the iProperties of the component under the tab "Project" -> "Part Number"
			'What is Item("Design Tracking Properties") ?? Is that the way to define "Project" tab in iProperties
			Dim oPartnumber As String = docFile.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
			'Define oProp as Inventor property
			Dim oProp As Inventor.Property
			Try
				'Item("Inventor User Defined Properties") -> Custom iProperties of assembly?
				oProp = openDoc.PropertySets.Item("Inventor User Defined Properties").Item(oPartnumber)
				'What is happening here?
oProp.Value = oProp.Value + qty Catch
'Add oPartnumber and it's qty into Custom iProperties of assembly oProp = openDoc.PropertySets.Item("Inventor User Defined Properties").Add(qty, oPartnumber) End Try End If Next Else MessageBox.Show("!", "Message",MessageBoxButtons.OK,MessageBoxIcon.Exclamation) End If

 

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

Frederick_Law
Mentor
Mentor
Accepted solution

https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-finall...

 

Instead of checking if the iProperty is available, the code TRY to read the iProperty first.

If the iProperty is not there, it will CATCH the exception or crash and add the iProperty.

 

 

Message 3 of 4

tomislav.peran
Advocate
Advocate

Ah, that makes sense. If it already exists, there is no need to add it.  That was the idea.

 

So this line means that the code will add a calculated quantity to an existing property (name of the part which the code took from part's iProperty):

 

oProp.Value = oProp.Value + qty

If some value also already exists for that property it will not be overwritten but a new value will be added to the existing one. Do I understand correctly?

 

And is this: Item("Design Tracking Properties")  Project tab in assembly iProperty?

 

 

 

0 Likes