Hello iLogic Experts,
Does anyone have an idea on how to change User Parameter Units to match the document settings? Model Parameters seem to update seamlessly with iLogic, but I cannot figure out how to change User Parameter Units.
Thanks,
Paul
HI Paul,
iLogic keeps converting in the background, which you can do too using UnitsOfMeasure:
http://adndevblog.typepad.com/manufacturing/2012/07/unitsofmeasure-object-and-example.html
Cheers,
Hi Adam,
I'm don't think the blog refers to the my situation. For example, I have a USER PARAMETER called "Length" with value "2" and units "mm", along with hundreds of other USER PARAMETERS (not model parameters). I need to change the default for these user parameters from "mm" to "in". When I change the document style, the model parameter default changes, but not the user parameters. I am in search of an iLogic solutions.
Thanks,
Paul
Hi Paul,
this change the unit of the user parameter in what you want, but doesn't convert the anterior value and unit.
I mean if you have as user parameter "MYUSERPARM" 5 in
after you run the rule it will have as unit type mm.
The 5 in will remain, but if you delete it and write another numeric it will be in mm.
Dim oPartDoc As PartDocument oPartDoc = ThisApplication.ActiveDocument Dim oParameter As Parameter For Each oParameter In oPartDoc.ComponentDefinition.Parameters.UserParameters oParameter.Units="mm" Next oParameter
Admaiora
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Hi Paul,
Yes, I misunderstood the issue, but the link I gave might come in handy anyway. 🙂
Using the code admaiora provided you can change the unit and using UnitsOfMeasure object you can convert the exiting value to the correct one.
Cheers,
admaiora,
Thanks, the code works great for part files. One last question: How can I apply it to all part files in an assembly and the assembly file.
This is what I have so far. My knowledge of code is lacking but I found this on the net. I would like to merge your code with this so that when units change in a document, both model parameters and user parameters update to the latest standard (either metric or imperial). I tried to add your code directly with a couple if/then statements but I received a series of errors. Your code skills are greatly appreciated.
'get input from user oUnit = InputRadioBox("Select a units of measure type", "Metric", "Imperial", False, "ilogic") If oUnit = True Then 'set to millimeter oUOM_1 = UnitsTypeEnum.kMillimeterLengthUnits 'set to kilogram oUOM_2 = UnitsTypeEnum.kKilogramMassUnits Else 'set to inch oUOM_1 = UnitsTypeEnum.kInchLengthUnits 'set to pounds mass oUOM_2 = UnitsTypeEnum.kLbMassMassUnits End If 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'Look at all of the files referenced in the open document Dim docFile As Document For Each docFile In openDoc.AllReferencedDocuments 'look at only part files If docFile.DocumentType = kPartDocumentObject 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 'rebuild to update the display docFile.Rebuild End If Next iLogicVb.UpdateWhenDone = True
What errors do you get?
Here is the merged code:
'get input from user oUnit = InputRadioBox("Select a units of measure type", "Metric", "Imperial", False, "ilogic") If oUnit = True Then 'set to millimeter oUOM_1 = UnitsTypeEnum.kMillimeterLengthUnits 'set to kilogram oUOM_2 = UnitsTypeEnum.kKilogramMassUnits Else 'set to inch oUOM_1 = UnitsTypeEnum.kInchLengthUnits 'set to pounds mass oUOM_2 = UnitsTypeEnum.kLbMassMassUnits End If 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'Look at all of the files referenced in the open document Dim docFile As Document For Each docFile In openDoc.AllReferencedDocuments 'look at only part files If docFile.DocumentType = kPartDocumentObject 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 Dim oParameter As Parameter For Each oParameter In docFile.ComponentDefinition.Parameters.UserParameters oParameter.Units = oUOM_1 Next oParameter 'rebuild to update the display docFile.Rebuild End If Next iLogicVb.UpdateWhenDone = True
Cheers,
Hi Adam,
Sorry for the delay. The code just has a couple issues:
1) Regarding the Part Files: The Mass and Angles in the Part User Parameters are being changed to Length UOM. (deg to in etc)
2) Regarding the Assembly File: The units are not updating. Can you include the assembly file in with the referenced part files?
Thank you for your help!
1/ You can use UnitsOfMeasure.GetTypeFromString method to determine if you deal with length units, mass and so on. Please take a look at the Help files if you need more details.
2/ The current code is only looping through the parameters in the referenced documents, you could do the same for the current document.
Hope that helps,
Philippe.
@freudeind wrote:
One last question: How can I apply it to all part files in an assembly and the assembly file.
Hi freudeind,
In addtion to the other replies, you might have a look at this link. The first variation at this link should change units of measure for the assembly and all of the part files in the assembly:
The variation called Another Variation 8-18-2014 uses the examples above to do what you're after in the assembly and part files:
http://inventortrenches.blogspot.com/2012/05/ilogic-rule-to-change-units-of-measure.html
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi Curtis,
Your code called Another Variation 8-18-2014 will be very useful if it can be modified slightly.
The code changes user parameters from "deg", "ul", and "lb" to "in". This causes errors as you can probably imagine.
If you can help me change the user parameter portion or your code, this rule will be really beneficial.
My attempt at changing the code is below. I am getting an error because the program doesn't know the numbers 11269, 11272, 11283, 11286. I need the program to look at the user parameters and determine if they are length, angles, or mass before converting them.
Dim oParameter As Parameter For Each oParameter In openDoc.ComponentDefinition.Parameters.UserParameters If oParameter.Units = 11269 Or oParameter.Units = 11272 Then oParameter.Units = oUOM_1 ElseIf oParameter.Units = 11283 Or oParameter.Units = 11286 Then oParameter.Units = oUOM_2 End If Next oParameter
Thanks,
Paul