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: 

ILogic rule to change all units

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
dclunie
4871 Views, 12 Replies

ILogic rule to change all units

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

Tags (2)
12 REPLIES 12
Message 2 of 13
Curtis_Waguespack
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

Message 3 of 13

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

Message 4 of 13

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.


EESignature


Design & Manufacturing Technical Services Manager at Cadpro New Zealand

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

Message 5 of 13

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.
Message 6 of 13
yan.wangBKEWN
in reply to: toon.gielen

if you want to permanently stored in the properties of the individual part. add this line under the line 

docFile.Rebuild

docFile.save 

Message 7 of 13
berry.lejeune
in reply to: dclunie

@Curtis_Waguespack 

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.

Message 8 of 13
berry.lejeune
in reply to: dclunie

@Curtis_Waguespack 

I figured it out already. It was just one line what I needed

ThisApplication.ActiveDocument.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kMillimeterLengthUnits

 

Message 9 of 13

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 😞

Message 10 of 13

Hi @Jolanta_Voigt 

 

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

 

Message 11 of 13

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.

Message 12 of 13

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

Message 13 of 13
WCrihfield
in reply to: Alexrose1942

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.

  • What document type would be active when the code starts (part, assembly, drawing)?
  • Do you want the code to target only the active document, only target the active document's immediately referenced documents, only target all levels of referenced documents, or the active document and referenced documents?
  • If effecting referenced documents, then what document types do you want it to effect (parts, assemblies, drawings)?
  • Which parameter types should it target (only UserParameters, or ModelParameters and/or other types too)?

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

EESignature

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

Post to forums