How to data from occurence.getMatrixData ?

How to data from occurence.getMatrixData ?

WillyPoelmans3643
Participant Participant
1,226 Views
2 Replies
Message 1 of 3

How to data from occurence.getMatrixData ?

WillyPoelmans3643
Participant
Participant

Hello,

 

I'm using c# for inventor 2013 to write an application but I'm having difficulties with getting the matrix data.

 

An extraction of the code is :

 

foreach (ComponentOccurrence oCompOcc in oCompDef.Occurrences.get_AllLeafOccurrences())
      {
        if ((oCompOcc.Enabled) && (oCompOcc.Suppressed == false) && (oCompOcc.Visible))
        {
          if (oCompOcc.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject)
          {
            PartDocument oPartDoc = (PartDocument)oCompOcc.Definition.Document;

            double [] dMatrix = new double [16];
            oCompOcc.Transformation.GetMatrixData(dMatrix);

            // Writing the matrix-data to a textfile to visualise :
            oCon.writeLine("Matrix data :");
            oCon.writeLine(dMatrix[0].ToString() + " " + dMatrix[1].ToString() + " " + dMatrix[2].ToString());

          } // Einde if
        } // Einde if
      } // Einde foreach

 The problem is that I only get zero's for the matrixdata in the array dMatrix.

 

(The oCon object in the code above only writes tekstlines to a file on the HD)

 

Before I started to write the application I wrote a bunch of testprograms in VBA and overthere it works well. 

The following code was one of the testing programs :

 

Sub getMatrixData()
  If (ThisApplication.ActiveDocumentType = kAssemblyDocumentObject) Then
    Dim oAsmDoc2 As AssemblyDocument
    Set oAsmDoc2 = ThisApplication.ActiveDocument
    
    Dim oAsmDef As AssemblyComponentDefinition
    Set oAsmDef = oAsmDoc2.ComponentDefinition
    
    Dim oLeafOccs As ComponentOccurrencesEnumerator
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
    
    Dim oOcc As ComponentOccurrence
    Dim iOcc As Integer
    
    iOcc = 0 'Teller voor aantal occurences
    
    For Each oOcc In oLeafOccs
      If (oOcc.DefinitionDocumentType = kPartDocumentObject) And (oOcc.Visible) Then
        'Er is een part gevonden
        Dim oMatrix As Matrix
        
        Set oMatrix = oOcc.Transformation
        iOcc = iOcc + 1
        
        Debug.Print CStr(iOcc) & " " & oOcc.Name & ">"
        
        Dim dCells() As Double
        Debug.Print "Matrix-data : "
        
        oMatrix.getMatrixData dCells
        Debug.Print CStr(dCells(0)) & " , " & CStr(dCells(1)) & " , " & CStr(dCells(2)) & " , " & CStr(dCells(3))
        Debug.Print CStr(dCells(4)) & " , " & CStr(dCells(5)) & " , " & CStr(dCells(6)) & " , " & CStr(dCells(7))
        Debug.Print CStr(dCells(8)) & " , " & CStr(dCells(9)) & " , " & CStr(dCells(10)) & " , " & CStr(dCells(11))
        Debug.Print CStr(dCells(12)) & " , " & CStr(dCells(13)) & " , " & CStr(dCells(14)) & " , " & CStr(dCells(15))
      End If
    Next
  End If
End Sub

 I don't understand why all matrix-data is zero in the c# code while in VBA I get the output as here below with the same assembly, I must be overlooking something.

 

Output of VBA :

1 Part2:2>
Matrix-data : 
0,612372435695793 , -0,499999999999999 , -0,612372435695794 , -8,88178419700125E-16
0,353553390593274 , 0,866025403784437 , -0,353553390593274 , 0
0,707106781186547 , -4,9297745912803E-16 , 0,707106781186543 , 0
0 , 0 , 0 , 1

 Output of c# :

Matrix data :
0 0 0

 

 

Any idea what I'm doing wrong here?

 

