- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on a rule to change the document units and the user parameter "length units" to either inch or mm.
I borrowed Curtis Waguespack code "Another Variation 8-18-2014" from http://inventortrenches.blogspot.com/2012/05/ilogic-rule-to-change-units-of-measure.html.
It handles the document units beautifully, but it changes all the user parameters to inch or mm, even if they are of other units.
In my case, I need to identify the user parameter as being a length unit and change the unit accordingly.
I see this topic has been kicked around a bit, bu with my very limited knowledge, I couldn't put a solution together.
I'm sure the solution is easy for the experts.
Here is my latest attempt....
'------- start of ilogic ------ question = MessageBox.Show("This process changes the unit of measure setting of the document. Completing this action in an assembly file will attempt to modify all files contained in the assembly. Are you sure you want to change the documents unit of measure?", _ "Change Document Units",MessageBoxButtons.YesNo,MessageBoxIcon.Warning) If question = vbNo Then Return Else 'get input from user oUnit = InputRadioBox("Select a unit of measure", "Metric", "Imperial", True, "Unit of Measure") 'create precision value list oPrecisionArray = New String(){0, 1, 2, 3, 4, 5} 'get input from user oPrecision = InputListBox("Select the number of decimal places to use for the units of length display.", _ oPrecisionArray, 3, "Precision", "Decimal Places (Display Only)") 'example UnitsTypeEnum Enumerators 'kCentimeterLengthUnits = 11268 'kMillimeterLengthUnits = 11269 'kInchLengthUnits = 11272 'kKilogramMassUnits = 11283 'kGramMassUnits = 11284 'kLbMassMassUnits = 11286 If oUnit = True Then 'set to millimeter oUOM_1 = 11269 'set to kilogram oUOM_2 = 11283 Else 'set to inch oUOM_1 = 11272 'set to pounds mass oUOM_2 = 11286 End If 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'I added------------------------------------- Dim oParameter As Parameter '--------------------------------------------- 'set length units for the top level assembly openDoc.unitsofmeasure.LengthUnits = oUOM_1 'set mass units for the top level assembly openDoc.unitsofmeasure.MassUnits = oUOM_2 'set precision openDoc.unitsofmeasure.LengthDisplayPrecision = oPrecision 'I added - Set user param unit equal To document units------------------ For Each oParameter In openDoc.ComponentDefinition.Parameters.UserParameters If oParameter.Units = 11269 Or oParameter.Units = 11272 Then oParameter.Units = oUOM_1 End If Next oParameter '------------------------------------------------------------------------ 'Look at all of the files referenced in the open document Dim docFile As Document For Each docFile In openDoc.AllReferencedDocuments 'I added. Checks if file is able to be modified and skips if not. (Works)--------------------------------- If docFile.IsModifiable = False Then 'skip Else If docFile.IsModifiable = True Then '-------------------------------------------------------------------------------------------------------- 'format file name Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 'set length units docFile.unitsofmeasure.LengthUnits = oUOM_1 'set mass units docFile.unitsofmeasure.MassUnits = oUOM_2 'set precision docFile.unitsofmeasure.LengthDisplayPrecision = oPrecision 'I added Change all user parameters units To match document units------------------------------------- For Each oParameter In docfile.ComponentDefinition.Parameters.UserParameters 'openDoc.ComponentDefinition.Parameters.UserParameters If oParameter.Units = 11269 Or oParameter.Units = 11272 Then oParameter.Units = oUOM_1 End If Next oParameter '---------------------------------------------------------------------------------------------------- 'rebuild to update the display docFile.Rebuild End If Next End If 'update all iLogicVb.UpdateWhenDone = True '------- end of ilogic ------
Inventor Pro 2023
Vault Pro 2023
Solved! Go to Solution.