Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Copy Derived Custom iProperties

desenho33ZLER
Explorer

Copy Derived Custom iProperties

desenho33ZLER
Explorer
Explorer

Hi!

 

I'm trying to adapt the code from a previous Post (works like a charm on an Part File)  so that i can run it on an assembly file.  Braking it down:

I've an assembly file with multiple parts (some with derived parts, others don't) and i'm trying to run a code that:

- Checks for the file type (.ipt/.iam)

- If it's an assembly file: iterates trough the multiple parts  and copies the Custom iProperties from the derived Parts from each one.

- If it's an Part file runs the previous code, no problems there...

 

Here is my Sample code:

 

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document

If openDoc.DocumentType = 12291 Then

For Each docFile In openDoc.AllReferencedDocuments

If docFile.ComponentDefinition.BOMStructure <> BOMStructureEnum.kPurchasedBOMStructure
Dim oDerived As Inventor.Document = ThisApplication.ActiveDocument ' <-i think this is where my problem lies because it jumps out to the main assembly custom iProproperties
If oDerived.ReferencedDocuments.Count = 0 Then Exit Sub

Dim oReferenced As Inventor.Document = oDerived.ReferencedDocuments(1)

Dim oDerProps As PropertySet = oDerived.PropertySets.Item("Inventor User Defined Properties")
Dim oRefProps As PropertySet = oReferenced.PropertySets.Item("Inventor User Defined Properties")

Dim oProList() As String = {"*"} 'Use "*" to copy all iPros
For Each oRefPro As Inventor.Property In oRefProps
Dim oSkip As Boolean = True
For Each ProName As String In oProList
If UCase(ProName) <> UCase(oRefPro.Name) And ProName <> "*" Then Continue For
oSkip = False
Exit For
Next
If oSkip Then Continue For
Dim oDerPro As Inventor.Property
Try
oDerPro = oDerProps(oRefPro.Name)
Catch
oDerPro = oDerProps.Add("", oRefPro.Name)
End Try
oDerPro.Value = oRefPro.Value
Next


End If
Next

Else If openDoc.DocumentType = 12290 Then

Dim oDerived As Inventor.Document = ThisApplication.ActiveDocument
If oDerived.ReferencedDocuments.Count = 0 Then Exit Sub

Dim oReferenced As Inventor.Document = oDerived.ReferencedDocuments(1)

Dim oDerProps As PropertySet = oDerived.PropertySets.Item("Inventor User Defined Properties")
Dim oRefProps As PropertySet = oReferenced.PropertySets.Item("Inventor User Defined Properties")

Dim oProList() As String = {"Pri_CodFamilia", "Pri_Descricao","Pri_Descricao_Familia","Pri_Descricao_Marca","Pri_Descricao_TipoArtigo","Pri_RefMarca","Pri_Referencia","Pri_UnidadeBase"} 'Use "*" to copy all iPros
For Each oRefPro As Inventor.Property In oRefProps
Dim oSkip As Boolean = True
For Each ProName As String In oProList
If UCase(ProName) <> UCase(oRefPro.Name) And ProName <> "*" Then Continue For
oSkip = False
Exit For
Next
If oSkip Then Continue For
Dim oDerPro As Inventor.Property
Try
oDerPro = oDerProps(oRefPro.Name)
Catch
oDerPro = oDerProps.Add("", oRefPro.Name)
End Try
oDerPro.Value = oRefPro.Value
Next


Else
'MessageBox.Show("O documento Ativo tem de ser um Assembly!", "Formato de Ficheiro Errado!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)


End If

 

Glad to anyone that can help

0 Likes
Reply
294 Views
0 Replies
Replies (0)