- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Inventor 2017
All updates and hot fixes installed
When I create an assembly that has a frame (constructed with Frame Gen) in it i have to go in to each individual part file and change the G_L user parameter "Custom property format" from "Decimal" to "Fractional" and change the "Precision" to "1/16th". I would like to do this through VBA (or iLogic if possible). The code i wrote shows the error in the attached pic when i try to run it. Can anyone help?? I have attached a pic of my code as well because when i paste it on here its hard to read.
Public Sub ChangeParameterFormat()
' Get the active assembly document.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
' Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
' Check to see if this is a part.
If oDoc.DocumentType = kPartDocumentObject Then
Dim oPartDoc As PartDocument
Set oPartDoc = oDoc
Dim oUserParams As UserParameters
Set oUserParams = oPartDoc.ComponentDefinition.Parameters.UserParameters
Dim i As Integer
For i = 0 To oUserParams.Count
oUserParams.Item(i).CustomPropertyFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
Next i
End If
Next
End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The code below should get you pointed in the right direction. It just adds multi-value Parameters and changing User Parameter. I hope this helps in some way.
SyntaxEditor Code Snippet
Imports Inventor.UnitsTypeEnum Dim oAssemblyDoc As Document oAssemblyDoc = ThisDoc.Document If oAssemblyDoc.DocumentType = kAssemblyDocumentObject Then Dim oAssemblyCompDef As AssemblyComponentDefinition oAssemblyCompDef = oAssemblyDoc.ComponentDefinition Dim oParams As Parameters oParams=oAssemblyCompDef.Parameters Dim oUserParams As UserParameters oUserParams=oParams.UserParameters Dim oAwesomeParameter As Parameter Try otester = oUserParams.Item("PK_Extended_Item_Description") Catch oInsulationType=oUserParams.AddByValue("PK_Extended_Item_Description", "General", kTextUnits) MultiValue.SetList("PK_Extended_Item_Description", "Manufacturing", "Purchasing", "General", "Customer Order", "Phantom") End Try End If Parameter.Param("PK_Extended_Item_Description").ExposedAsProperty = False Parameter.Param("PK_Extended_Item_Description").IsKey = False
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That helped? Thanks! Here is the final code in case others have a similar issue.
Public Sub SetParameterFormatToSixteenthsFractional()
'Get the active assembly document.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
'Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
For Each oDoc In oAsmDoc.AllReferencedDocuments
'Check to see if this is a part.
If oDoc.DocumentType = kPartDocumentObject Then
Debug.Print oDoc.FullFileName
Dim oPartDoc As PartDocument
Set oPartDoc = oDoc
Dim oUserParams As UserParameters
Set oUserParams = oPartDoc.ComponentDefinition.Parameters.UserParameters
'Check to see if the part document contains user parameters.
If oUserParams.Count > 0 Then
Dim oUserParam As UserParameter
'Loop through each user paramter.
For Each oUserParam In oUserParams
'look for user parameter G_L.
If oUserParam.Name = "G_L" Then
Debug.Print oUserParam.Name
Set oUserParam = oUserParams.Item("G_L")
oUserParam.CustomPropertyFormat.Precision = kSixteenthsFractionalLengthPrecision
End If
Next oUserParam
End If
End If
Next oDoc
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I recognize this is an old post, but did you use this code in iLogic? In what file (weldment assembly, top level assembly, etc) did you run this code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I actually use it as a VBA macro, not iLogic. You should be able to just copy and paste it in a module then run it. I use it in assemblies that were created before i modified the content center parts (now when I use frame generator the structural parts have the G_L parameter set to fractional when it placed in the assembly) that i use in frame generator or in assemblies that were created by someone else who did not have content center updated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In case you want to use it in iLogic instead, here below is the translation.
I've removed the debugs and simplified the user parameter search. Also there's no need to cast it to PartDocument type.
You can apply these changes to your VBA makro as well. It would be a bit faster in parts with a lot of custom parameters as it doesn't iterate through all of them. Or let me know if you want me to do so for you.
Public Sub Main()
' Get the active assembly document.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Iterate through all of the documents referenced by the assembly.
For Each oDoc As Document In oAsmDoc.AllReferencedDocuments
' Check to see if this is a part.
If oDoc.DocumentType <> kPartDocumentObject Then Continue For
Dim oUserParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
' Check to see if the part document contains user parameters.
If oUserParams.Count = 0 Then Continue For
' Look for user parameter named "G_L".
Dim oUserParam As UserParameter = oUserParams.Item("G_L")
If oUserParam Is Nothing Then Continue For
oUserParam.CustomPropertyFormat.Precision = kSixteenthsFractionalLengthPrecision
Next oDoc
End Sub
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You're welcomed.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I know this is an old post, but I get this error when running the rule. Any thoughts on it? I'm running it from an Assembly level. Many thanks!