Products

Conversions and Transformations using the Solid Edge API – Part 4

By Tushar Suradkar

…continued from part 3

This series of articles discusses the following:


  1. Document Unit Conversion – ParseUnit and Format Unit methods of the UnitsOfMeasure object.

  2. View Coordinate Conversion – ViewToSheetViewToSheetViewToSheetViewToSheetViewToSheet and SheetToView methods of the DrawingView object.

  3. 2D to 3D Conversion – Convert2DCoordinate method of the Profile object.

  4. 3D to 2D Transformations – ModelToView method of the DrawingView object.

  5. Assembly Transformations – GetMatrix and PutMatrix methods of the Occurrence object.

Assembly Transformations

This part of the conversion and transformation series discusses the transformation of occurrences in the assembly using matrices. These transformations are movement and rotation.

An Occurrence object in the assembly has a Matrix Property which is an array and can be accessed as below:

Imports SolidEdgeAssembly

Module Module1

Sub Main()
  Dim seApp As SolidEdgeFramework.Application = Runtime.InteropServices.Marshal.GetActiveObject(“SolidEdge.Application”)
  Dim seDoc As AssemblyDocument = seApp.ActiveDocument
  Dim seOccs As Occurrences = seDoc.Occurrences
  Dim seOcc As Occurrence = seOccs.Item(1)

  Dim Matrix = Array.CreateInstance(GetType(Double), 16)
  seOcc.GetMatrix(Matrix)

  Debug.Print(Matrix.GetValue(0))
  .
  .
  .
  Debug.Print(Matrix.GetValue(15))

Note the array of size 16 and index from 0 to 15 which can be represented in a matrix form as shown below:

CAT12.png

The position of each element has a special meaning in the matrix.

For example, the positions highlighted below are the translations, meaning moving an occurrence along the X, Y and Z directions respectively.

CAT10.png

These correspond to the elements at position 12, 13 and 14 in the array.

Therefore, to move an occurrence along the X-Axis:


  1. Get the occurrence matrix into an array of Doubles.

  2. Change the 12th element in the array.

  3. Assign the matrix back to the occurrence.


  seMatrix.SetValue(0.125, 12)
seOcc.PutMatrix(seMatrix, True)
End Sub

CAT13.png


Similarly, to rotate the occurrence about the Z-axis by 30, the calculations are as shown in the image below and assign to the corresponding 4 elements of the matrix.

CAT11.pngTipIcon.png Note: The rotation angle in radians array:


To rotate an occurrence about the X-axis:


CAT14.png

To rotate an occurrence about the Y-axis:


CAT15.png

This concludes the series on Conversion and Transformations using the Solid Edge API.

If you have any questions, please use the Solid Edge Developer forum to post messages.

Tushar Suradkar


www.CADVertex.com


www.SurfAndCode.IN

Solid Edge User Group on FaceBook:


https://www.facebook.com/groups/solidedgeusers/

Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/solidedge/conversions-and-transformations-using-the-solid-edge-api-part-4/