Hi All
I am after a rule to change the unit type of all .ipts from cm to mm.
This has to go down to all levels in hierarchy but only change .ipt files
any code would be appreciated
Dave
Solved! Go to Solution.
Solved by berry.lejeune. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi dclunie,
I think this will work for you (if you modify it a bit):
'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
This is a variation of this rule:
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
Here's a version specifically, directed toward changing from mm to cm:
'get input from user oUnit = InputRadioBox("Select a units of measure type", "millimeter", "centimeter", True, "ilogic") If oUnit = True then 'set to millimeter oUOM_1 = UnitsTypeEnum.kMillimeterLengthUnits Else 'set to centimeter oUOM_1 = UnitsTypeEnum.kCentimeterLengthUnits 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 'rebuild to update the display docFile.Rebuild End If Next iLogicVb.UpdateWhenDone = True
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Curtis,
Since the OP didn't say thank you I will. This just saved one of my staff a tonne of time. Thank you very much!
Cheers
Scott.
Scott Moyse
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.
Design & Manufacturing Technical Services Manager at Cadpro New Zealand
Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project
thank you for your post.
I managed to change globally the lbpounds of the parts to kg. The bom was also updated positively.
But I need to add a rule in order this change is permanent. (I use the parts in other projects).
With the rule (under) : it works only once. When I reopen the assembly with all the parts, the unit is again lb pounds.
Specific question. I need to have the kg unit for each part. Permanently stored in the properties of the individual part.
code:
SyntaxEditor Code Snippet
'get input from user oUnit = InputRadioBox("Select a unit 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 'set mass units docFile.unitsofmeasure.MassUnits = oUOM_2 'rebuild to update the display docFile.Rebuild End If Next iLogicVb.UpdateWhenDone = True
Thank you for helping me.
if you want to permanently stored in the properties of the individual part. add this line under the line
docFile.Rebuild
docFile.save
This code was just what I was looking for. But can this also be done for an individual file? I used the code on an assembly and there it changes all the parts to mm. But I actually need it for an individual part.
I figured it out already. It was just one line what I needed
ThisApplication.ActiveDocument.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits
Thank you for all your contributions.
This rule that you shared is very close to what I am looking for.
I need to change units to inch but without user input. I have an excising rule that takes an iAssembly one member at a time, shrinkwraps,save as ipt save as stp save as dwg but somehow Inventor is changing the units from inch to cm when saving as ipt and that ipt being saved as dwg causes the scale to be at 2.54, meaning that if a length is 48 in in the iAssembly the dwg ends up being 48*2.54. So I thought maybe I can insert change units after it saves as ipt and them stp dwg
Our IT man that wrote all those rules for me retired last month 😞
This example will change all of the documents in an assembly to inches.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
For Each docFile In ThisDoc.Document.AllReferencedDocuments docFile.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kInchLengthUnits Next
First and foremost I always appreciate your help.
I read more about this on your blog, now I understand better what is happening after reading the section about the internal Inventor units being in cm, that explains my issue why the dwg is scaled to 2.54.
For some reason, it doesn't work for me. i want to change all the parameters that i created in mm to cm. did i misunderstand something ?
Thanks
Hi @Alexrose1942. You are talking about changing the units of parameter objects. This forum thread is talking about changing the 'default' document level units. The default document level units are set manually within the Document Settings. The document settings button is located on the Tools tab, Options panel. Within that dialog, on the Units tab is where these settings are found manually. That is what they are doing here in this discussion.
If you want a code solution for changing the units of parameters, then it may be better to start a different forum topic for that. Also, you would need to specify all the details of the task, because code needs to be extremely specific.
And any other useful details that we may need to know.
Edit: Attached is a text file containing the code for an example iLogic rule you can play around with. It can be ran on any document type. It will 'process' that active document, and it will 'process' all levels of that document's referenced documents, without filtering out any specific document type. The code is modular (multiple routines), with one custom Function routine just for retrieving the Parameters collection from a supplied Document (because it is done differently for models and drawings), and a custom Sub routine just for the primary parameter unit replacement task, designed to process an entire Parameters collection at a time. That second routine could easily be converted to process a single parameter at a time, instead of an entire collection though.
Wesley Crihfield