


{"id":293765,"date":"2023-07-19T03:50:35","date_gmt":"2023-07-19T03:50:35","guid":{"rendered":"\/forum\/forums\/reply\/293765\/"},"modified":"2023-07-19T03:50:35","modified_gmt":"2023-07-19T03:50:35","slug":"293765","status":"publish","type":"reply","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/reply\/293765\/","title":{"rendered":"Reply To: SpaceClaim Python API: Extruding Rectangle Sketch"},"content":{"rendered":"<p>&lt;p&gt;Also, creating a robust script is different than the actions a user would normally use in the GUI.&lt;\/p&gt;&lt;p&gt;You want to get the returned entities from creation functions. Most results have a list of a specific type underneath, such as .CreatedPlanes .CreatedCurves, .CreatedBodies, CreatedFaces, etc&#8230;&lt;br&gt;face1 = result.CreatedFaces[0]&lt;\/p&gt;&lt;p&gt;You can use dir(result) to see the objects underneath.&lt;\/p&gt;&lt;p&gt;Use .GetCreated to get entities of a type:&lt;br&gt;result = DatumPlaneCreator.Create(origin, Direction)&lt;br&gt;plane1 = result.GetCreated[IDatumPlane]()&lt;\/p&gt;&lt;p&gt;Also, you want to use bottom-up type methodology so you don&#8217;t lose a reference to the previous entities created. So that means: create points\/curves, then faces, then bodies. When sketching , you&#8217;ll want to turn on &#8220;Layout sketch&#8221; in the options.&lt;\/p&gt;&lt;p&gt;<img decoding=\"async\" src=\"\/forum\/wp-content\/uploads\/sites\/2\/2023\/07\/19-07-2023-1689738168-mceclip0.png\" \/>&lt;\/p&gt;&lt;p&gt;This will record the command:&lt;\/p&gt;&lt;p&gt;SketchHelper.LayoutCurves = True&lt;\/p&gt;&lt;p&gt;So you&#8217;ll just have curves when you go to 3D mode. You will need to create a surface with Fill or Blend, but you&#8217;ll still have the curve references when you go to 3D and you&#8217;ll then have the surface reference when you create the surface.&lt;\/p&gt;&lt;p&gt;ClearAll() &nbsp; &nbsp;# good to do this at the beginning so you always start from the same state, and entity indices don&#8217;t continue from some previously defined indices&lt;br&gt;extrudeDepth = MM(40)&lt;br&gt;BaseLength = MM(20)&lt;br&gt;BaseWidth = MM(16)&lt;br&gt;# Set Sketch Plane&lt;br&gt;sectionPlane = Plane.PlaneXY&lt;br&gt;result = ViewHelper.SetSketchPlane(sectionPlane, None)&lt;br&gt;# Set Layout Curves&lt;br&gt;SketchHelper.StartConstraintSketching()&lt;br&gt;SketchHelper.LayoutCurves = True&lt;br&gt;# Sketch Line&lt;br&gt;start = Point2D.Create(MM(0), MM(0))&lt;br&gt;end = Point2D.Create(BaseLength, MM(0))&lt;br&gt;result = SketchLine.Create(start, end)&lt;br&gt;crv1 = result.CreatedCurves[0]&lt;br&gt;# Sketch Line&lt;br&gt;start = Point2D.Create(BaseLength, MM(0))&lt;br&gt;end = Point2D.Create(BaseLength, BaseWidth)&lt;br&gt;result = SketchLine.Create(start, end)&lt;br&gt;crv2 = result.CreatedCurves[0]&lt;br&gt;# Sketch Line&lt;br&gt;start = Point2D.Create(BaseLength, BaseWidth)&lt;br&gt;end = Point2D.Create(MM(0), BaseWidth)&lt;br&gt;result = SketchLine.Create(start, end)&lt;br&gt;crv3 = result.CreatedCurves[0]&lt;br&gt;# Sketch Line&lt;br&gt;start = Point2D.Create(MM(0), BaseWidth)&lt;br&gt;end = Point2D.Create(MM(0), MM(0))&lt;br&gt;result = SketchLine.Create(start, end)&lt;br&gt;crv4 = result.CreatedCurves[0]&lt;br&gt;# Solidify Sketch&lt;br&gt;mode = InteractionMode.Solid&lt;br&gt;result = ViewHelper.SetViewMode(mode, None)&lt;br&gt;# Extrude 1 Edge&lt;br&gt;selection = Selection.Create(crv1)&lt;br&gt;options = ExtrudeEdgeOptions()&lt;br&gt;pnt1 = crv1.Shape.StartPoint&lt;br&gt;result = ExtrudeEdges.Execute(selection, pnt1, Direction.DirZ, extrudeDepth, options)&lt;br&gt;face1 = result.CreatedFaces[0]&lt;br&gt;body1 = face1.Parent&lt;br&gt;# Extrude 1 Edge&lt;br&gt;selection = Selection.Create(crv2)&lt;br&gt;pnt1 = crv2.Shape.StartPoint&lt;br&gt;result = ExtrudeEdges.Execute(selection, pnt1, Direction.DirZ, extrudeDepth, options)&lt;br&gt;face2 = result.CreatedFaces[0]&lt;br&gt;body2 = face2.Parent&lt;br&gt;# Extrude 1 Edge&lt;br&gt;selection = Selection.Create(crv3)&lt;br&gt;pnt1 = crv3.Shape.StartPoint&lt;br&gt;result = ExtrudeEdges.Execute(selection, pnt1, Direction.DirZ, extrudeDepth, options)&lt;br&gt;face3 = result.CreatedFaces[0]&lt;br&gt;body3 = face3.Parent&lt;br&gt;# Extrude 1 Edge&lt;br&gt;selection = Selection.Create(crv4)&lt;br&gt;pnt1 = crv4.Shape.StartPoint&lt;br&gt;result = ExtrudeEdges.Execute(selection, pnt1, Direction.DirZ, extrudeDepth, options)&lt;br&gt;face4 = result.CreatedFaces[0]&lt;br&gt;body4 = face4.Parent&lt;br&gt;# Fill&lt;br&gt;selection = Selection.Create([crv1,crv2,crv3,crv4])&lt;br&gt;secondarySelection = Selection.Empty()&lt;br&gt;options = FillOptions()&lt;br&gt;result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, None)&lt;br&gt;face5 = result.CreatedFaces[0]&lt;br&gt;body5 = face5.Parent&lt;br&gt;# Merge Bodies&lt;br&gt;targets = BodySelection.Create(body1)&lt;br&gt;tools = BodySelection.Create(body2, body3, body4, body5)&lt;br&gt;result = Combine.Merge(targets, tools)&lt;br&gt;# Fix Missing Face&lt;br&gt;options = FixMissingFacesOptions()&lt;br&gt;result = FixMissingFaces.FindAndFix(options, None)&lt;br&gt;#FixMissingFaces.FindAndFix does not return the faces creates. Knowing only one hole will be filled, get the last face in the list:&lt;br&gt;face6 = body1.Faces[-1] &nbsp; &nbsp;# Only body1 is left since all the other bodies were tool bodies to merge to body1&lt;br&gt;# Create Named Selection Group&lt;br&gt;primarySelection = BodySelection.Create(body1)&lt;br&gt;secondarySelection = Selection.Empty()&lt;br&gt;result = NamedSelection.Create(primarySelection, secondarySelection)&lt;br&gt;result = NamedSelection.Rename(&#8220;Group1&#8221;, &#8220;My Body1&#8221;)&lt;br&gt;# Create Named Selection Group&lt;br&gt;primarySelection = FaceSelection.Create(face1)&lt;br&gt;secondarySelection = Selection.Empty()&lt;br&gt;result = NamedSelection.Create(primarySelection, secondarySelection)&lt;br&gt;result = NamedSelection.Rename(&#8220;Group1&#8221;, &#8220;My face1&#8221;)&lt;\/p&gt;&lt;p&gt;At the end, I still had the faces and body I could place in a named selection.&lt;br&gt;I did choose to use &#8220;Repair &gt; Missing Faces&#8221; to make face6, and this does not return the face created, so I just got last face in the list. This is not the best means of creation if you wanted to track face6 to place in a named selection. It may be better to create all the wireframe edges of the body, and Fill or Blend each surface instead of pulling the 4 edges like I did so that you can track more explicitly all 6 faces made from the fill or blend operation.&lt;\/p&gt;<\/p>\n","protected":false},"template":"","class_list":["post-293765","reply","type-reply","status-publish","hentry"],"aioseo_notices":[],"acf":[],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies\/293765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/reply"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/replies\/293765\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=293765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}