


{"id":288191,"date":"2023-06-12T13:08:29","date_gmt":"2023-06-12T13:08:29","guid":{"rendered":"\/forum\/forums\/topic\/spaceclaim-script-selection-by-filterbyboundingbox\/"},"modified":"2023-06-15T09:17:16","modified_gmt":"2023-06-15T09:17:16","slug":"spaceclaim-script-selection-by-filterbyboundingbox","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/spaceclaim-script-selection-by-filterbyboundingbox\/","title":{"rendered":"SpaceClaim Script: Selection by FilterByBoundingBox"},"content":{"rendered":"<p class=\"MsoNormal\">Dear Ansys Learning Forum Community,<\/p>\n<p class=\"MsoNormal\">I am trying to select a specific face in a geometry. The easiest way to do this task is by knowing in advance the index of the face of interest. However, this option lacks of scalability if my geometry is modified or generated in a different order. This solution is referred as Option 1.<\/p>\n<p class=\"MsoNormal\">So, other option is to use the FilterByArea method. This works fine as long as your faces have a unique area, otherwise, you will select multiple faces instead of only one. This solution is referred as Option 2.<\/p>\n<p class=\"MsoNormal\">Then, by searching the available options, there is the FilterByBoundingBox method where you can select a face that intersects with a previously defined box. This method looks as the most generic so that you can control the way a face is selected. However, due to the lack of documentation in SpaceClaim or the absence of a similar example, I am not able to use this method properly. Maybe is due to an error in the syntax or in my understanding of the method. Please, could you help me? This solution is referred as Option 3.<\/p>\n<p class=\"MsoNormal\">Attached you will find a minimal working example (MWE) with the implementation of Option 1, 2 and 3. This last one is currently not working as is the one I am interested the most. Feel free to add\/modify its content.<\/p>\n<p class=\"MsoNormal\">However, if you know a better solution to select a specific face (i.e based on its normal or another feature, feel free to share your valuable know-how)<\/p>\n<p class=\"MsoNormal\">As always, thank you for your help.<\/p>\n<p class=\"MsoNormal\">Best regards,<\/p>\n<p class=\"MsoNormal\">Ramiro<\/p>\n<h6 class=\"MsoNormal\">#####<\/h6>\n<pre>\"\"\"<br>Minimal Working Example MWE<br>Author: Ramiro MENA ANDRADE<br>Date: 2023-06-12<br><br><br>Script to generate a Cube of dimensions Cube_X, Cube_Y and Cube_Z<br>and select faces based on three different methods:<br>&nbsp; &nbsp; - Option1: When the index of the face is known in advance (not useful to fully automatize a code)<br>&nbsp; &nbsp; - Option2: By using FilterByArea method (not useful if more than one face has the same area)<br>&nbsp; &nbsp; - Option3: By using FilterByBoundingBox method (could be useful, but I do not know how to write the proper syntax)<br>\"\"\"<br><br># Python Script, API Version = V19<br>#*************************************<br># Part 1: Geometry definition (dimensions in mm)<br>#*************************************<br>Cube_X= 10<br>Cube_Y= 20<br>Cube_Z= 5<br><br>pointA = [0,0]<br>pointB = [Cube_X,0]<br>pointC = [Cube_X,Cube_Y]<br><br>tol = 0.01 #define a tolerance<br>area = Cube_X*Cube_Y #calculate the area<br><br>#%%<br>#*********************************<br>#Part2: Geometry generation<br>#*********************************<br>sectionPlane = Plane.PlaneXY<br>result = ViewHelper.SetSketchPlane(sectionPlane, None)<br># EndBlock<br><br># Set New Sketch<br>result = SketchHelper.StartConstraintSketching()<br># EndBlock<br><br># Sketch Rectangle<br>point1 = Point2D.Create(MM(pointA[0]),MM(pointA[1]))<br>point2 = Point2D.Create(MM(pointB[0]),MM(pointB[1]))<br>point3 = Point2D.Create(MM(pointC[0]),MM(pointC[1]))<br>result = SketchRectangle.Create(point1, point2, point3)<br><br># Solidify Sketch<br>mode = InteractionMode.Solid<br>result = ViewHelper.SetViewMode(mode, None)<br># EndBlock<br><br># Extrude 1 Face<br>selection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[:])<br>options = ExtrudeFaceOptions()<br>options.ExtrudeType = ExtrudeType.Add<br>result = ExtrudeFaces.Execute(selection, MM(Cube_Z), options)<br># EndBlock<br><br>#%%<br>#************************************************<br>#Part 3: Selection of faces by different methods<br>#*************************************************<br><br># OPTION 1: Create Named Selection Group (Top)&nbsp;<br># PROBLEM: YOU NEED TO KNOW IN ADVANCE THE INDEX OF THE FACE<br>primarySelection = FaceSelection.Create(GetRootPart().Bodies[0].Faces[0])<br>secondarySelection = Selection.Empty()<br>result = NamedSelection.Create(primarySelection, secondarySelection)<br>result = NamedSelection.Rename(\"Group1\", \"Option1\")<br># EndBlock<br><br><br>#OPTION 2: Create a named selection by using FilterByArea<br>#PROBLEM: FOR THIS CASE, MULTIPLE FACES CAN HAVE THE SAME AREA, SO YOU CAN NOT SELECT A SPECIFIC FACE<br>comp = Selection.Create(GetRootPart())<br>faces = comp.ConvertToFaces().FilterByArea(MM2(area-tol),MM2(area+tol))<br>faces.CreateAGroup('Option2')<br><br>#OPTION 3: Create a named selection by using FilterByBoundingBox Method<br>#PROBLEM: I DO NOT KNOW THE PROPER SYNTAX FOR USING THIS METHOD CORRECTLY<br><br>#Create Points&nbsp;<br>min_point = Point.Create(MM(pointA[0]), MM(pointA[1]), MM(0))<br>max_point = Point.Create(MM(pointC[0]), MM(pointC[1]), MM(0))<br><br>#Create a Box<br>mbox = Box.Create(min_point, max_point)<br><br>#Apply the Filter to a face (fface means filtered face)<br>fface = comp.ConvertToFaces().FilterByBoundingBox(mbox)<br>fface.CreateAGroup('Option3')<br><br><\/pre>\n","protected":false},"template":"","class_list":["post-288191","topic","type-topic","status-closed","hentry","topic-tag-geometry","topic-tag-scripting","topic-tag-spaceclaim"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["187145","200","64297"],"_bbp_author_ip":["23.47.145.29"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["5793"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["288191"],"_bbp_forum_id":["27789"],"_bbp_engagement":["200","64297","187145"],"_bbp_voice_count":["3"],"_bbp_reply_count":["7"],"_bbp_last_reply_id":["310002"],"_bbp_last_active_id":["310002"],"_bbp_last_active_time":["2023-10-04 10:45:49"]},"test":"ramiromena"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/288191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/288191\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=288191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}