Form to show extracted existing custom properties and their values with button to update the values

Form to show extracted existing custom properties and their values with button to update the values

rogerEXHPC
Explorer Explorer
308 Views
4 Replies
Message 1 of 5

Form to show extracted existing custom properties and their values with button to update the values

rogerEXHPC
Explorer
Explorer

Hi.  I have just switched to Inventor after many years using Solidworks.  I haven't researched a lot at this stage but noticed there is no "record macro" functionality which I would most likely use to work out the following normally.

I intend to create a VBA userform with a button which when clicked retrieves existing custom properties from a part or assembly file along with each property's value (added to a text box).  I can then update any of the text box values and click another button to write the values back to the part or assembly file. If someone has an existing macro for this please share it.
If not can someone please provide code in VBA to extract all the custom properties and their values.  Also if possible please provide code to write a value back to the part or assembly file.  I can then create the form and the necessary button to update the value(s).  

0 Likes
309 Views
4 Replies
Replies (4)
Message 2 of 5

tim11_manhhieu
Advocate
Advocate

hope this help

 

 

Private Sub UserForm_Activate()

' Get the active document.
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

' Get the PropertySets object.
Dim oPropSets As PropertySets
Set oPropSets = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSet As PropertySet
Set oPropSet = oPropSets.item("Design Tracking Properties")
  
' Get the part number iProperty.
Dim oPartNumiProp As Property
Set oPartNumiProp = oPropSet.item("Part Number")

' Get the Part Name iProperty.
Dim oStockNumiProp As Property
Set oStockNumiProp = oPropSet.item("Stock Number")

' Get the Surface Treatment iProperty.
Dim oDescriptioniProp As Property
Set oDescriptioniProp = oPropSet.item("Description")

'Get the material iProperty.
Dim oMaterialiProp As Property
Set oMaterialiProp = oPropSet.item("Material")

'Get the designer iProperty.
Dim oDesigneriProp As Property
Set oDesigneriProp = oPropSet.item("Designer")

'Get the Authority iProperty.
Dim oAuthorityiProp As Property
Set oAuthorityiProp = oPropSet.item("Authority")

' Get the PropertySets object.
Dim oPropSetsHeat As PropertySets
Set oPropSetsHeat = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSetHeat As PropertySet
Set oPropSetHeat = oPropSets.item("Inventor User Defined Properties")

Dim oHeatiProp As Property
Set oHeatiProp = oPropSetHeat.item("XXX")

'--------------------------------------------------
'Read Unit name
UnitNameCombo.Value = Left(oDoc.DisplayName, 2)

'Read Part name
PartNoTextBox.Text = oDoc.DisplayName

'BACK UP PART NAME
'Read Part no
PartNameTextBox.Text = oAuthorityiProp.Value

'Read material
MaterialCombo.Value = oMaterialiProp.Value

'Read surface treatment
SurfaceCombo.Value = oDescriptioniProp.Value

'Read designer
DesignCombo.Value = oDesigneriProp.Value

'Read heat
HeatCombo.Value = oHeatiProp.Value
'--------------------------------------------------

End Sub



Private Sub SaveButton_Click()

' Get the active document.
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

' Get the PropertySets object.
Dim oPropSets As PropertySets
Set oPropSets = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSet As PropertySet
Set oPropSet = oPropSets.item("Design Tracking Properties")
    
' Get the part number iProperty.
Dim oPartNumiProp As Property
Set oPartNumiProp = oPropSet.item("Part Number")

' Get the Part Name iProperty.
Dim oStockNumiProp As Property
Set oStockNumiProp = oPropSet.item("Stock Number")

' Get the Surface Treatment iProperty.
Dim oDescriptioniProp As Property
Set oDescriptioniProp = oPropSet.item("Description")

' Get the material iProperty.
Dim oMaterialiProp As Property
Set oMaterialiProp = oPropSet.item("Material")

'Get the designer iProperty.
Dim oDesigneriProp As Property
Set oDesigneriProp = oPropSet.item("Designer")
    
'' Get the Creation Time iProperty.
'Dim oCreationTimeiProp As Property
'Set oCreationTimeiProp = oPropSet.Item("Creation Time")
'' Uncheck the Creation Time iProperty.
'oCreationTimeiProp.Expression = "1601, 1, 1"

'Get the Authority iProperty.
Dim oAuthorityiProp As Property
Set oAuthorityiProp = oPropSet.item("Authority")

'Get the Costcenter iProperty.
Dim oCostCenteriProp As Property
Set oCostCenteriProp = oPropSet.item("Cost Center")

' Get the PropertySets object.
Dim oPropSetsHeat As PropertySets
Set oPropSetsHeat = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSetHeat As PropertySet
Set oPropSetHeat = oPropSets.item("Inventor User Defined Properties")

Dim oHeatiProp As Property
Set oHeatiProp = oPropSetHeat.item("XXX")
    
' -------------------------------------
If oDoc.DocumentType = kPartDocumentObject Then

'Assign Part No
oPartNumiProp.Value = UCase(PartNameTextBox.Text)

'Back up Part No
oAuthorityiProp.Value = UCase(PartNameTextBox.Text)

'Assign Part Name
oStockNumiProp.Value = UCase(PartNoTextBox.Text)

'Assign Material
Dim oMaterial As Material
Set oMaterial = oDoc.Materials.item(MaterialCombo.Value)
oDoc.ComponentDefinition.Material = oMaterial

'Assign Surface Treatment
oDescriptioniProp.Value = SurfaceCombo.Value

'Assign designer
oDesigneriProp.Value = UCase(DesignCombo.Value)

