{"id":3806,"date":"2019-05-25T07:48:33","date_gmt":"2019-05-25T14:48:33","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/Conversions-and-Transformations-using-the-Solid-Edge-API-Part-2\/ba-p\/594103"},"modified":"2026-03-26T07:29:00","modified_gmt":"2026-03-26T11:29:00","slug":"conversions-and-transformations-using-the-solid-edge-api-part-2","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/solidedge\/conversions-and-transformations-using-the-solid-edge-api-part-2\/","title":{"rendered":"Conversions and Transformations using the Solid Edge API &#8211; Part 2"},"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-1\/ba-p\/594024\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">Continuing from the previous part<\/A> that discussed the UnitsOfMeasure object, this part&nbsp;explains the conversion of sheet coordinates to view coordinates.<\/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; ViewToSheet 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><SPAN>View Coordinates Conversion<\/SPAN><\/STRONG><\/P><\/p>\n<p><P><SPAN>When you right-click a drawing view in a Draft sheet, one of the options is to zoom fit to the Drawing View<\/SPAN><\/P><\/p>\n<p><P><SPAN><span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 359px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT04-1.png\" alt=\"CAT04.png\" title=\"CAT04.png\" \/><\/span><\/SPAN><\/P><\/p>\n<p><P><SPAN>But other simpler drawing objects like lines and circles do not have this feature. Let\u2019s implement it.<\/SPAN><\/P><\/p>\n<p><P><SPAN>The coordinates of the bounding box or extents of an object can be determined by the Range Method.<\/SPAN><\/P><\/p>\n<p><PRE>Public Sub Range( _<br \/>\n&nbsp;&nbsp; ByRef XMin As Double, _<br \/>\n&nbsp;&nbsp; ByRef YMin As Double, _<br \/>\n&nbsp;&nbsp; ByRef XMax As Double, _<br \/>\n&nbsp;&nbsp; ByRef YMax As Double _<br \/>\n)<\/PRE><\/p>\n<p><P><SPAN>And depicted as below:<\/SPAN><\/P><br \/>\n<P><SPAN> <span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 366px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT05-1.png\" alt=\"CAT05.png\" title=\"CAT05.png\" \/><\/span><\/SPAN><\/P><\/p>\n<p><P>The image above shows the range of a bunch of objects for which a direct API does not exist.<\/P><br \/>\n<P>The function below determines the combined Range for a set of selected objects in Solid Edge Draft:<\/P><\/p>\n<p><P><SPAN>First check if the user has selected at least one drawing object:<\/SPAN><\/P><\/p>\n<p><PRE>Sub Main()<br \/>\n  Dim seApp As SolidEdgeFramework.Application = <BR \/>  System.Runtime.InteropServices.Marshal.GetActiveObject(&#8220;solidedge.application&#8221;)<br \/>\n  Dim seDoc As SolidEdgeDraft.DraftDocument = seApp.ActiveDocument<br \/>\n&nbsp; Dim seSheet As SolidEdgeDraft.Sheet = seDoc.ActiveSheet<br \/>\n&nbsp; Dim sSet As SelectSet = seDoc.SelectSet<\/p>\n<p>  If sSet.Count = 0 Then<br \/>\n    MsgBox(&#8220;select atleast one object.&#8221;)<br \/>\n&nbsp;&nbsp;&nbsp; End<br \/>\n&nbsp; End If<\/PRE><br \/>\n<P><SPAN>Next, take the first object in the select set as a seed object and get its range:<\/SPAN><\/P><\/p>\n<p><P>oSel.Item(1).Range(XMin, YMin, XMax, YMax)<\/P><\/p>\n<p><P><SPAN>Loop through all the objects in the select set and compare their extents with the seed object to determine which one has a greater extent:<\/SPAN><\/P><br \/>\n<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/P><br \/>\n<PRE>For i = 1 To oSel.Count<br \/>\n  oSel.Item(i).Range(X1, Y1, X2, Y2)<\/p>\n<p>&nbsp;&nbsp;If X1 &lt; XMin Then<br \/>\n&nbsp;&nbsp;  XMin = X1<br \/>\n&nbsp;&nbsp;End If<\/p>\n<p>&nbsp;&nbsp;If Y1 &lt; YMin Then<br \/>\n    YMin = Y1<br \/>\n  End If<\/p>\n<p>&nbsp;&nbsp;If X2 &gt; XMax Then<br \/>\n&nbsp;&nbsp;  XMax = X1<br \/>\n&nbsp;&nbsp;End If<\/p>\n<p>&nbsp;&nbsp;If Y2 &gt; YMax Then<br \/>\n&nbsp;&nbsp;  YMax = Y2<br \/>\n&nbsp;&nbsp;End If<br \/>\nNext<\/PRE><\/p>\n<p><P><SPAN>This finds the extents or bounding box of the objects combined.<\/SPAN><\/P><\/p>\n<p><P><SPAN>These values of the bounding box are in terms of the document units and the sheet coordinates increase in the North-East direction i.e. from Lower-Left corner to Upper-Right corner.<\/SPAN><\/P><\/p>\n<p><P><SPAN>For zooming the view to these coordinates, they need to be converted to the window or view coordinates who increase in the South-East direction meaning from Top-Left to the Bottom-Right corner as shown below:<\/SPAN><\/P><\/p>\n<p><P><SPAN><span class=\"lia-inline-image-display-wrapper lia-image-align-center\" style=\"width: 474px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT09-1.png\" alt=\"CAT09.png\" title=\"CAT09.png\" \/><\/span><\/SPAN><\/P><\/p>\n<p><P><SPAN>Convert the values obtained by the Range method to window coordinates using the ModelToWindow method:<\/SPAN><\/P><\/p>\n<p><PRE>oSheetWindow = oApp.ActiveWindow<\/p>\n<p>oSheetWindow.ModelToWindow(XMin, YMin, XWinMin, YWinMin)<br \/>\noSheetWindow.ModelToWindow(XMax, YMax, XWinMax, YWinMax)<\/PRE><br \/>\n<P><SPAN>Use these converted coordinates to zoom in using the ZoomArea method:<\/SPAN><\/P><\/p>\n<p><PRE>If XWin1 = XWin2 Then<br \/>\n&nbsp; XWin2 *= 1.1<br \/>\nEnd If<\/p>\n<p>If YWin1 = YWin2 Then<br \/>\n&nbsp; YWin2 *= 1.1<br \/>\nEnd If<\/p>\n<p>oSheetWindow.ZoomArea(XWin1, YWin1, XWin2, YWin2)<\/PRE><br \/>\n<P><SPAN>Add some extra checks before zooming to the area for vertical or horizontal lines since their coordinates could be the same and an area or window is not formed.<\/SPAN><\/P><\/p>\n<p><P><SPAN>Now you have a brand new command that zooms in an area formed by the extents of a bunch of selected object in Solid Edge Draft.<\/SPAN><\/P><\/p>\n<p><P><SPAN>In the next part of this article, I will show you how to perform a 3-step conversion of the center point coordinates of a hole in a part model all way to its coordinate in the Drawing Sheet in Draft.<\/SPAN><\/P><\/p>\n<p><P>If you have any questions related to this article, kindly post them on 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>.<\/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>Join the 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>&nbsp;<br \/>\n Continuing from the previous part that discussed the UnitsOfMeasure object, this part&nbsp;explains the conversion of sheet coordinates to view coordinates. <\/p>\n<p> This series of article&#8230;<\/p>\n","protected":false},"author":42979,"featured_media":3816,"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-3806","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","category-tips-tricks","tag-developer"],"featured_image_url":"https:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/CAT09-1.png","_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/3806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/users\/42979"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/comments?post=3806"}],"version-history":[{"count":4,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/3806\/revisions"}],"predecessor-version":[{"id":3817,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/3806\/revisions\/3817"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media\/3816"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media?parent=3806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/categories?post=3806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/tags?post=3806"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/industry?post=3806"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/product?post=3806"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/coauthors?post=3806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}