Transformation.Translation doesn't match IProperties?

Transformation.Translation doesn't match IProperties?

Anonymous
Not applicable
574 Views
3 Replies
Message 1 of 4

Transformation.Translation doesn't match IProperties?

Anonymous
Not applicable

 

Hello,

I have been given the task to export some key information from Inventor to a different 3D software (Blender).

I do not know much about Inventor as it is not my main field of work. I have been reading solutions on the forum but I don't understand the results I get.

 

I am testing with a simple assembly representing a cylinder. There are 2 parts: the cylinder main body, and the piston.

 

Capture1.JPG

 

 

 

 

 

 

 

 

 

 

 

 

I need to get the data on the ORIGINS of each part, as an offset to the main assembly's origin (0,0,0).

 

 

I have tried using Occurrence.Transformation.Translation to get the Vector from the Origin, but the results don't match what I see in the IProperties window!!! at least, the Y and Z coordinates.

 

Capture3.JPG

 

 

The code:

 

Public Sub getObjectsOrigins()

    ' Get the active assembly.
    Dim oAsmDoc As Document
    Set oAsmDoc = ThisApplication.ActiveDocument

    ' Get the assembly component definition.
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc.ComponentDefinition
    
    'Loop through scene assemblies
    Dim oOcc As ComponentOccurrence

    For Each oOcc In oAsmDef.Occurrences
        Debug.Print oOcc.Name & " - has " & CStr(oOcc.Definition.Occurrences.Count) & " children"
        'Iterate through parts
        If (oOcc.Definition.Occurrences.Count > 0) Then
            Dim oChild As ComponentOccurrence
            For Each oChild In oOcc.Definition.Occurrences
                Debug.Print (vbTab & vbTab & "Part: " & oChild.Name)
                Debug.Print (vbTab & "Origin: " & CStr(oChild.Transformation.Cell(1, 4)) & ", " & CStr(oChild.Transformation.Cell(2, 4)) & ", " & CStr(oChild.Transformation.Cell(3, 4)))
                'This gives the same result as above
                'Debug.Print (vbTab & "Origin: " & CStr(oChild.Transformation.Translation.X) & ", " & CStr(oChild.Transformation.Translation.Y) & ", " & CStr(oChild.Transformation.Translation.Z))
            Next
        End If
    Next
    
    Set oOcc = Nothing
    Set oAsmDef = Nothing
    Set oAsmDoc = Nothing
    
End Sub

 

 

The output from the code. If you compare element X, the results are very different.

cilinder:1 - has 4 children
    Part: cilinder:1
        Origin: 0, 0, 0
    Part: gaffel cilinder:1
        Origin: -6.9, -2.88657986402541E-15, 0
    Part: gec40-01:1
        Origin: -6.9, -2.28215382142666E-15, -4.44089209850063E-16
    Part: gec40-02:1
        Origin: -6.9, -2.06010921650163E-15, -4.44089209850063E-16
zuiger:1 - has 4 children
    Part: zuiger:1
        Origin: 0, 0, 0
    Part: stangkop:1
        Origin: 113, 5.32222989921713E-15, -3.19933921501746E-17
    Part: gec40-01:1
        Origin: 121.5, 5.540951718455E-15, -4.74410459210098E-16
    Part: gec40-02:1
        Origin: 121.5, 5.5409517184549E-15, -4.74410459210112E-16

 

Comparing IProperties of "stangkop:1" element with the output from the vba script:

IProperties:

Offset X = 1130.000 mm

Offset Y = 0.000 mm

Offset Z = -0.000 mm

 

Vba output:

Origin X = 113

Origin Y = 5.32222989921713E-15

Origin Z =  -3.19933921501746E-17

 

What am I missing?

thank you in advance

0 Likes
Accepted solutions (1)
575 Views
3 Replies
Replies (3)
Message 2 of 4

LukeDavenport
Collaborator
Collaborator
Accepted solution

Hi GLBeatriz,

I haven't looked through your code in detail, but the numbers you are getting for the Y and Z positions are effectively zero, as expected ( Z value is -0.000000000000000003) You need to allow for Inventor's internal floating point calculations for geometry - see this useful article.

 

http://modthemachine.typepad.com/my_weblog/2013/08/comparing-floating-point-numbers.html

 

In summary - I think you're reading the translation vector correctly. If you want to check if the translation EQUALS a particular value (like (0,0,0), then you'll need to use a similar method to that shown in the article.

Hope this helps

Luke

Message 3 of 4

Anonymous
Not applicable

Luke,

That was spot on, thanks a lot Cat Happy

 

I changed my approach and now I am trying to round the results from the vba code using the FormatNumber function. I want the rounding to take 2 decimals only. Code:

 

Debug.Print "Position: "
Debug.Print CStr(FormatNumber(oCom.Transformation.Translation.X, 2, vbTrue, vbFalse, vbFalse))
Debug.Print CStr(FormatNumber(oCom.Transformation.Translation.Y, 2, vbTrue, vbFalse, vbFalse))
Debug.Print CStr(FormatNumber(oCom.Transformation.Translation.Z, 2, vbTrue, vbFalse, vbFalse))

 

I also set the display precision of the document via vba:

    Dim oAsmDoc As Document
    Set oAsmDoc = ThisApplication.ActiveDocument
    
    oAsmDoc.UnitsOfMeasure.LengthDisplayPrecision = 0
    oAsmDoc.UnitsOfMeasure.AngleDisplayPrecision = 0
    oAsmDoc.UnitsOfMeasure.LengthUnits = kMillimeterLengthUnits

 

 

However,

I still get discrepancies (due to the rounding), this time in the non-zero results

iProperties:

X Offset  = 1215 mm

Y Offset  = 0 mm

Z Offset  = 0 mm

 

Vba output:

X Offset =-125.50
Y Offset = 0.00
Z Offset =0.00

 

Even after multiplying the vba output by 10 (Inventor uses cm for length, as read here), the discrepancy is not acceptable for my case.

 

Are there any other solutions?

0 Likes
Message 4 of 4

Anonymous
Not applicable

Found why this "discrepancy" was happening

Pending more testing, the numbers are correct

 

This is the situation

 

PARENT ASSEMBLY

-- ASSEMBLY1 [Offset in mm: 0,0,0]

----- PART [Offset in mm: -69, 0, 0]

 

-- ASSEMBLY2 [Offset in mm: 40,0,0]

----- PART [Offset in mm: 1255, 0, 0] >>>> instead of [1215, 0, 0] shown in iProperties screen. Difference: 40 mm

 

In the second assembly, the assembly itself already has an offset to the scene's origin.

The vba is just calculating the TOTAL offset to the scene's origin, so everything seems to be correct 🙂

0 Likes