Access to Virtual Part custom property

Access to Virtual Part custom property

marco_bonacina5834P
Enthusiast Enthusiast
384 Views
10 Replies
Message 1 of 11

Access to Virtual Part custom property

marco_bonacina5834P
Enthusiast
Enthusiast

Hi all, I'm trying to extract the custom properties contained in the Bom for virtual parts.
With this code

ESBomRow.iPartNumber = oRow.ComponentDefinitions.Item(1).PropertySets.Item("Design Tracking Properties").Item("xxxx").Value

I can get all the other properties and I would have expected that by replacing "Design Tracking Properties" with "Inventor User Defined Properties" I would have also gotten the custom values, but unfortunately Visual Studio throws an error and from what I see it seems that it can't access the property.

 

Has anyone already faced this problem?

0 Likes
Accepted solutions (2)
385 Views
10 Replies
Replies (10)
Message 2 of 11

jjstr8
Collaborator
Collaborator

Your syntax is correct for getting the iProperty. Check for typos, such as the property set or property name. Inventor will throw an exception if the property set or property doesn't exist. Lastly, make sure your iProperty value can be automatically cast to whatever data type ESBomRow.iPartNumber is. You can assign every iProperty data type to a string, while only Number and Yes/No can be directly assigned to an integer. 

0 Likes
Message 3 of 11

marco_bonacina5834P
Enthusiast
Enthusiast

Hi, thanks for the reply, so, I checked that the name of the property was correct. I also tried to create a debug with all the properties present in the virtual part and what I get is this:

 Componente Virtuale: Componente1
  📂 PropertySet: Inventor Summary Information
     - Title = 
     - Subject = 
     - Author = 
     - Keywords = 
     - Comments = 
     - Last Saved By = 
     - Revision Number = 
Eccezione generata: 'System.NullReferenceException' in Edilsider.dll
     Errore durante il recupero delle proprietà: Object reference not set to an instance of an object.

I can't seem to access the value of custom properties even though they are in the list

 

marco_bonacina5834P_0-1739458373653.png

 

0 Likes
Message 4 of 11

ryan.rittenhouse
Advocate
Advocate

Try directly addressing the property instead of going through the Item handler, like this:

 

ESBomRow.iPartNumber = oRow.ComponentDefinitions(1).PropertySets("Design Tracking Properties")("Part Number").Value

 

In my testing, this has been more consistent than use Item to drill down to other properties. Your milage may vary.

If this solved your problem, or answered your question, please click Accept Solution.
0 Likes
Message 5 of 11

jjstr8
Collaborator
Collaborator

Can you share more of your code? Also, I'm guessing ESBomRow is a custom class. Are you sure ESBomRow has been instantiated and is not null?

0 Likes
Message 6 of 11

marco_bonacina5834P
Enthusiast
Enthusiast

