I’ve had the need to create a custom property for all new and existing models.
The new property has been added to the part & assembly templates.
Is there an easy way to get this new iproperty into my existing models? There’s about 250 model model files that need updating. I know I’ll have to open each file but I was hoping not to have to type in the new iproperty each time.
Solved! Go to Solution.
Solved by johnsonshiue. Go to Solution.
You need some ilogic for this. The rule below will ask you for a custom iprop name and a value. It will then create it in all sub parts/assemblies.
If you want to alter the values individually you are best to add it to the Bill of Materials dialogue box and change them in one place.
Sub Main
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oNewiPropName As String
oNewiPropName = InputBox("Enter new custom iProp name", "iLogic", "")
Dim oNewiPropValue As String
oNewiPropValue = InputBox("Enter new custom iProp default value", "iLogic", "")
If oNewiPropName <> "" Then
SubName(oAsmDoc.ComponentDefinition.Occurrences, 1, oNewiPropName,oNewiPropValue)
End If
End Sub
Private Sub SubName(Occurrences As ComponentOccurrences, Level As Integer, oNewiPropName As String, oNewiPropValue As String)
Dim oOcc As ComponentOccurrence
For Each oOcc In Occurrences
Dim oDoc As Document = oOcc.Definition.Document
Dim customPropertySet As PropertySet
customPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
Try
customPropertySet.Add(oNewiPropValue, oNewiPropName)
Catch
'Do Nothing
End Try
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
SubName(oOcc.SubOccurrences, Level + 1, oNewiPropName,oNewiPropValue)
End If
Next
End Sub
You can just create the custom iprop in the BOM also... See screenshot. It will only populate if it gets assigned a value.
Adding this to your external rules, will give you access to the rule from all existing documents, just replace my custom iproperties by yours.
iProperties.Value("Custom", "PTN_ARTNR") = ""
iProperties.Value("Custom", "PTN_CLIENT") = ""
iProperties.Value("Custom", "PTN_CLIENT_DRAWING") = ""
iProperties.Value("Custom", "PTN_CLIENT_TAG") = ""
iProperties.Value("Custom", "PTN_CODE") = ""
iProperties.Value("Custom", "PTN_COMMENTS") = ""
iProperties.Value("Custom", "PTN_DESCRIPTION_EN") = ""
iProperties.Value("Custom", "PTN_DESCRIPTION_NL") = ""
iProperties.Value("Custom", "PTN_DESCRIPTION_FR") = ""
iProperties.Value("Custom", "PTN_DESIGNER") = ""
iProperties.Value("Custom", "PTN_DRAWING") = ""
iProperties.Value("Custom", "PTN_LOCATION") = ""
iProperties.Value("Custom", "PTN_MANAGER") = ""
iProperties.Value("Custom", "PTN_MATERIAL") = ""
iProperties.Value("Custom", "PTN_PN") = ""
iProperties.Value("Custom", "PTN_PROJECTNR") = ""
iProperties.Value("Custom", "PTN_REVISION") = ""
iProperties.Value("Custom", "PTN_SIZE") = ""
iProperties.Value("Custom", "PTN_STATUS") = ""
iProperties.Value("Custom", "PTN_SUPPLIER") = ""
iProperties.Value("Custom", "PTN_TAG") = ""
iProperties.Value("Custom", "PTN_TITLE_EN") = ""
iProperties.Value("Custom", "PTN_TITLE_NL") = ""
iProperties.Value("Custom", "PTN_TITLE_FR") = ""
iProperties.Value("Custom", "PTN_TRADEMARK") = ""
iProperties.Value("Custom", "PTN_TRADEMARK_ARTNR") = ""
iProperties.Value("Custom", "PTN_TYPE") = ""
iProperties.Value("Custom", "PTN_WEIGHT") = ""
Are all the files in one folder or are you opening them on a case by case basis? You should be able to run a rule as above on all the files using a batch tool once you know what they are and where they are. There is a great batch tool here.
and here.
It does take a bit of testing when integrating these rules but it works really well. I will give it a go with @gcoombridge code and post it up when working. You will be sipping tea/coffee in the break room while the computer is churning true the files in know time.
I had made an assumption in the rule above that it would be run in an assembly containing all/many of the parts. If that assembly doesn't exist you could just create it..
The files are not in one assembly they are all in one folder. I've no idea were you enter this code.
The files are not in one assembly they are all in one folder. I've no idea were you enter this code.
You would create an assembly - add the rule in the ilogic browser. Then drag and drop all part files in there (without constraining them - just use the assembly as a container). Run the code, save and then delete the assembly.
That was just the idea that came to me... The batch tool @A.Acheson posted looks awesome..
Hi! Another workflow is to use File Explorer. You can multi-select the Inventor files in File Explorer -> iProperties -> Custom -> add the value. You don't need to launch Inventor to do that.
Many thanks!
Can't find what you're looking for? Ask the community or share your knowledge.