Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I change the document Units?

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
karthur1
3200 Views, 18 Replies

How do I change the document Units?

I have imported a large .sat assembly file that has its units set to "feet". When I imported this assembly, I had to use feet in order to get the parts to come in correctly. Now all the parts in this assembly also have the document units set to feet. I would like to now change all the parts to have the document units set to inch. There are over 1,300 parts that I have to change, so I don't want to have to open each part up and change it. Looking for a macro or some way to go thru the parts and set this quickly.

Thanks
18 REPLIES 18
Message 2 of 19
alewer
in reply to: karthur1

On a small test assembly, this macro seems to do the trick.

Public Sub SetActiveDocUnits()
'(Run this macro)
Dim oActiveDocument As Inventor.Document
Set oActiveDocument = ThisApplication.ActiveDocument

SetLengthUnitsToInch oActiveDocument
End Sub

Private Sub SetLengthUnitsToInch(Document As Inventor.Document)
'Get Units of Measure
Dim oUOM As Inventor.UnitsOfMeasure
Set oUOM = Document.UnitsOfMeasure

'Set lenght units to inch and save
oUOM.LengthUnits = kInchLengthUnits
Document.Save

'Run recursively for assembly
If TypeOf Document Is Inventor.AssemblyDocument Then
Dim oAssemblyDocument As Inventor.AssemblyDocument
Set oAssemblyDocument = Document
Dim oOccurrence As Inventor.ComponentOccurrence
For Each oOccurrence In oAssemblyDocument.ComponentDefinition.Occurrences
SetLengthUnitsToInch oOccurrence.Definition.Document
Next oOccurrence
End If
End Sub
Message 3 of 19
karthur1
in reply to: karthur1

It changes the units, but I can't get it to save the change to the parts. After I run this macro, I can open the parts individually and the units are changed. But, if I close the assembly and open the part itself, it is back to the old units.
When I have the assembly open and run the macro, I saved the assembly. I thought that the parts were also getting saved, but they are not.

If I open a part and manually change the document settings, it will dirty the part and it shows that it needs to be saved. If I run this macro it changes the document settings, but it does not dirty the part. Edited by: karthur1 on Sep 25, 2009 8:52 AM
Message 4 of 19
karthur1
in reply to: karthur1

Here is a corrected version alewer sent me that dirty's the file so it will be saved. Thanks.


Public Sub SetActiveDocUnits()

Dim oActiveDocument As Inventor.Document
Set oActiveDocument = ThisApplication.ActiveDocument
SetLengthUnitsToInch oActiveDocument
End Sub


Private Sub SetLengthUnitsToInch(Document As Inventor.Document)

'Get Units of Measure
Dim oUOM As Inventor.UnitsOfMeasure
Set oUOM = Document.UnitsOfMeasure
'Set length units to inch and save
oUOM.LengthUnits = kInchLengthUnits
document.Dirty = True
Document.Update
Document.Save

'Run recursively for assembly
If TypeOf Document Is Inventor.AssemblyDocument Then
Dim oAssemblyDocument As Inventor.AssemblyDocument
Set oAssemblyDocument = Document
Dim oOccurrence As Inventor.ComponentOccurrence
For Each oOccurrence In oAssemblyDocument.ComponentDefinition.Occurrences
SetLengthUnitsToInch oOccurrence.Definition.Document
Next oOccurrence
End If
End Sub

Edited by: karthur1 on Sep 25, 2009 4:13 PM
Message 5 of 19
scottmoyse
in reply to: karthur1

Just to contribute to this beauty. I've tweaked this to correct the units for the rest of the world 😉

 

Also changed it from only modifying Length units, but also mass & angle.

 

Thanks to all in this thread for posting this in the first place. I'll be using this to convert all of the Inventor HSM CAM datasets to metric from imperial.

 

Public Sub SetActiveDocUnits()
Dim oActiveDocument As Inventor.Document
Set oActiveDocument = ThisApplication.ActiveDocument
SetUnitsToMetric oActiveDocument
End Sub

Private Sub SetUnitsToMetric(Document As Inventor.Document)
'Get Units of Measure
Dim oUOM As Inventor.UnitsOfMeasure
Set oUOM = Document.UnitsOfMeasure
'Set length units to Metric and save
oUOM.LengthUnits = kMillimeterLengthUnits
oUOM.MassUnits = kGramMassUnits
oUOM.AngleUnits = kDegreeAngleUnits
Document.Dirty = True
Document.Update
Document.Save

'Run recursively for assembly
If TypeOf Document Is Inventor.AssemblyDocument Then
Dim oAssemblyDocument As Inventor.AssemblyDocument
Set oAssemblyDocument = Document
Dim oOccurrence As Inventor.ComponentOccurrence
For Each oOccurrence In oAssemblyDocument.ComponentDefinition.Occurrences
SetUnitsToMetric oOccurrence.Definition.Document
Next oOccurrence
End If
End Sub

 


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.


EESignature


Design & Manufacturing Technical Services Manager at Cadpro New Zealand

Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project

Message 6 of 19
WHolzwarth
in reply to: scottmoyse

Good stuff, Scott.

I think, that can be used with imported STEPs or other types for changing angles from radians to degrees, too.

I'll try it instantly.

Walter 

Walter Holzwarth

