{"id":3174,"date":"2019-06-17T23:47:29","date_gmt":"2019-06-18T06:47:29","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Conversions-and-Transformations-using-the-Solid-Edge-API-Part-4\/ba-p\/594481"},"modified":"2020-02-17T09:42:31","modified_gmt":"2020-02-17T14:42:31","slug":"conversions-and-transformations-using-the-solid-edge-api-part-4","status":"publish","type":"post","link":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/conversions-and-transformations-using-the-solid-edge-api-part-4\/","title":{"rendered":"Conversions and Transformations using the Solid Edge API &#8211; Part 4"},"content":{"rendered":"<p><P><a href=\"https:\/\/community.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Conversions-and-Transformations-using-the-Solid-Edge-API-Part-3\/ba-p\/594317\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">&#8230;continued from part 3<\/A><\/P><\/p>\n<p><P>This series of articles discusses the following:<\/P><\/p>\n<p><OL><br \/>\n<LI><U>Document Unit Conversion<\/U><SPAN>&nbsp;<\/SPAN>&#8211; ParseUnit and Format Unit methods of the UnitsOfMeasure object.<\/LI><br \/>\n<LI><U>View Coordinate Conversion<\/U><SPAN>&nbsp;<\/SPAN>&#8211; ViewToSheetViewToSheetViewToSheetViewToSheetViewToSheet and SheetToView methods of the DrawingView object.<\/LI><br \/>\n<LI><U>2D to 3D Conversion<\/U><SPAN>&nbsp;<\/SPAN>&#8211; Convert2DCoordinate method of the Profile object.<\/LI><br \/>\n<LI><U>3D to 2D Transformations<\/U><SPAN>&nbsp;<\/SPAN>&#8211; ModelToView method of the DrawingView object.<\/LI><br \/>\n<LI><U>Assembly Transformations<\/U><SPAN>&nbsp;<\/SPAN>&#8211; GetMatrix and PutMatrix methods of the Occurrence object.<\/LI><br \/>\n<\/OL><\/p>\n<p><P><STRONG>Assembly Transformations<\/STRONG><\/P><\/p>\n<p><P><SPAN>This part of the conversion and transformation series discusses the transformation of occurrences in the assembly using matrices. These transformations are movement and rotation.<\/SPAN><\/P><\/p>\n<p><P>An Occurrence object in the assembly has a Matrix Property which is an array and can be accessed as below:<\/P><\/p>\n<p><PRE>Imports SolidEdgeAssembly<\/p>\n<p>Module Module1<\/p>\n<p>Sub Main()<br \/>\n&nbsp; Dim seApp As SolidEdgeFramework.Application =&nbsp;Runtime.InteropServices.Marshal.GetActiveObject(&#8220;SolidEdge.Application&#8221;)<br \/>\n&nbsp; Dim seDoc As AssemblyDocument = seApp.ActiveDocument<br \/>\n&nbsp; Dim seOccs As Occurrences = seDoc.Occurrences<br \/>\n&nbsp; Dim seOcc As Occurrence = seOccs.Item(1)<\/p>\n<p>&nbsp; Dim Matrix = Array.CreateInstance(GetType(Double), 16)<br \/>\n&nbsp; seOcc.GetMatrix(Matrix)<\/p>\n<p>&nbsp; Debug.Print(Matrix.GetValue(0))<br \/>\n&nbsp; .<br \/>\n&nbsp; .<br \/>\n&nbsp; .<br \/>\n&nbsp; Debug.Print(Matrix.GetValue(15))<\/PRE><\/p>\n<p><P>Note the array of size 16 and index from 0 to 15 which can be represented in a matrix form as shown below:<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 207px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT12-1.png\" alt=\"CAT12.png\" title=\"CAT12.png\" \/><\/span><\/P><\/p>\n<p><P>The position of each element has a special meaning in the matrix.<\/P><\/p>\n<p><P>For example, the positions highlighted below are the translations, meaning moving an occurrence along the X, Y and Z directions respectively.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 369px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT10-1.png\" alt=\"CAT10.png\" title=\"CAT10.png\" \/><\/span><\/P><\/p>\n<p><P>These correspond to the elements at position 12, 13 and 14 in the array.<\/P><\/p>\n<p><P>Therefore, to move an occurrence along the X-Axis:<\/P><\/p>\n<p><OL><br \/>\n<LI>Get the occurrence matrix into an array of Doubles.<\/LI><br \/>\n<LI>Change the 12th element in the array.<\/LI><br \/>\n<LI>Assign the matrix back to the occurrence.<\/LI><br \/>\n<\/OL><br \/>\n<PRE>  seMatrix.SetValue(0.125, 12)<br \/>\n  seOcc.PutMatrix(seMatrix, True)<br \/>\nEnd Sub<\/PRE><br \/>\n<P><span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 600px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT13-1.png\" alt=\"CAT13.png\" title=\"CAT13.png\" \/><\/span><\/P><br \/>\n<P>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.<\/P><\/p>\n<p><P><span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 434px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT11-1.png\" alt=\"CAT11.png\" title=\"CAT11.png\" \/><\/span><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 30px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/TipIcon-62.png\" alt=\"TipIcon.png\" title=\"TipIcon.png\" \/><\/span>&nbsp;<STRONG>Note:<\/STRONG> The rotation angle in radians array:<\/P><br \/>\n<P>To rotate an occurrence about the X-axis:<\/P><br \/>\n<P><span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 503px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT14-1.png\" alt=\"CAT14.png\" title=\"CAT14.png\" \/><\/span><\/P><\/p>\n<p><P>To rotate an occurrence about the Y-axis:<\/P><br \/>\n<P><span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 532px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT15-1.png\" alt=\"CAT15.png\" title=\"CAT15.png\" \/><\/span><\/P><\/p>\n<p><P>This concludes the series on Conversion and Transformations using the Solid Edge API.<\/P><\/p>\n<p><P>If you have any questions, please use the <a href=\"http:\/\/community.plm.automation.siemens.com\/t5\/Solid-Edge-Developer-Forum\/bd-p\/SEDeveloperForum\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">Solid Edge Developer forum<\/A> to post messages.<\/P><\/p>\n<p><P><SPAN>Tushar Suradkar<\/SPAN><\/P><br \/>\n<P><SPAN><a href=\"http:\/\/www.cadvertex.com\/\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">www.CADVertex.com<\/A><\/SPAN><\/P><br \/>\n<P><a href=\"http:\/\/www.surfandcode.in\/2014\/01\/index-of-all-tutorials-on-this-solid.html\" target=\"_blank\" rel=\"noopener nofollow noreferrer\"><SPAN>www.SurfAndCode.IN<\/SPAN><\/A><\/P><\/p>\n<p><P>Solid Edge User Group on FaceBook:<\/P><br \/>\n<P><a href=\"https:\/\/www.facebook.com\/groups\/solidedgeusers\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https:\/\/www.facebook.com\/groups\/solidedgeusers\/<\/A><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;continued from part 3 <\/p>\n<p> This series of articles discusses the following: <\/p>\n<p> Document Unit Conversion &#8211; ParseUnit and Format Unit methods of the UnitsOfMeasure object.<br \/>\n V&#8230;<\/p>\n","protected":false},"author":42979,"featured_media":3196,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spanish_translation":"","french_translation":"","german_translation":"","italian_translation":"","polish_translation":"","japanese_translation":"","chinese_translation":"","footnotes":""},"categories":[1,96],"tags":[33],"industry":[],"product":[],"coauthors":[],"class_list":["post-3174","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","category-tips-tricks","tag-developer"],"featured_image_url":"https:\/\/blogs.stage.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT15-1.png","_links":{"self":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/3174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/users\/42979"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/comments?post=3174"}],"version-history":[{"count":8,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/3174\/revisions"}],"predecessor-version":[{"id":3197,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/3174\/revisions\/3197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media\/3196"}],"wp:attachment":[{"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media?parent=3174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/categories?post=3174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/tags?post=3174"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/industry?post=3174"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/product?post=3174"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.stage.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/coauthors?post=3174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}