Thanks in advance.

Best regards,

Willy Poelmans

 

 

0 Likes
1,227 Views
2 Replies
Replies (2)
Message 2 of 3

WillyPoelmans3643
Participant
Participant

Hello,

 

I have 'solved' the issue for me now by using a workaround of wich you can find the code and output below.

But still, if anyone knows what's wrong with the original getMatrixData workflow that I've used, I'm still interested to know!

 

Thanks.

Willy

 

foreach (ComponentOccurrence oCompOcc in oCompDef.Occurrences.get_AllLeafOccurrences())
      {
        if ((oCompOcc.Enabled) && (oCompOcc.Suppressed == false) && (oCompOcc.Visible))
        {
          if (oCompOcc.DefinitionDocumentType == DocumentTypeEnum.kPartDocumentObject)
          {
            PartDocument oPartDoc = (PartDocument)oCompOcc.Definition.Document;

            double [] dMatrix = new double [16];
            oCompOcc.Transformation.GetMatrixData(dMatrix);
            

            oCon.writeLine("Matrix data :");
            oCon.writeLine(dMatrix[0].ToString() + " " + dMatrix[1].ToString() + " " + dMatrix[2].ToString() + " " + dMatrix[3].ToString());
            oCon.writeLine(dMatrix[4].ToString() + " " + dMatrix[5].ToString() + " " + dMatrix[6].ToString() + " " + dMatrix[7].ToString());
            oCon.writeLine(dMatrix[8].ToString() + " " + dMatrix[9].ToString() + " " + dMatrix[10].ToString() + " " + dMatrix[11].ToString());
            oCon.writeLine(dMatrix[12].ToString() + " " + dMatrix[13].ToString() + " " + dMatrix[14].ToString() + " " + dMatrix[15].ToString());

            oCon.writeLine("Matrix data (direct) :");
            oCon.writeLine(oCompOcc.Transformation.get_Cell(1, 1).ToString() + " " + oCompOcc.Transformation.get_Cell(1, 2).ToString() + " " + oCompOcc.Transformation.get_Cell(1, 3).ToString() + " " + oCompOcc.Transformation.get_Cell(1, 4).ToString());
            oCon.writeLine(oCompOcc.Transformation.get_Cell(2, 1).ToString() + " " + oCompOcc.Transformation.get_Cell(2, 2).ToString() + " " + oCompOcc.Transformation.get_Cell(2, 3).ToString() + " " + oCompOcc.Transformation.get_Cell(2, 4).ToString());
            oCon.writeLine(oCompOcc.Transformation.get_Cell(3, 1).ToString() + " " + oCompOcc.Transformation.get_Cell(3, 2).ToString() + " " + oCompOcc.Transformation.get_Cell(3, 3).ToString() + " " + oCompOcc.Transformation.get_Cell(3, 4).ToString());
            oCon.writeLine(oCompOcc.Transformation.get_Cell(4, 1).ToString() + " " + oCompOcc.Transformation.get_Cell(4, 2).ToString() + " " + oCompOcc.Transformation.get_Cell(4, 3).ToString() + " " + oCompOcc.Transformation.get_Cell(4, 4).ToString());
          } // Einde if
        } // Einde if
      } // Einde foreach

 

Output :

The second output (Matrix data (direct)) is what I needed/expected :

 

Matrix data :
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Matrix data (direct) :
0.612372435695793 -0.499999999999999 -0.612372435695794 -8.88178419700125E-16
0.353553390593274 0.866025403784437 -0.353553390593274 0
0.707106781186547 -4.9297745912803E-16 0.707106781186543 0
0 0 0 1

 

0 Likes
Message 3 of 3

xiaodong_liang
Autodesk Support
Autodesk Support

Hi Willy,

 

I can reproduce this issue. The argument of GetMatrixData is defined as SafeArray. I doubt this is a problem when marshal the safearray to double[]. I did not find other workaround except get_Cell. I logged this issue.

 

0 Likes