{"id":2743,"date":"2017-10-10T02:28:48","date_gmt":"2017-10-10T09:28:48","guid":{"rendered":"https:\/\/blogs.plm.automation.siemens.com\/t5\/Solid-Edge-Blog\/3D-Geometry-API-A-Gentle-Introduction\/ba-p\/438144"},"modified":"2026-03-26T07:29:51","modified_gmt":"2026-03-26T11:29:51","slug":"3d-geometry-api-a-gentle-introduction","status":"publish","type":"post","link":"https:\/\/blogs.sw.siemens.com\/solidedge\/3d-geometry-api-a-gentle-introduction\/","title":{"rendered":"3D Geometry API &#8211; A Gentle Introduction"},"content":{"rendered":"<p><P><SPAN>Among tangible or visible geometric elements, the prominently accessed collections in a Part or Sheetmetal document are the Features, Sketches, Profiles, PMI and the Reference Planes. The most sought after automation requirements include parametric updating of models or creation of simple parts involving sketches that are extruded or revolved.<\/SPAN><\/P><br \/>\n<P><SPAN>&nbsp; <\/SPAN><\/P><br \/>\n<P><SPAN>It is rare for a designer who is also typically a Mechanical guy having specialized as an automation programmer caring to think about diving into low level geometry like the faces, edges and vertices to manipulate model geometry in a more powerful and direct manner. <\/SPAN><\/P><\/p>\n<p><P><SPAN>But once you know how to extract and use it, the possibilities are endless. Some common examples would be custom composite holes or Sheetmetal punch shapes. A scenario of a custom composite hole would be a .150 diameter counterbore with a depth of .200.&nbsp; At the bottom of the counterbore is a thru hole of .050 diameter with a nearside countersink of .070 diameter.<\/SPAN><\/P><\/p>\n<p><P><SPAN><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 345px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/01_Custom_Composite_Hole-1.png\" alt=\"01_Custom_Composite_Hole.png\" title=\"01_Custom_Composite_Hole.png\" \/><\/span>&nbsp;<\/SPAN><\/P><br \/>\n<P><SPAN>Although this article does not aim to show you all the geometric calculations and APIs involved in achieving such composite holes, it is a beginning in the right direction.<\/SPAN><\/P><\/p>\n<p><P><SPAN>Note the additional Solid Edge Geometry reference that must be added which provides for the meaty part of the API involved in 3D geometry access and manipulation:<\/SPAN><\/P><\/p>\n<p><P><SPAN>&nbsp;<span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 201px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/05_References-1.png\" alt=\"05_References.png\" title=\"05_References.png\" \/><\/span><\/SPAN><\/P><\/p>\n<p><P><SPAN>Faces and Edges can be accessed for the entire model using the workflow below:<\/SPAN><\/P><\/p>\n<p><PRE>Dim seApp As SolidEdgeFramework.Application = GetActiveObject(&#8220;SolidEdge.Application&#8221;)<br \/>\nDim seDoc As SolidEdgePart.PartDocument = seApp.ActiveDocument<br \/>\n&nbsp;<br \/>\nDim seModel As Model = seDoc.Models(0)<br \/>\nDim seBody As Body = seModel.Body<br \/>\n&nbsp;<br \/>\nDim seFaces As Faces = seBody.Faces(FeatureTopologyQueryTypeConstants.igQueryAll)<br \/>\nDim seEdges As Edges = seBody.Edges(FeatureTopologyQueryTypeConstants.igQueryAll)<\/PRE><\/p>\n<p><P><SPAN>The FeatureTopologyQueryTypeConstants come from the SolidEdgeGeometry reference.<\/SPAN><\/P><br \/>\n<P><SPAN>The other possible filters are:<\/SPAN><\/P><\/p>\n<p><P><SPAN>&nbsp;<span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 456px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/03_Query-1.png\" alt=\"03_Query.png\" title=\"03_Query.png\" \/><\/span><\/SPAN><\/P><\/p>\n<p><P><SPAN>You can either query all faces or edges using igQueryAll and then check each one using its Geometry property in a loop as below:<\/SPAN><\/P><\/p>\n<p><PRE>Dim seFace As Face<br \/>\n&nbsp;<br \/>\nFor i As Integer = 0 To seFaces.Count &#8211; 1<br \/>\nseFace = seFaces.Item(i)<br \/>\n  If TypeOf (seFace.Geometry) Is SolidEdgeGeometry.Plane Then<br \/>\n    Debug.WriteLine(seFace.Area)<br \/>\n  End If<br \/>\nNext<\/PRE><\/p>\n<p><P><SPAN>Similarly, to check edges you use the Geometry property as shown next. <\/SPAN><\/P><br \/>\n<P><SPAN><span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 24px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/02_TipIcon-1.png\" alt=\"02_TipIcon.png\" title=\"02_TipIcon.png\" \/><\/span>&nbsp;Note how the geometry is compared with <EM>Line<\/EM> and <STRONG>not<\/STRONG> with <EM>Line2D<\/EM> from the SolidEdgeFrameworkSupport library. These two are entirely different species.<\/SPAN><\/P><\/p>\n<p><PRE>For Each seEdge As Edge In seEdges<br \/>\n  If TypeOf seEdge.Geometry Is Line Then<br \/>\n    Debug.WriteLine(GetEdgeLength(seEdge))<br \/>\n  End If<br \/>\nNext<\/PRE><\/p>\n<p><P><SPAN>Where the GetEdgeLength function looks like:<\/SPAN><\/P><br \/>\n<P><SPAN>&nbsp;<\/SPAN>&nbsp;<\/P><br \/>\n<PRE>Public Function GetEdgeLength(ByVal seEdge As Edge) As Double<br \/>\n  Dim StartVertex As Vertex = seEdge.StartVertex()<br \/>\n  Dim EndVertex As Vertex = seEdge.EndVertex<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;Dim StartVertexCoordinates(2) As Double<br \/>\n&nbsp;&nbsp;StartVertex.GetPointData(StartVertexCoordinates)<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;Dim EndVertexCoordinates(2) As Double<br \/>\n&nbsp;&nbsp;EndVertex.GetPointData(EndVertexCoordinates)<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;Dim StartX As Double = StartVertexCoordinates(0)<br \/>\n&nbsp;&nbsp;Dim StartY As Double = StartVertexCoordinates(1)<br \/>\n&nbsp;&nbsp;Dim StartZ As Double = StartVertexCoordinates(2)<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;Dim EndX As Double = EndVertexCoordinates(0)<br \/>\n&nbsp;&nbsp;Dim EndY As Double = EndVertexCoordinates(1)<br \/>\n&nbsp;&nbsp;Dim EndZ As Double = EndVertexCoordinates(2)<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;Dim EdgeLength As Double<br \/>\n&nbsp;&nbsp;EdgeLength = Math.Sqrt((StartX &#8211; EndX) ^ 2 + (StartX &#8211; EndY) ^ 2 + (StartXZ &#8211; EndZ) ^ 2)<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;Return EdgeLength<br \/>\nEnd Function<\/PRE><br \/>\n<P><SPAN>Another shorter method of getting the length of an edge is using the GetLengthAtParam function:<\/SPAN><\/P><\/p>\n<p><PRE>Dim seEdges As Edges = seBody.Edges(FeatureTopologyQueryTypeConstants.igQueryAll)<br \/>\n  <BR \/>Dim EdgeLength As Double, MinParam As Double, MaxParam As Double<BR \/>  <BR \/>For Each seEdge As Edge In seEdges<br \/>\n  If TypeOf seEdge.Geometry Is Line Then<BR \/>    seEdge.GetParamExtents(MinParam, MaxParam)<BR \/>    seEdge.GetLengthAtParam(MinParam, MaxParam, EdgeLength)<br \/>\n    Debug.WriteLine(EdgeLength)<br \/>\n  End If<br \/>\nNext<\/PRE><\/p>\n<p><P><SPAN>In the function for getting the edge length you also get a quick introduction to the Vertex object. The function also shows there are direct functions to get the start and end vertex of an edge.<\/SPAN><\/P><br \/>\n<P><SPAN>All vertices of the body can be accessed simply using with no additional parameters:<\/SPAN><\/P><\/p>\n<p><PRE>Dim seVertices As Vertices = seBody.Vertices()<br \/>\nDebug.WriteLine(seVertices.Count)<\/PRE><\/p>\n<p><P><SPAN>Similarly, vertices for one specific face can be extracted using:<\/SPAN><\/P><\/p>\n<p><PRE>seFace = seFaces.Item(0)<br \/>\nseVertices = seFace.Vertices<br \/>\nDebug.WriteLine(seVertices.Count)<\/PRE><\/p>\n<p><P><SPAN>Further, there are faces attached to an edge which can be obtained as below:<\/SPAN><\/P><\/p>\n<p><PRE>Dim seFaceArray() As Object = { }<br \/>\nDim FaceCount As Integer<br \/>\nDim seEdge As Edge = seEdges.Item(0)<\/p>\n<p>seEdge.GetFaces(FaceCount, seFaceArray)<\/PRE><\/p>\n<p><P>When you debug the above lines of code, note that the number of faces associated with an edge are always 2 so FaceCount will be 2<\/P><\/p>\n<p><P><SPAN>&nbsp;<span class=\"lia-inline-image-display-wrapper lia-image-align-inline\" style=\"width: 434px;\"><img decoding=\"async\" src=\"http:\/\/blogs.sw.siemens.com\/wp-content\/uploads\/sites\/8\/2019\/09\/04_FaceCount-1.png\" alt=\"04_FaceCount.png\" title=\"04_FaceCount.png\" \/><\/span><\/SPAN><\/P><br \/>\n<P><SPAN>Finally there are edges and faces attached to a vertex which can be obtained as below:<\/SPAN><\/P><\/p>\n<p><PRE>Dim seVertex As Vertex = seVertices.Item(0)<\/p>\n<p>seEdges = seVertex.Edges()<br \/>\nseFaces = seVertex.Faces<\/PRE><\/p>\n<p><P><EM>This shows that the Geometry objects like Faces, Edges and Vertices do not have a hierarchical structure like the other objects in the Solid Edge object model.<\/EM><\/P><\/p>\n<p><P><SPAN>In the next part of this&nbsp;article learn about:<\/SPAN><\/P><\/p>\n<p><OL><br \/>\n<LI><SPAN>What are Edge and Face IDs.<\/li>\n<p><LI><SPAN>How to reliably extract a face from its ID when the face is modified.<\/li>\n<p><LI><SPAN>Extracting Edges and faces of features.<\/li>\n<p><LI><SPAN>Special faces and edges of features.<\/li>\n<p><LI><SPAN>Highlighting edges, faces and vertices.<\/li>\n<p><LI><SPAN>How to use the TopoTools free tool to identify and highlight faces, edges and vertices.<\/li>\n<p><\/OL><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Among tangible or visible geometric elements, the prominently accessed collections in a Part or Sheetmetal document are the Features, Sketches, Profiles, PMI and the Reference Planes. The most sought&#8230;<\/p>\n","protected":false},"author":42979,"featured_media":2758,"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-2743","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\/02_TipIcon-1.png","_links":{"self":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/2743","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=2743"}],"version-history":[{"count":6,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/2743\/revisions"}],"predecessor-version":[{"id":2760,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/posts\/2743\/revisions\/2760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media\/2758"}],"wp:attachment":[{"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/media?parent=2743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/categories?post=2743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/tags?post=2743"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/industry?post=2743"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/product?post=2743"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blogs.sw.siemens.com\/solidedge\/wp-json\/wp\/v2\/coauthors?post=2743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}