Here is the part of code where the properties are extracted and then passed to a class

	Public Sub QueryBOMRowProperties2(oBOMRows As BOMRowsEnumerator, sNotaSheet As Excel.Worksheet)

		Dim ESBomRows As New List(Of EdSiBomRow)
		FillBomRowsList(oBOMRows, ESBomRows)
		WriteToExcel(ESBomRows, sNotaSheet)
	End Sub


	Private Sub FillBomRowsList(oBomRows As BOMRowsEnumerator, ESBomRows As List(Of EdSiBomRow))
		For Each oRow As BOMRow In oBomRows

			'Set a reference to the primary ComponentDefinition of the row
			Dim oCompDef As ComponentDefinition
			oCompDef = oRow.ComponentDefinitions.Item(1)

			' Imposta iProperties
			Dim oPropSets As PropertySets
			oPropSets = oCompDef.Document.PropertySets
			Dim oInventorSummaryPropertySet = oPropSets.Item("Inventor Summary Information") 'Riepilogo
			Dim oInventorDocumentPropertySet = oPropSets.Item("Inventor Document Summary Information") ' Riepilogo Documento
			Dim oDesignTrackingPropertySet = oPropSets.Item("Design Tracking Properties") ' Progetto
			Dim oCustomPropertySet = oPropSets.Item("Inventor User Defined Properties") ' Personalizzate

			'Get the file properties that are required
			Dim ESBomRow = New EdilSiderBomRow()
			Dim oType As Integer


			' ----------Riepilogo----------
			ESBomRow.iTitle = oInventorSummaryPropertySet.Item("Title").Value ' Iproperties Titolo
			ESBomRow.iSubject = oInventorSummaryPropertySet.Item("Subject").Value ' iProperties Oggetto
			ESBomRow.iAuthor = oInventorSummaryPropertySet.Item("Author").Value  ' iProperties Autore
			ESBomRow.iManager = oInventorDocumentPropertySet.Item("Manager").Value 'iProperties Responsabile
			ESBomRow.iCompany = oInventorDocumentPropertySet.Item("Company").Value 'iProperties Società
			ESBomRow.iCategory = oInventorDocumentPropertySet.Item("Category").Value 'iProperties Categoria
			ESBomRow.iKeywords = oInventorSummaryPropertySet.Item("Keywords").Value 'iProperties Parola chiave
			ESBomRow.iComments = oInventorSummaryPropertySet.Item("Comments").Value ' iProperties Commenti

			' ----------Progetto----------
			'Verifica se il componente è virtuale
			If TypeOf oRow.ComponentDefinitions.Item(1) Is VirtualComponentDefinition Then
				ESBomRow.iPartNumber = oRow.ComponentDefinitions.Item(1).PropertySets.Item("Design Tracking Properties").Item("Part Number").Value ' iProperties Numero Parte Componente Virtuale
				ESBomRow.iStockNumber = oRow.ComponentDefinitions.Item(1).PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value ' iProperties Numero di Magazzino Componente Virtuale
				ESBomRow.iDescription = oRow.ComponentDefinitions.Item(1).PropertySets.Item("Design Tracking Properties").Item("Description").Value ' iProperties Descrizione Componente Virtuale
				ESBomRow.iDocumentSubTypeName = oRow.ComponentDefinitions.Item(1).PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value 'iProperties Nome Sottotipo
				ESBomRow.iDocumentSubType = oRow.ComponentDefinitions.Item(1).PropertySets.Item("Design Tracking Properties").Item("Document SubType").Value 'iProperties Sottotipo

				Dim virtualComp As VirtualComponentDefinition = CType(oRow.ComponentDefinitions.Item(1), VirtualComponentDefinition)

				Debug.WriteLine("🔹 Componente Virtuale: " & virtualComp.DisplayName)
				Try
					' Elenca tutti i PropertySet disponibili
					For Each propSet As PropertySet In virtualComp.PropertySets
						Debug.WriteLine("  📂 PropertySet: " & propSet.Name)

						' Stampa tutte le proprietà disponibili in quel PropertySet
						For Each prop As [Property] In propSet
							Debug.WriteLine("     - " & prop.Name & " = " & prop.Value.ToString())
						Next
					Next

				Catch ex As Exception
					Debug.WriteLine("     Errore durante il recupero delle proprietà: " & ex.Message)
				End Try

				Debug.WriteLine("-------------------------------------------------")

			Else
				ESBomRow.iDocumentSubTypeName = oDesignTrackingPropertySet.Item("Document SubType Name").Value 'iProperties Nome Sottotipo
				ESBomRow.iDocumentSubType = oDesignTrackingPropertySet.Item("Document SubType").Value 'iProperties Sottotipo
				ESBomRow.iPartNumber = oDesignTrackingPropertySet.Item("Part Number").Value ' iProperties Numero Parte Componente Virtuale
				ESBomRow.iStockNumber = oDesignTrackingPropertySet.Item("Stock Number").Value ' iProperties Numero di Magazzino Componente Virtuale
				ESBomRow.iDescription = oDesignTrackingPropertySet.Item("Description").Value ' iProperties Descrizione Componente Virtuale
			End If
			ESBomRow.iRevisionNumber = oInventorSummaryPropertySet.Item("Revision Number").Value 'iProperties Revisione
			ESBomRow.iProject = oDesignTrackingPropertySet.Item("Project").Value 'iProperties Progetto
			ESBomRow.iDesigner = oDesignTrackingPropertySet.Item("Designer").Value 'iProperties Disegnatore
			ESBomRow.iAuthority = oDesignTrackingPropertySet.Item("Authority").Value 'iProperties Autorità
			ESBomRow.iCostCenter = oDesignTrackingPropertySet.Item("Cost Center").Value 'iProperties Centro Gestione Costi
			ESBomRow.iCost = oDesignTrackingPropertySet.Item("Cost").Value 'iProperties Costo Preventivato
			ESBomRow.iManufacturer = oDesignTrackingPropertySet.Item("Manufacturer").Value 'iProperties Fornitore
			ESBomRow.iCatalogWebLink = oDesignTrackingPropertySet.Item("Catalog Web Link").Value 'iProperties Collegamento Web

			' ----------Stato----------
			ESBomRow.iUserStatus = oDesignTrackingPropertySet.Item("User Status").Value ' iProperties Stato
			ESBomRow.iDesignStatus = oDesignTrackingPropertySet.Item("Design Status").Value ' iProperties Stato progetto
			ESBomRow.iCheckedBy = oDesignTrackingPropertySet.Item("Checked By").Value ' iProperties Verificato da
			ESBomRow.iDateChecked = oDesignTrackingPropertySet.Item("Date Checked").Value ' iProperties Data verifica
			ESBomRow.iEngrApprovedBy = oDesignTrackingPropertySet.Item("Engr Approved By").Value ' iProperties Prog. Approvata da
			ESBomRow.iEngrDateApproved = oDesignTrackingPropertySet.Item("Engr Date Approved").Value ' iProperties Data Approvazione Prog.
			ESBomRow.iMfgApprovedBy = oDesignTrackingPropertySet.Item("Mfg Approved By").Value ' iProperties Prod. Approvata da
			ESBomRow.iMfgDateApproved = oDesignTrackingPropertySet.Item("Mfg Date Approved").Value ' iProperties Data Approvazione prod.

			' ---------- Personalizzate ----------
			' Verifica iProperty Personalizzata/Proprietà istanza
			If Not TypeOf oRow.ComponentDefinitions.Item(1) Is VirtualComponentDefinition Then
				Dim component As Object = oRow.ComponentOccurrences(1)
				Dim propertySet As PropertySet = Nothing

				' Determina il tipo di componente e ottiene il propertySet corretto
				If component.Type = ObjectTypeEnum.kComponentOccurrenceObject Then
					Dim compOccurrence As ComponentOccurrence = CType(component, ComponentOccurrence)
					If compOccurrence.OccurrencePropertySetsEnabled Then
						propertySet = compOccurrence.OccurrencePropertySets(1)
					End If
				ElseIf component.Type = ObjectTypeEnum.kComponentOccurrenceProxyObject Then
					Dim compProxy As ComponentOccurrenceProxy = CType(component, ComponentOccurrenceProxy)
					If compProxy.NativeObject.OccurrencePropertySetsEnabled Then
						propertySet = compProxy.NativeObject.OccurrencePropertySets(1)
					End If
				End If

				' Se non ha trovato un propertySet valido, usa le iProperties personalizzate
				If propertySet Is Nothing Then propertySet = oCustomPropertySet

				' Assegna i valori delle proprietà
				ESBomRow.iSpare = GetPropertyValue(propertySet, "Spare")
				ESBomRow.iBoxNumber = GetPropertyValue(propertySet, "Numero Scatola")

			Else

				Try
					ESBomRow.iSpare = oCustomPropertySet.Item("Spare").Value
				Catch ex As Exception
				End Try




			End If

			Try
				ESBomRow.iLength = oCustomPropertySet.Item("Lunghezza").Value ' iProperties Lunghezza
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iWidth = oCustomPropertySet.Item("Larghezza").Value ' iProperties Larghezza
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iThickness = oCustomPropertySet.Item("Spessore").Value ' iProperties Spessore
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iSection = oCustomPropertySet.Item("Sezione").Value 'iProperties Sezione
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iGruoping = oCustomPropertySet.Item("Gruppo").Value ' iProperties Gruppo
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iID = oCustomPropertySet.Item("ID").Value ' iProperties ID
			Catch ex As Exception
			End Try

			Try
				ESBomRow.iMark = oCustomPropertySet.Item("Marca").Value ' iProperties Marca
			Catch ex As Exception
			End Try

			' ----------Fisiche----------
			ESBomRow.iMaterial = oDesignTrackingPropertySet.Item("Material").Value ' iProperties Materiale
			Try
				ESBomRow.iDensity = Left(oRow.ComponentDefinitions.Item(1).Material.Density, 4) ' iProperties Densità
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iMass = Left(oRow.ComponentDefinitions.Item(1).Material.Mass, 5) ' iProperties Mass
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iArea = Left(oRow.ComponentDefinitions.Item(1).Material.Area, 5) ' iProperties Area
			Catch ex As Exception
			End Try
			Try
				ESBomRow.iVolume = Left(oRow.ComponentDefinitions.Item(1).Material.Volume, 5) ' iProperties Volume
			Catch ex As Exception
			End Try

			' ----------Distinta componenti----------
			ESBomRow.ItemNumber = oRow.ItemNumber ' Articolo Numero
			ESBomRow.UnitQty = oRow.ComponentDefinitions.Item(1).BOMQuantity.BaseUnits ' Quantità di base
			ESBomRow.ItemQuantity = oRow.TotalQuantity ' Quantità Elemento
			ESBomRow.BomStructure = oRow.BOMStructure ' Struttura Distinta Componenti
			'ESBomRow.Type = oRow.Merged

			'ESBomRow.Public Property oType As String

			'Iterate child rows if any
			If oRow.ChildRows IsNot Nothing Then
				FillBomRowsList(oRow.ChildRows, ESBomRows)
				oType = 1
			Else
				oType = 0
			End If

			ESBomRow.oType = oType
			'Append new value to List
			ESBomRows.Add(ESBomRow)
		Next
	End Sub
