• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor

    Reply
    Valued Contributor
    dclunie
    Posts: 58
    Registered: ‎03-26-2008
    Accepted Solution

    ILogic rule to change all units

    235 Views, 3 Replies
    11-25-2012 09:07 PM

    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

     

    Convert to mm.JPG

    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,933
    Registered: ‎03-08-2006

    Re: ILogic rule to change all units

    11-26-2012 10:11 AM in reply to: dclunie

    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



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,933
    Registered: ‎03-08-2006

    Re: ILogic rule to change all units

    11-26-2012 10:22 AM in reply to: Curtis_Waguespack

    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



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    *Expert Elite*
    ScottMoyse
    Posts: 1,266
    Registered: ‎06-10-2009

    Re: ILogic rule to change all units

    03-18-2013 12:48 PM in reply to: Curtis_Waguespack

    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.

    Cheers
    Scott Moyse

    Please use Mark Solutions!.Accept as Solution &Give Kudos!Kudos to further enhance the value of these forums. Cheers!


       

    Please use plain text.