# Python Script, API Version = V21 ClearAll() def create_a_plane_from_origin_and_normal(origin = [0, 0, 0], normalDirection = [0, 0, 1]): originPoint = Point.Create(origin[0], origin[1], origin[2]) dirZ = Direction.Create(normalDirection[0], normalDirection[1], normalDirection[2]) frame = Frame.Create(originPoint, dirZ) plane = Plane.Create(frame) return plane def get_group(groupName): groups = GetActiveWindow().ActiveWindow.Groups for group in groups: if group.GetName() == groupName: return group return None def get_dimension_value(group): tryGetDimensionResult = group.TryGetDimensionValue() if tryGetDimensionResult[0]: return True, tryGetDimensionResult[1] else: return False, 0 def set_dimension_value(group, value): group.SetDimensionValue(value) # Open Project File.Open(r"E:\Sctipts\Bracket.dsco") # Fill selection = Face1 secondarySelection = Selection.Empty() options = FillOptions() result = Fill.Execute(selection, secondarySelection, options, FillMode.ThreeD, Info1) # Thicken 9 Faces selection = FaceSelection.Create(Face0, Face1, Face2, Face3, Face4, Face5, Face6, Face7, Face8) options = ThickenFaceOptions() result = ThickenFaces.Execute(selection, Direction.Create(0.7071068, 0, 0.7071068), MM(-5), options) # EndBlock # Create 4 Rounds selection = PowerSelection.Edges.ByLength(Edge1, PowerSelectOptions(True), SearchCriteria.SizeComparison.Equal) options = ConstantRoundOptions() result = ConstantRound.Execute(selection, MM(2.5), options, Info1) # Save Project As File.SaveAs(r"E:\Scripts\U-Bracket.dsco") # Create a block startPoint = Point.Create(MM(5), MM(5), MM(15)) endPoint = Point.Create(MM(20), MM(20), MM(20)) BlockBody.Create(startPoint, endPoint) # Create rectangles RectangularSurface.Create(MM(40), MM(5),Point.Origin) RectangularSurface.Create(MM(5), MM(40),Point.Origin) # Merge rectangles allSurfaceBodies = PowerSelection.Bodies.AllSurfaceBodies() result = Combine.Merge(allSurfaceBodies) # Create a plane and switch to sketch mode origin = [MM(5), MM(5), MM(5)] plane = create_a_plane_from_origin_and_normal(origin) ViewHelper.SetSketchPlane(plane) # Sketch Spline points = List[Point2D]() points.Add(Point2D.Create(MM(0), MM(15))) points.Add(Point2D.Create(MM(5), MM(5))) points.Add(Point2D.Create(MM(15), MM(0))) result = SketchNurbs.CreateFrom2DPoints(False, points) splineCurve = result.CreatedCurves[0] # Switch to 3D mode mode = InteractionMode.Solid ViewHelper.SetViewMode(mode) # Extrude spline selection = Selection.Create(splineCurve) options = ExtrudeEdgeOptions() result = ExtrudeEdges.Execute(selection, Point.Origin, Direction.DirZ, MM(30), options) resultFace = result.CreatedFaces ## Slice block by resultFace toolFaces = Selection.Create(resultFace) selection = PowerSelection.Bodies.AllSolidBodies() result = SplitBody.ByCutter(selection, toolFaces, True) # delete unncessary bodies referencePoint = Point.Create(MM(5), MM(5), MM(15)) for body in GetRootPart().GetAllBodies(): if not body.Shape.ContainsPoint(referencePoint): body.Delete() # Extrude resulting surface body faceToExtrude = result.GetModified[IDesignFace]() faceToExtrudeSelection = Selection.Create(faceToExtrude) options = ExtrudeFaceOptions() options.ExtrudeType = ExtrudeType.Add result = ExtrudeFaces.Execute(faceToExtrudeSelection, MM(40), options) # Create the named selections Selection.Create(GetRootPart().Bodies).CreateAGroup("SolidBody") for face in GetRootPart().Bodies[0].Faces: if (face.Shape.ContainsPoint(Point.Create(MM(2.5), 0, MM(2.5)))): Selection.Create(face).CreateAGroup("Fixed support") if (face.Shape.ContainsPoint(Point.Create(0, MM(2.5), MM(2.5)))): Selection.Create(face).CreateAGroup("Pressure load") #How to Access Groups groups = GetActiveWindow().ActiveWindow.Groups for group in groups: print group.GetName() #How to get all items of a Group/Named Selection group = GetActiveWindow().ActiveWindow.Groups[0] Group.Members #or Selection.CreateByGroups("Height").Items heightGroup = get_group("Height") tryGetDimensionResult = heightGroup.TryGetDimensionValue() print tryGetDimensionResult topGroup = get_group("Top") tryGetDimensionResult = topGroup.TryGetDimensionValue() print tryGetDimensionResult heightGroup = get_group("Height") success, height = get_dimension_value(heightGroup) if success: print height heightGroup.SetDimensionValue(MM(5)) if success: print height set_dimension_value(heightGroup, height + MM(4)) #Using script parameter to create a surface Test = Parameters.Test print Test RectangularSurface.Create(Test,Test,Point.Origin) #Units of Script Parameters Length = Parameters.Length myUnits = UnitsHelper.GetDocumentUnits() print ("Parameter - SI units: " + str(Parameters.Length)) print ("Parameter - local units (" + myUnits.LengthProperties.Type.ToString() \ + "): " + str(Parameters.Length*myUnits.LengthFactor)) #Set radius1 to half of the initial value radius1Group = get_group("radius1") success, radius1 = get_dimension_value(radius1Group) if success: print radius1 set_dimension_value(radius1Group, radius1/2) #Set radius2 to 1.5x the initial value radius2Group = get_group("radius2") success, radius2 = get_dimension_value(radius2Group) if success: print radius2 set_dimension_value(radius2Group, radius2*1.5) #Set radius3 to initial value minus radius1 divided by 3 radius3Group = get_group("radius3") success, radius3 = get_dimension_value(radius3Group) if success: print radius3 set_dimension_value(radius3Group, radius3 - radius1/3) #Set thickness to 1.5x radius1 thicknessGroup = get_group("thickness") success, thickness = get_dimension_value(thicknessGroup) if success: print thickness set_dimension_value(thicknessGroup, 1.5*radius1) #Objects, Selections and Named Selections #Access Bodies: select bodies using part.Bodies Selection.Clear() part = GetRootPart() bodies = part.Bodies selection = Selection.Create(bodies) selection.SetActive() #Access Bodies: select bodies using part.GetBodies() Selection.Clear() part = GetRootPart() bodies = part.GetBodies() selection = Selection.Create(bodies) selection.SetActive() #select bodies using part.GetBodies(“filter”) Selection.Clear() part = GetRootPart() bodies = part.GetBodies("_2") selection = Selection.Create(bodies) selection.SetActive() #listing bodies using part.GetAllBodies() Selection.Clear() part = GetRootPart() bodies = part.GetAllBodies() for body in bodies: print body.GetName() #Index of bodies Selection.Clear() part = GetRootPart() bodies = part.GetAllBodies() for index,body in enumerate(bodies): print index,body.GetName() # Access Components: Selection.Clear() part = GetRootPart() for component in part.Components: print component.GetName() Selection.Clear() part = GetRootPart() for component in part.GetAllComponents(): print component.GetName() Selection.Clear() # Access Coordinate System: part = GetRootPart() for coordinateSystem in part.CoordinateSystems: print coordinateSystem.GetName() for coordinateSystem in part.Components[0].GetCoordinateSystems(): print coordinateSystem.GetName() for coordinateSystem in part.Components[0].GetAllCoordinateSystems(): print coordinateSystem.GetName() for coordinateSystem in part.GetDescendants[ICoordinateSystem](): print coordinateSystem.GetName() # Access Datum Plane part.DatumPlanes part.Components[0].GetDatumPlanes() part.Components[0].GetAllDatumPlanes() # Access Datum Lines part.DatumLines part.Components[0].GetDatumLines() part.Components[0].GetAllDatumLines() # Access Datum Points part.DatumPoints part.Components[0].GetDatumPoints() part.Components[0].GetAllDatumPoints() # Getting Faces of body: myBody = GetRootPart().Bodies[0] for myFace in myBody.Faces: myGeometry = myFace.Shape.Geometry if isinstance(myGeometry, Cone): ColorHelper.SetColor(Selection.Create(myFace), ColorHelper.Azure) if isinstance(myGeometry, Plane): ColorHelper.SetColor(Selection.Create(myFace), ColorHelper.Olive) if isinstance(myGeometry, Cylinder): ColorHelper.SetColor(Selection.Create(myFace), ColorHelper.Violet) # Getting Descandants myBody = GetRootPart().Bodies[0] myEgdes = myBody.GetDescendants[IDesignEdge]() mySel = Selection.Create(myEgdes) mySel.SetActive() # Getting newly created entities: myBody = GetRootPart().Bodies[0] myEgdes = myBody.GetDescendants[IDesignEdge]() mySel = Selection.Create(myEgdes) myOptions = ConstantRoundOptions() result = ConstantRound.Execute(mySel, MM(1), myOptions) mySelection = Selection.Create(result.CreatedFaces) ColorHelper.SetColor(mySelection, ColorHelper.Cyan) cfaces = result.CreatedFaces length_cfaces = len(cfaces) MessageBox.Show("Number of Created Faces:" + str(length_cfaces)) # Getting Modified entities myBody = GetRootPart().Bodies[0] myEgdes = myBody.GetDescendants[IDesignEdge]() mySel = Selection.Create(myEgdes) myOptions = ConstantRoundOptions() result = ConstantRound.Execute(mySel, MM(1), myOptions) mySelection = Selection.Create(result.CreatedFaces) ColorHelper.SetColor(mySelection, ColorHelper.Cyan) mySelection = Selection.Create(result.GetModified[IDesignFace]()) ColorHelper.SetColor(mySelection, ColorHelper.Magenta) # Operating on Object lists myBodies = GetRootPart().GetAllBodies() Selection.Create(myBodies).SetActive() myBodies.Remove(GetRootPart().GetAllBodies()[1]) Selection.Create(myBodies).SetActive() myBodies.Remove(GetRootPart().GetAllBodies()[2]) Selection.Create(myBodies).SetActive() myBodies.Add(GetRootPart().GetAllBodies()[1]) Selection.Create(myBodies).SetActive() # Selecting entities mySel_0 = Selection.GetActive() for body in mySel_0.GetItems[IDesignBody](): print body.GetName() mySel_1 = Selection.CreateByNames("myCylinder") mySel_1.SetActive() Selection.Clear() mySel_1.GetInverse().SetActive() mySel_2 = Selection.CreateByGroups("top") mySel_2.SetActive() mySel_3 = Selection.CreateByNames("myBox") mySel_3.AddToActive() mySel_4 = Selection.SelectAll() mySel_4.SetActive() mySel_5 = mySel_4 - mySel_3 mySel_5.SetActive() # ---------------------Selecting entities-------------------------------------- # gets the current selection from the active view mySel_1 = Selection.GetActive() # creates inverted selection mySel_2 = mySel_1.GetInverse() # selects objects from this selection in active view mySel_2.SetActive() # Power Selection seedSelection = Selection.CreateByNames("b0700") powSelection = PowerSelection.Bodies.ByVolume(seedSelection, PowerSelectOptions(True), SearchCriteria.SizeComparison.SmallerOrEqual) powSelection.SetActive() seedSelection = Selection.CreateByNames("Bolt_7") powSelection = PowerSelection.Bodies.ByVolume(seedSelection, PowerSelectOptions(False), SearchCriteria.SizeComparison.SmallerOrEqual) powSelection.SetActive() # Power Selection – selecting other bodies otherBodies=Selection.Create(GetRootPart().GetAllBodies()) options=PowerSelectOptions(False, otherBodies) seed=Selection.Create(GetRootPart().GetAllBodies("Bolt_3")) pSel=PowerSelection.Bodies.ByVolume(seed, options, \ SearchCriteria.SizeComparison.LargerOrEqual) pSel.SetActive() otherBodies=Selection.Create(GetRootPart().GetBodies()) options=PowerSelectOptions(False, otherBodies) seed=Selection.Create(GetRootPart().GetAllBodies("Bolt_3")) pSel=PowerSelection.Bodies.ByVolume(seed, options, \ SearchCriteria.SizeComparison.LargerOrEqual) pSel.SetActive() # Power Selection – selecting seed options=PowerSelectOptions(True,None,True) seed=Selection.Create(GetRootPart().GetAllBodies("Bolt_7")) pSel=PowerSelection.Bodies.ByVolume(seed, options, \ SearchCriteria.SizeComparison.SmallerOrEqual) pSel.SetActive() options=PowerSelectOptions(True,None,False) seed=Selection.Create(GetRootPart().GetAllBodies("Bolt_7")) pSel=PowerSelection.Bodies.ByVolume(seed, options, \ SearchCriteria.SizeComparison.SmallerOrEqual) pSel.SetActive() # Multiple Objects Selection b1 = GetRootPart().Bodies[0] b2 = GetRootPart().Bodies[1] b3 = GetRootPart().Bodies[2] # Approach 1 s1 = Selection.Create(b1, b2, b3) # Approach 2 body_list = [b1, b2] body_list.Add(b3) s2 = Selection.Create(body_list) # Approach 3 list = List[IDesignBody]() list.Add(b1) list.Add(b2) list.Add(b3) s3 = Selection.Create(list) # Approach 4 s4 = Selection.Create(b1, b2) s4 = s4 + Selection.Create(b3) s4.SetActive() # Mixed Selections b1 = GetRootPart().Bodies[0] b2 = GetRootPart().Bodies[1] b3 = GetRootPart().Bodies[2] f1 = b3.Faces[0] f2 = b3.Faces[1] # Approach 1 s1 = Selection.Create(b1, b2, f1, f2) # Approach 2 b_list = [b1, b2] f_list = [f1, f2] s2 = Selection.Create(b_list + f_list) s2.SetActive() # Multiple objects selection b1 = GetRootPart().Bodies[0] b2 = GetRootPart().Bodies[1] b3 = GetRootPart().Bodies[2] f1 = b3.Faces[0] f2 = b3.Faces[1] b_list = [b1, b2] f_list = [f1, f2] sel1 = Selection.CreateByObjects([b1, f_list]) sel2 = Selection.CreateByObjects([b_list, f_list]) sel3 = Selection.Create(b1, f1, f2) sel3.SetActive() #Creating Named Selections for face in GetRootPart().Bodies[0].Faces: myNS=NamedSelection.Create(Selection.Create(face),Selection()) if isinstance(face.Shape.Geometry, Cylinder): myNS.CreatedNamedSelection.SetName("sideWall") elif face not in Selection.CreateByGroups("inlet").GetItems[IDesignFace](): myNS.CreatedNamedSelection.SetName("outlet") else: myNS.CreatedNamedSelection.Delete() myNS=NamedSelection.Create(Selection.CreateByNames("cylinder"),Selection()) myNSName=myNS.CreatedNamedSelection.GetName() NamedSelection.Rename(myNSName,"myCylinder") Selection.Create(GetRootPart().Bodies[0]).CreateAGroup("myCyl") part = GetRootPart() for component in part.Components: bodies = component.GetAllBodies() selection = Selection.Create(bodies) selection.SetActive() # Move bodies to root component result = ComponentHelper.MoveBodiesToComponent(selection, part, False) # Delete Empty Components ComponentHelper.DeleteEmptyComponents(part) Selection.Clear() myBodies = List[IDesignBody]() part = GetRootPart() for body in part.GetAllBodies(): if body.Shape.Volume <= 3e-07 : myBodies.Add(body) Selection.Create(myBodies).SetActive() myFilter=3e-7 for body in GetRootPart().GetAllBodies(): if body not in GetRootPart().GetBodies(): ComponentHelper.MoveBodiesToComponent(Selection.Create(body),\ GetRootPart().Root) for comp in GetRootPart().GetAllComponents(): ComponentHelper.DeleteEmptyComponents(Selection.Create(comp)) myPowSel=PowerSelection.Bodies.ByVolume(myFilter, None, \ SearchCriteria.SizeComparison.SmallerOrEqual) myPowSelInv=Selection.Create(GetRootPart().GetAllBodies())-myPowSel result = ComponentHelper.MoveBodiesToComponent(myPowSel) result.CreatedComponents[0].SetName("smallBodies") result = ComponentHelper.MoveBodiesToComponent(myPowSelInv) result.CreatedComponents[0].SetName("bigBodies") #Demo 1: Creating cylinders by extruding surfaces ClearAll() myDiameter = [10,30,20,40,60] myLength = [50,75,25,10,60] z_offset = 100 # cylinder creation version 1 for i in range(len(myDiameter)): myFace = CircularSurface.Create(myDiameter[i]/2, Direction.DirZ, Point.Create(0,0, sum(myLength[:i])-myLength[0] + z_offset)).CreatedBody.Faces options = ExtrudeFaceOptions() options.ExtrudeType = ExtrudeType.ForceIndependent result = ExtrudeFaces.Execute(Selection.Create(myFace), myLength[i], options) result.CreatedBodies[0].SetName("Cylinder_v1_"+str(i)) Selection.Clear() ViewHelper.ZoomToEntity() # Solidify Sketch mode = InteractionMode.Solid result = ViewHelper.SetViewMode(mode) # Demo 2 ClearAll() myDiameter = [10,30,20,40,60] myLength = [50,75,25,10,60] z_offset = 100 # cylinder creation version 2 for i in range(len(myDiameter)): myCenterBottom=Point.Create(0, (sum(myLength[:i] ) - myLength[0]) + z_offset ,0) myCenterTop=Point.Create(myCenterBottom.X, myCenterBottom.Y+myLength[i] ,myCenterBottom.Z) myDragPoint=Point.Create(myDiameter[i]/2., myCenterTop.Y,myCenterTop.Z) result=CylinderBody.Create(myCenterBottom, myCenterTop,myDragPoint,ExtrudeType.ForceIndependent) result.CreatedBodies[0].SetName("Cylinder_v2_"+str(i)) Selection.Clear() ViewHelper.ZoomToEntity() # Solidify Sketch mode = InteractionMode.Solid result = ViewHelper.SetViewMode(mode) #Demo 3 ClearAll() from math import tan, pi myConeHeight=0.02 myConeAngle=DEG(30) ViewHelper.SetSketchPlane(Plane.PlaneXY) pt1 = Point2D.Create(0,0) pt2 = Point2D.Create(0,myConeHeight) pt3 = Point2D.Create(myConeHeight*tan(myConeAngle/2),0) SketchLine.Create(pt1, pt2) SketchLine.Create(pt2, pt3) SketchLine.Create(pt3, pt1) result=ViewHelper.SetViewMode(InteractionMode.Solid) mySel=Selection.Create(result.CreatedBodies[0].Faces) myAxis = Line.Create(Point.Origin,Direction.DirY) myOptions = RevolveFaceOptions() myOptions.ExtrudeType = ExtrudeType.Add RevolveFaces.Execute(mySel, myAxis, DEG(360), myOptions) Selection.Clear() ViewHelper.ZoomToEntity() # Demo 4 ClearAll() pt1=Point.Origin pt2=Point.Create(MM(10),MM(2),MM(2)) result=BlockBody.Create(pt1,pt2,ExtrudeType.Add) b0=result.CreatedBody for i in range(10): mySel = Selection.Create(b0) direction = Direction.DirY options = MoveOptions() options.Copy = True result = Move.Translate(mySel, direction, (i+1)*MM(10), options) Selection.Clear() ViewHelper.ZoomToEntity() # Demo 5 ClearAll() pt1=Point.Create(MM(-10),MM(0),MM(0)) pt2=Point.Create(pt1.X+MM(2),pt1.Y+MM(2),pt1.Z+MM(2)) result=BlockBody.Create(pt1,pt2,ExtrudeType.Add) b0=result.CreatedBody for i in range(11): mySel = Selection.Create(b0) axis = Line.Create(Point.Origin, Direction.DirZ) options = MoveOptions() options.Copy = True result = Move.Rotate(mySel, axis, (i+1)*DEG(30), options) Selection.Clear() ViewHelper.ZoomToEntity() # Demo from SpaceClaim.Api.V21 import Command import os ClearAll() #Import the geometry my_path = os.path.dirname(GetActiveWindow().Document.Path) DocumentInsert.Execute(os.path.join(my_path, "valve1.dsco")) Selection.Create(GetRootPart().Components[0]).SetActive() c = Command.GetCommand("ImportComponentGroups") c.Execute() ViewHelper.ZoomToEntity() #Fill the surface holes < criteria criteria_radius = MM(7) total_selection = Selection.Empty() selection1 = PowerSelection.Faces.BySurfaceHoleRadius(criteria_radius, PowerSelectOptions(True), SearchCriteria.SizeComparison.SmallerOrEqual) total_selection += selection1 total_selection.SetActive() result = Fill.Execute(total_selection) #Remove all chamfers and rounds criteria_radius = MM(20) total_selection = PowerSelection.Faces.ByRoundRadius(criteria_radius, PowerSelectOptions(True), SearchCriteria.SizeComparison.SmallerOrEqual, SearchCriteria.RoundType.All) for body in GetRootPart().GetAllBodies(): for face in body.Faces: if isinstance(face.Shape.Geometry, Cone): total_selection += Selection.Create(face) total_selection.SetActive() result = Fill.Execute(total_selection) #Create missing bodies from Named Selections and move them to new components ComponentHelper.SetActive(Selection.Create(GetRootPart().Components[0]), None) options = LoftOptions() options.IsRuled = True selection = Selection.CreateByGroups("Right_elbow_in") selection += Selection.CreateByGroups("Right_connector_out") result = Loft.Create(selection, None, options) selection = Selection.Create(result.CreatedBodies[0]) result = ComponentHelper.MoveBodiesToComponent(selection) result.CreatedComponents[0].SetName("Right_connector") selection = Selection.CreateByGroups("Left_elbow_in") selection += Selection.CreateByGroups("Left_connector_out") result = Loft.Create(selection, None, options) selection = Selection.Create(result.CreatedBodies[0]) result = ComponentHelper.MoveBodiesToComponent(selection) result.CreatedComponents[0].SetName("Left_connector") #Simplify 1 body body = GetActivePart().GetAllComponents("Valve")[0].GetBodies()[0] zmax = 0 for face in body.Faces: if face.EvalMid().Point.Z > zmax: zmax = face.EvalMid().Point.Z my_face = face selection = Selection.Create(my_face) + Selection.Create(my_face.AdjacentFaces) result = Fill.Execute(selection) # Remove holes of radius 3mm sel = PowerSelection.Faces.BySurfaceHoleRadius(MM(3), PowerSelectOptions(False, BodySelection.Create(GetRootPart().Bodies[0])), SearchCriteria.SizeComparison.Equal) secondarySelection = Selection.Empty() options = FillOptions() result = Fill.Execute(sel, secondarySelection, options, FillMode.ThreeD) # Translate bigger hole Along X Handle circ_face = PowerSelection.Faces.BySurfaceHoleRadius(MM(35), PowerSelectOptions(False, BodySelection.Create(GetRootPart().Bodies[0])), SearchCriteria.SizeComparison.Equal) direction = Direction.Create(1, 0, 0) options = MoveOptions() result = Move.Translate(circ_face, direction, MM(45), options) # Translate (copy) bigger hole Along X Handle direction = Direction.Create(1, 0, 0) options = MoveOptions() options.CreatePatterns = True options.Copy = True result = Move.Translate(circ_face, direction, MM(-90), options) # Create Fluid Volume part = GetRootPart() body = part.Bodies[0] ymin = 0 ymax = 0 zmax = 0 # access faces with openings (ymin, ymax, zmax) for face in body.Faces: if face.EvalMid().Point.Y < ymin: ymin = face.EvalMid().Point.Y ymin_face = face if face.EvalMid().Point.Y > ymax: ymax = face.EvalMid().Point.Y ymax_face = face if face.EvalMid().Point.Z > zmax: zmax = face.EvalMid().Point.Z zmax_face = face options = VolumeExtractOptions() selection = FaceSelection.Create(ymin_face, ymax_face, zmax_face) #select seed face secondarySelection = circ_face result = VolumeExtract.Create(selection, secondarySelection, options) #----------------------------------EXTERNAL CONNECTONS------------------------- #Reference to Microsoft Excel ClearAll() clr.AddReference("Microsoft.Office.Interop.Excel") import Microsoft.Office.Interop.Excel as Excel import os mypath = os.path.dirname(GetActiveWindow().Document.Path) myExcel = Excel.ApplicationClass() myExcel.Visible = True excel_file_name = "read_excel.xlsx" workbook = myExcel.Workbooks.Open(os.path.join(mypath,excel_file_name)) #or myWorkSheet = workbook.Worksheets("Sheet1") myWorkSheet = workbook.Worksheets[1] #Read data from Excel file i = 1  myX = "" wloc = True points = List[Point2D]() while wloc: myX = myWorkSheet.Rows[i].Value2[0,0] if not isinstance(myX, str): myY = myWorkSheet.Rows[i].Value2[0,1] points.Add(Point2D.Create(MM(myX), MM(myY))) i = i+1 if myX == "End": wloc = False workbook.Close() myExcel.Quit() #create spline curve from imported point data and create a surface body ViewHelper.SetSketchPlane(Plane.PlaneXY) result = SketchNurbs.CreateFrom2DPoints(True, points) ViewHelper.SetViewMode(InteractionMode.Solid) ViewHelper.ZoomToEntity() # convert CAD files and save them in the same directory import glob, os os.chdir(r"E:\Scripts\") for file in glob.glob("*.stp"): File.ResetProject() File.Open(os.path.join(os.getcwd(), file), ImportOptions.Create()) File.SaveAs(os.path.join(os.getcwd(), file[:-4]+".igs")) #run Discovery script in batch mode "C:\Program Files\Ansys Inc\v221\Discovery\Discovery.exe" --run-script \ "E:\Scripts\pipe.scscript" --hidden --exit-after-script # run Discovery script from WB project page import os myScriptGeometry = "E:\Scripts\pipe.scscript" #SetScriptVersion(Version="22.1.217") template1 = GetTemplate(TemplateName="Geometry") system1 = template1.CreateSystem() geometry1 = system1.GetContainer(ComponentName="Geometry") geometry1.Edit(IsDiscoveryGeometry=True) geometry1.RunScript(ScriptFile=myScriptGeometry,GeometryContainer="Geometry",useAsMacro="false") geometry1.Exit()