0 Likes
Message 7 of 11

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@marco_bonacina5834P,  I only had a quick look at this, so I might be off the mark, but a quick look at an iLogic rule I had for this shows a slightly different syntax for working from the BOM row see example.

 

Edit: I think I got confused in my quick look earlier, this is where I was seeing the difference, so I think this supports that you have the syntax correct.

apologies for any confusion

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oBOM As BOM = oDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows
For i = 1 To oBOMRows.Count
	Dim oRow As BOMRow = oBOMRows.Item(i)
	Dim oCompDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)

	If TypeOf oCompDef Is VirtualComponentDefinition Then

		Dim oCustomPropertySet_Virt = oCompDef.PropertySets.Item("Inventor User Defined Properties")
		Try
			oProperty = oCustomPropertySet_Virt.Item("xxxx")
			MsgBox(oProperty.value )
		Catch
		End Try
	Else

		Dim oCustomPropertySet = oCompDef.Document.PropertySets.Item("Inventor User Defined Properties")
		Try
			oProperty = oCustomPropertySet.Item("xxxx")
			MsgBox(oProperty.value)
		Catch
		End Try
	End If

Next

 

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oBOM As BOM = oDoc.ComponentDefinition.BOM
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows
For i = 1 To oBOMRows.Count
	Dim oRow As BOMRow = oBOMRows.Item(i)
	Dim oCompDef As ComponentDefinition = oRow.ComponentDefinitions.Item(1)

	Dim oCustomPropertySet = oCompDef.Document.PropertySets.Item("Inventor User Defined Properties")
	Try
		oProperty = oCustomPropertySet.Item("xxxx")
		MsgBox(oProperty.value)
	Catch
	End Try
Next

 

EESignature

0 Likes
Message 8 of 11

marco_bonacina5834P
Enthusiast
Enthusiast

Hi, thanks for the reply, I tried your rule with iLogic and the message containing the property value for the virtual component is not displayed. To make sure it worked correctly I tried assigning a value to another "standard" element and the message was displayed correctly

0 Likes
Message 9 of 11

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@marco_bonacina5834P , see the edits to my previous reply. I had it wrong and updated to show the difference.

EESignature

0 Likes
Message 10 of 11

marco_bonacina5834P
Enthusiast
Enthusiast

This approach seems to work fine in iLogic, tomorrow I'll try to start from this and try to implement it in Visual Studio.

Thanks

0 Likes
Message 11 of 11

jjstr8
Collaborator
Collaborator

@marco_bonacina5834P : It looks like you'll need to do your check for a virtual component earlier. When the code below executes for a virtual component definition, the Document is the assembly that its in, not the virtual component.

 

oPropSets = oCompDef.Document.PropertySets

  

0 Likes