'Assign heat treatment
oHeatiProp.Value = UCase(HeatCombo.Value)

End If
'--------------------------------------

Unload Me

oDoc.Save2 (True)

End Sub

 

 

0 Likes
Message 3 of 5

tim11_manhhieu
Advocate
Advocate

hope this help

 

 

 

Private Sub UserForm_Activate()

' Get the active document.
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

' Get the PropertySets object.
Dim oPropSets As PropertySets
Set oPropSets = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSet As PropertySet
Set oPropSet = oPropSets.item("Design Tracking Properties")
  
' Get the part number iProperty.
Dim oPartNumiProp As Property
Set oPartNumiProp = oPropSet.item("Part Number")

' Get the Part Name iProperty.
Dim oStockNumiProp As Property
Set oStockNumiProp = oPropSet.item("Stock Number")

' Get the Surface Treatment iProperty.
Dim oDescriptioniProp As Property
Set oDescriptioniProp = oPropSet.item("Description")

'Get the material iProperty.
Dim oMaterialiProp As Property
Set oMaterialiProp = oPropSet.item("Material")

'Get the designer iProperty.
Dim oDesigneriProp As Property
Set oDesigneriProp = oPropSet.item("Designer")

'Get the Authority iProperty.
Dim oAuthorityiProp As Property
Set oAuthorityiProp = oPropSet.item("Authority")

' Get the PropertySets object.
Dim oPropSetsHeat As PropertySets
Set oPropSetsHeat = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSetHeat As PropertySet
Set oPropSetHeat = oPropSets.item("Inventor User Defined Properties")

Dim oHeatiProp As Property
Set oHeatiProp = oPropSetHeat.item("XXX")

'--------------------------------------------------
'Read Unit name
UnitNameCombo.Value = Left(oDoc.DisplayName, 2)

'Read Part name
PartNoTextBox.Text = oDoc.DisplayName

'BACK UP PART NAME
'Read Part no
PartNameTextBox.Text = oAuthorityiProp.Value

'Read material
MaterialCombo.Value = oMaterialiProp.Value

'Read surface treatment
SurfaceCombo.Value = oDescriptioniProp.Value

'Read designer
DesignCombo.Value = oDesigneriProp.Value

'Read heat
HeatCombo.Value = oHeatiProp.Value
'--------------------------------------------------

End Sub



Private Sub SaveButton_Click()

' Get the active document.
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

' Get the PropertySets object.
Dim oPropSets As PropertySets
Set oPropSets = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSet As PropertySet
Set oPropSet = oPropSets.item("Design Tracking Properties")
    
' Get the part number iProperty.
Dim oPartNumiProp As Property
Set oPartNumiProp = oPropSet.item("Part Number")

' Get the Part Name iProperty.
Dim oStockNumiProp As Property
Set oStockNumiProp = oPropSet.item("Stock Number")

' Get the Surface Treatment iProperty.
Dim oDescriptioniProp As Property
Set oDescriptioniProp = oPropSet.item("Description")

' Get the material iProperty.
Dim oMaterialiProp As Property
Set oMaterialiProp = oPropSet.item("Material")

'Get the designer iProperty.
Dim oDesigneriProp As Property
Set oDesigneriProp = oPropSet.item("Designer")
    
'' Get the Creation Time iProperty.
'Dim oCreationTimeiProp As Property
'Set oCreationTimeiProp = oPropSet.Item("Creation Time")
'' Uncheck the Creation Time iProperty.
'oCreationTimeiProp.Expression = "1601, 1, 1"

'Get the Authority iProperty.
Dim oAuthorityiProp As Property
Set oAuthorityiProp = oPropSet.item("Authority")

'Get the Costcenter iProperty.
Dim oCostCenteriProp As Property
Set oCostCenteriProp = oPropSet.item("Cost Center")

' Get the PropertySets object.
Dim oPropSetsHeat As PropertySets
Set oPropSetsHeat = oDoc.PropertySets

' Get the design tracking property set.
Dim oPropSetHeat As PropertySet
Set oPropSetHeat = oPropSets.item("Inventor User Defined Properties")

Dim oHeatiProp As Property
Set oHeatiProp = oPropSetHeat.item("XXX")
    
' -------------------------------------
If oDoc.DocumentType = kPartDocumentObject Then

'Assign Part No
oPartNumiProp.Value = UCase(PartNameTextBox.Text)

'Back up Part No
oAuthorityiProp.Value = UCase(PartNameTextBox.Text)

'Assign Part Name
oStockNumiProp.Value = UCase(PartNoTextBox.Text)

'Assign Material
Dim oMaterial As Material
Set oMaterial = oDoc.Materials.item(MaterialCombo.Value)
oDoc.ComponentDefinition.Material = oMaterial

'Assign Surface Treatment
oDescriptioniProp.Value = SurfaceCombo.Value

'Assign designer
oDesigneriProp.Value = UCase(DesignCombo.Value)

'Assign heat treatment
oHeatiProp.Value = UCase(HeatCombo.Value)

End If
'--------------------------------------

Unload Me

oDoc.Save2 (True)

End Sub

 

 

0 Likes
Message 4 of 5

Michael.Navara
Advisor
Advisor

For this purpose you don't need to code anything. You can use iLogic forms and create your own dialog with specified iProperties

MichaelNavara_1-1734332927237.png

 

MichaelNavara_0-1734332824814.png

 

0 Likes
Message 5 of 5

rogerEXHPC
Explorer
Explorer

Thanks to you both for taking the time to reply.  I will go through both replies  in a few weeks when I return to work and let you know the outcome.  

0 Likes