Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switching units of Document using Ilogic // Changer les unites piece avec Ilogic

5 REPLIES 5
Reply
Message 1 of 6
pierre.masson
895 Views, 5 Replies

Switching units of Document using Ilogic // Changer les unites piece avec Ilogic

Some customer might want to switch units between in and mm quickly. This could enable to make some measurements in mm and the quickly switch back to in.

 

For example if Ilogic Browser is displayed and you have to make these units changes very often, you can do it quite quickly writing this rule :

 

Pour les personnes qui doivent regulierement passer de in a mm comme unite dans les documents Inventor, vous pouvez le faire avec la regle Ilogic ci dessous :

 


doc=ThisDoc.Document
units=doc.unitsofmeasure.lengthunits


Ifunits=11269Then
doc.unitsofmeasure.lengthunits=11272
EndIf



Ifunits=11272Then
doc.unitsofmeasure.lengthunits=11269
EndIf

 

11269 and 11272 are values valid for in and mm.

 

Pierre Masson Product Support Specialist PS MFG EMEA Autodesk, Inc.
5 REPLIES 5
Message 2 of 6
theiman
in reply to: pierre.masson

Hello, I would like to do the same thing but using a macro so that I can assign it to a keyboard shortcut. I can get the units to change but the update command I'm using exits out of the sketch. I would like to be able to run this in the sketch, part, or assembly and have it automatically update the units the same way as if you manually changed them. Any help is appreciated. Thanks.

 

Currently my script is

 

Public Sub units()

    Dim oPartDoc As Inventor.PartDocument

     Set oPartDoc = ThisApplication.ActiveDocument

    ' Set a reference to the UnitsOfMeasure object of the

     ' active document.     Dim oUOM As UnitsOfMeasure

     Set oUOM = ThisApplication.ActiveDocument.UnitsOfMeasure

         ' Display information about the current unit settings.

         ' Get the current length units.

     Dim eLengthUnits As UnitsTypeEnum

     eLengthUnits = oUOM.LengthUnits

         ' Checks to see if units are in mm

     If oUOM.LengthUnits = kMillimeterLengthUnits Then

         ' If true then switches to inches

         oUOM.LengthUnits = kInchLengthUnits

         oUOM.LengthDisplayPrecision = 3

         ' If false then switches to mm

     Else

         oUOM.LengthUnits = kMillimeterLengthUnits

         oUOM.LengthDisplayPrecision = 2

     End If

         oPartDoc.Update

End Sub

Tags (1)
Message 3 of 6
theiman
in reply to: pierre.masson

So I was trying to do the update with :

 

    Dim oPartDoc As Inventor.PartDocument

    Set oPartDoc = ThisApplication.ActiveDocument

    oPartDoc.Update

 

But I think I just need a different update command which updates the active window. If I take that code out, run my script, then modify anything on the sketch, the units update. I just dont know what command to use to make the screen update.

Message 4 of 6
theiman
in reply to: theiman

Also tried putting in 

 

ThisApplication.ActiveView.Update

 

at the end of the sub and it did not work either. 

Message 5 of 6
pierre.masson
in reply to: theiman

Hello Iman

 

I don't think you can get that kind of update properly in sketch environment. You need to exit and update.

 

I'd use this trick, if Sketch active, then exit sketch update and come back in. Code is a bit slower but it seems to work

 

Dim Osketch As Sketch
If oPartDoc.SketchActive = True Then
    Set Osketch = ThisApplication.ActiveEditObject
    Osketch.ExitEdit
    oPartDoc.Update
    Osketch.Edit
   
Else: oPartDoc.Update

End If
        

 

Hope this helps.

Pierre Masson Product Support Specialist PS MFG EMEA Autodesk, Inc.
Message 6 of 6
QuasiMojo
in reply to: pierre.masson

Reviving an ancient thread here, I know.  This code no longer works for 2016.  Can anyone tell me why?  I cannot find the object and parameter reference for the units to know what has changed.

Cheers, thanks,

Andrew

Tags (3)

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

Post to forums  

Autodesk Design & Make Report