EESignature

Message 7 of 19
aveen.design
in reply to: scottmoyse

Capture.JPG

Message 8 of 19
WHolzwarth
in reply to: aveen.design

It's VBA, not iLogic

 

VBA vs iLogic.jpg

 

iLogic needs a minor change

Walter Holzwarth

EESignature

Message 9 of 19
aveen.design
in reply to: WHolzwarth

dear sir I need illogic I don't know how VBA works

 

Message 10 of 19
WHolzwarth
in reply to: aveen.design

Message 11 of 19
eng.co
in reply to: scottmoyse

Hello Scott,

 

Please, can you make a short screencast video which shows how to insert this code in inventor and how this code is used.

I know nothing about this things.

 

Thank you!

2020 Autodesk Product Design Suite Premium
Windows 10 Pro
INTEL Core i7-8700K 6-Core 3.7GHz (4.7GHz) Box
32 GB RAM
NVIDIA GeForce GTX 1660 Ti
Message 12 of 19

Hi!

Could you please convert this code to ilogic?

Thanks in advance.

Manuel Campos Costa
Message 13 of 19

Hi Manuel,

 

The 2023 iLogic debug tool helps quite a bit. I can follow the error message and correct the syntax to VB.Net. Here you go. Just copy the following and paste it to a rule.

Many thanks!

 

Johnson

 

Public Sub Main()
Dim oActiveDocument As Inventor.Document
oActiveDocument = ThisApplication.ActiveDocument
SetUnitsToMetric(oActiveDocument)
End Sub

Private Sub SetUnitsToMetric(Document As Inventor.Document)
'Get Units of Measure
Dim oUOM As Inventor.UnitsOfMeasure
oUOM = Document.UnitsOfMeasure
'Set length units to Metric and save
oUOM.LengthUnits = kMillimeterLengthUnits
oUOM.MassUnits = kGramMassUnits
oUOM.AngleUnits = kDegreeAngleUnits
Document.Dirty = True
Document.Update
Document.Save

'Run recursively for assembly
If TypeOf Document Is Inventor.AssemblyDocument Then
Dim oAssemblyDocument As Inventor.AssemblyDocument
oAssemblyDocument = Document
Dim oOccurrence As Inventor.ComponentOccurrence
For Each oOccurrence In oAssemblyDocument.ComponentDefinition.Occurrences
SetUnitsToMetric(oOccurrence.Definition.Document)
Next oOccurrence
End If
End Sub



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 14 of 19

@johnsonshiue Thanks a lot!

 

I know it was probably easy to solve, it's my fault not knowing how to program.

 

Also we aren't yet on 2023.

Manuel Campos Costa
Message 15 of 19

@johnsonshiue 

 

I'm getting an error when I run it on assemblies, and also in parts when I run it with trigger before save.

 

Manuelcamposcosta_0-1663840157748.pngManuelcamposcosta_1-1663840171651.png

 

Manuel Campos Costa
Message 16 of 19

Hi Manuel,

 

No, it is not your fault that you don't program. You don't need to. I am not a developer either. I am just a user happening to know the product relatively well.

If possible, please share the files and the rule with me directly johnson.shiue@autodesk.com. I would like to take a closer look. It is possible the rule has issues that I did not see.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 17 of 19
johnsonshiue
in reply to: johnsonshiue

Hi Folks,

 

Manuel sent me his files and the rule. I think it was a bit over-complicated. Here is a simpler rule to change the document units. It should work.

 

Dim oAssy As Document = ThisApplication.ActiveDocument

Dim allDocs As DocumentsEnumerator = oAssy.AllReferencedDocuments

Dim oDoc As Document

For Each oDoc In allDocs

    oDoc.UnitsOfMeasure.AngleUnits = UnitsTypeEnum.kDegreeAngleUnits

              oDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits

              oDoc.UnitsOfMeasure.MassUnits = UnitsTypeEnum.kKilogramMassUnits

Next

 

Many thanks!

 



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
Message 18 of 19

@johnsonshiue Perfect!

Is there any possibility to have for example grams in parts and kilograms in assemblies?

 

Just to note for other people this rule doesn't change the values in the assembly we are running the ilogic, but that's easy to solve.

 

Thanks a lot Johnson!

Manuel Campos Costa
Message 19 of 19

Hi Manuel,

 

Here you go! You need to change the unit enums accordingly. This rule just shows how to change Doc Units per doc type within an assembly.

 

Dim oAssy As Document = ThisApplication.ActiveDocument
Dim allDocs As DocumentsEnumerator = oAssy.AllReferencedDocuments
Dim oDoc As Document
For Each oDoc In allDocs

If oDoc.DocumentType=Inventor.DocumentTypeEnum.kPartDocumentObject Then

 

oDoc.UnitsOfMeasure.AngleUnits = UnitsTypeEnum.kDegreeAngleUnits
oDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits
oDoc.UnitsOfMeasure.MassUnits = UnitsTypeEnum.kGramMassUnits

 

Else If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
oDoc.UnitsOfMeasure.AngleUnits = UnitsTypeEnum.kRadianAngleUnits
oDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMeterLengthUnits
oDoc.UnitsOfMeasure.MassUnits = UnitsTypeEnum.kKilogramMassUnits
End If

Next

 

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report