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 change User Parameter Units

10 REPLIES 10
Reply
Message 1 of 11
freudeind
3527 Views, 10 Replies

iLogic change User Parameter Units

Hello iLogic Experts,

Does anyone have an idea on how to change User Parameter Units to match the document settings? Model Parameters seem to update seamlessly with iLogic, but I cannot figure out how to change User Parameter Units.

 

Thanks,
Paul

10 REPLIES 10
Message 2 of 11
adam.nagy
in reply to: freudeind

HI Paul,

 

iLogic keeps converting in the background, which you can do too using UnitsOfMeasure:

http://adndevblog.typepad.com/manufacturing/2012/07/unitsofmeasure-object-and-example.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 11
freudeind
in reply to: adam.nagy

Hi Adam,

I'm don't think the blog refers to the my situation. For example, I have a USER PARAMETER called "Length" with value "2" and units "mm", along with hundreds of other USER PARAMETERS (not model parameters). I need to change the default for these user parameters from "mm" to "in". When I change the document style, the model parameter default changes, but not the user parameters. I am in search of an iLogic solutions.

 

Thanks,

Paul

Message 4 of 11
admaiora
in reply to: freudeind

Hi Paul,

this change the unit of the user parameter in what you want, but doesn't convert the anterior value and unit.

I mean if you have as user parameter "MYUSERPARM"  5 in

after you run the rule it will have as unit type mm.

The 5 in will remain, but if you delete it and write another numeric it will be in mm.

 

Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oParameter As Parameter
For Each oParameter In oPartDoc.ComponentDefinition.Parameters.UserParameters
oParameter.Units="mm" 
Next oParameter

 

Admaiora
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.

_____________________________________________________________________________
Facebook | Twitter | Youtube

Message 5 of 11
adam.nagy
in reply to: freudeind

Hi Paul,

 

Yes, I misunderstood the issue, but the link I gave might come in handy anyway. 🙂

Using the code admaiora provided you can change the unit and using UnitsOfMeasure object you can convert the exiting value to the correct one.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 6 of 11
freudeind
in reply to: admaiora

admaiora,

Thanks, the code works great for part files. One last question: How can I apply it to all part files in an assembly and the assembly file.

 

This is what I have so far. My knowledge of code is lacking but I found this on the net. I would like to merge your code with this so that when units change in a document, both model parameters and user parameters update to the latest standard (either metric or imperial). I tried to add your code directly with a couple if/then statements but I received a series of errors. Your code skills are greatly appreciated.

 

 

'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

 

Message 7 of 11
adam.nagy
in reply to: freudeind

What errors do you get?

Here is the merged code:

'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 
	
    Dim oParameter As Parameter
    For Each oParameter In docFile.ComponentDefinition.Parameters.UserParameters
      oParameter.Units = oUOM_1  
    Next oParameter

	'rebuild to update the display
	docFile.Rebuild
	End If
Next	
iLogicVb.UpdateWhenDone = True

Cheers,



Adam Nagy
Autodesk Platform Services
Message 8 of 11
freudeind
in reply to: adam.nagy

Hi Adam,

Sorry for the delay. The code just has a couple issues:

1) Regarding the Part Files:  The Mass and Angles in the Part User Parameters are being changed to Length UOM. (deg to in etc)

 

2) Regarding the Assembly File: The units are not updating. Can you include the assembly file in with the referenced part files?

 

Thank you for your help!

Message 9 of 11

1/ You can use UnitsOfMeasure.GetTypeFromString method to determine if you deal with length units, mass and so on. Please take a look at the Help files if you need more details.

 

2/ The current code is only looping through the parameters in the referenced documents, you could do the same for the current document.

 

Hope that helps,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 10 of 11


@freudeind wrote:

 

One last question: How can I apply it to all part files in an assembly and the assembly file.


 


Hi freudeind,

 

In addtion to the other replies, you might have a look at this link. The first variation at this link should change units of measure for the assembly and all of the part files in the assembly:

 

The variation called Another Variation 8-18-2014  uses the examples above to do what you're after in the assembly and part files:

 

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 11 of 11

Hi Curtis,

Your code called Another Variation 8-18-2014 will be very useful if it can be modified slightly.

 

The code changes user parameters from "deg", "ul", and "lb" to "in". This causes errors as you can probably imagine.

 

If you can help me change the user parameter portion or your code, this rule will be really beneficial.

 

My attempt at changing the code is below. I am getting an error because the program doesn't know the numbers 11269, 11272, 11283, 11286. I need the program to look at the user parameters and determine if they are length, angles, or mass before converting them.

 

Dim oParameter As Parameter
For Each oParameter In openDoc.ComponentDefinition.Parameters.UserParameters
If oParameter.Units = 11269 Or oParameter.Units = 11272 Then 
oParameter.Units = oUOM_1
ElseIf oParameter.Units = 11283 Or oParameter.Units = 11286 Then 
oParameter.Units = oUOM_2
End If
Next oParameter

 Thanks,

Paul

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

Post to forums  

Autodesk Design & Make Report