How to interpret length values in inches, not centimeters?

How to interpret length values in inches, not centimeters?

amillsLD4X8
Participant Participant
618 Views
5 Replies
Message 1 of 6

How to interpret length values in inches, not centimeters?

amillsLD4X8
Participant
Participant

Why does Inventor interpret my dimension values in units of "cm" and not "in"? 

All I'm trying to do in the code below is draw a circle with a diameter of 120 in. But it creates a circle with diameter of 47.244 in. It looks like Inventor is taking my 120 in "cm" and then by dividing by 2.54 to converting to "cm". Is there away to tell Inventor that the 120 is already in inches? 

I thought line 17 would tell the document to interpret length values in "in", but it doesn't look like that is happening.  

 

Thank you for the help.

Sub BuildPart()

'Get value from user input
Dim circleRadius As Double
circleID = 120

'Define Inventor Document
Dim app As Application
Set app = Inventor.ThisApplication
Dim partDoc As Document

Set partDoc = app.Documents.Add(kPartDocumentObject, ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
Set compDef = partDoc.ComponentDefinition
Set tG = app.TransientGeometry

'Change units of document
partDoc.UnitsOfMeasure.LengthUnits = UnitsTypeEnum.kInchLengthUnits

'Create sketch
Dim baseSketch As PlanarSketch
Set baseSketch = compDef.Sketches.Add(compDef.WorkPlanes.Item(2))

'Create circle in sketch
Dim tankID As SketchCircle
Set tankID = baseSketch.SketchCircles.AddByCenterRadius(tG.CreatePoint2d(0, 0), circleID / 2)

End Sub

 

 

 

amillsLD4X8_0-1682691655965.png

 

 

0 Likes
Accepted solutions (1)
619 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @amillsLD4X8.  Centimeters are Inventor's default length units (database units) used for everything behind the scenes in all their code.  Any raw numbers in your code that are supposed to represent length measurements that have units, will be automatically interpreted as representing centimeters.  It has always been this way, and will likely never change.  You can just expect this behavior and use simple math to convert, or you can use the built-in units converter function (Document.UnitsOfMeasure.ConvertUnits).  Most of the values you get back from stuff in Inventor are also in 'database units', there are different default units for different types of measurements (angle, mass, time, etc).  There are a few situations where you will get 'document' units, but it would be difficult to list them all here.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Adding a plug (link) to my related idea on the Inventor Ideas forum, just for the exposure. 😁

https://forums.autodesk.com/t5/inventor-ideas/add-property-method-to-api-for-parameter-type-objects-... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

amillsLD4X8
Participant
Participant

Thank you, @WCrihfield

 

I was kind of hoping that wasn't the case (the 'database' units and all) but it is easy enough to get around. I just wanted to make sure there wasn't a more 'official' method before I just convert all user input myself. 

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Hi @amillsLD4X8.  One good thing to keep in mind that may make things a bit easier is to look for anything that has a Property named 'Expression', besides having a Property named 'Value'.  The value of the 'Expression' property is always a String (text), instead of numerical or other Type.  And anything you provide as the value of that Expression will be understood/used literally.  So, you could say Object.Expression = "6.25 in" and it will be understood as 6 inches, without the units being converted.  Think of it like typing something into the Equation column of a parameter, in the parameters dialog box.  You can also put a quoted equation as the value of the Expression property in some situations (like a parameter).  And there are some places in code where it is asking for a "Variant" or "Object" as the value of something, where you would expect to supply a numerical value.  That often means that it will accept a String, as well as a Double (or other numerical data type), and you can use that the same way (supply a quoted value, with units specified).  Just some more tips to keep in mind.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

amillsLD4X8
Participant
Participant

Awesome, thank you for the tip.

0 Likes