3D Design

3D Design

Topics related to Ansys Discovery and Ansys SpaceClaim.

Using SpaceClaim scripts vs recorded blocks for parametric optimization workflow

    • vspenergyofficial
      Subscriber

      Hello,

      I’m Surya Teja and I’m using SpaceClaim (2022 R1) for my parametric hydrodynamic optimization research. The broader goal is to connect SpaceClaim geometry with Python-based sampling and optimization, where:

      • SpaceClaim geometric parameters serve as design variables.

      • AQWA provides hydrodynamic outputs.

      • A custom Sci-ML adaptive learning algorithm (with backpropagation) guides the next parameter set based on an external objective function.

      What I’ve tried so far:

      • Scripting (V21 API):

        • I attempted to draw my geometry idea directly with scripting.

        • As a beginner in SpaceClaim scripting, I wasn’t able to fully complete it.

      • Recorded Script option:

        • I manually created the geometry and recorded the steps into a script.

        • The generated script runs correctly in the original session.

        • However, when I copy/paste the script into a new session (new design, new console, new script file), the run breaks with errors.

        • I’ve tried known tips such as avoiding extra clicks and preferring index-based selections over SmartVariables, but the errors persist.

        • I even tried external help (AI chatbots, documentation), but most fixes turn out redundant or incorrect.

      Where I’m stuck / my questions:

      • Is there a recommended way to make recorded scripts replayable in fresh sessions?

      • Should I instead rely on recorded blocks for robust rebuilds, since they are stored inside the .scdoc file?

      • If blocks are the safer method, how can I:

        • Test them safely by re-running them to check whether they break (if this is obvious, please confirm).

        • Access their parameters in Python for custom sampling under constraints.

      • Is there any best practice for combining SpaceClaim parameters with external optimization loops (Python + AQWA) without the workflow breaking?

      I’m mainly looking for a repeatable and stable approach to:

      1. Define geometry in SpaceClaim.

      2. Expose parameters for optimization.

      3. Safely integrate with Python + AQWA.

      Any guidance, examples, or references would be greatly appreciated.

      Thanks,
      Surya Teja

      Below is my recorded script, please test it and rectify the errors:

      # Python Script, API Version = V21

      # Set Sketch Plane
      sectionPlane = Plane.PlaneXY
      result = ViewHelper.SetSketchPlane(sectionPlane, Info1)
      # EndBlock
      # Set New Sketch
      result = SketchHelper.StartConstraintSketching()
      # EndBlock
      # Sketch Circle
      origin = Point2D.Create(M(0), M(0))
      result = SketchCircle.Create(origin, M(1.75))
      baseSel = SelectionPoint.Create(CurvePoint1)
      targetSel = SelectionPoint.Create(DatumLine1)
      result = Constraint.CreateCoincident(baseSel, targetSel)
      baseSel = SelectionPoint.Create(CurvePoint1)
      targetSel = SelectionPoint.Create(DatumPoint1)
      result = Constraint.CreateCoincident(baseSel, targetSel)
      # EndBlock
      # Solidify Sketch
      mode = InteractionMode.Solid
      result = ViewHelper.SetViewMode(mode, Info2)
      # EndBlock
      # Translate Along X Handle
      selection = Body1
      direction = Direction.DirX
      options = MoveOptions()
      result = Move.Translate(selection, direction, M(-8), options, Info3)
      # EndBlock
      # Extrude 1 Face
      selection = Face1
      options = ExtrudeFaceOptions()
      options.ExtrudeType = ExtrudeType.Add
      result = ExtrudeFaces.Execute(selection, M(4), options, Info4)
      # EndBlock
      # Extrude 1 Face
      selection = Face2
      options = ExtrudeFaceOptions()
      options.ExtrudeType = ExtrudeType.Add
      result = ExtrudeFaces.Execute(selection, M(4), options, Info5)
      # EndBlock
      # Set Sketch Plane
      selection = Face2
      result = ViewHelper.SetSketchPlane(selection, Info6)
      # EndBlock
      # Set New Sketch
      result = SketchHelper.StartConstraintSketching()
      # EndBlock
      # Sketch Circle
      origin = Point2D.Create(M(0), M(0))
      result = SketchCircle.Create(origin, M(1))
      baseSel = Curve1
      targetSel = Curve2
      result = Constraint.CreateConcentric(baseSel, targetSel)
      # EndBlock
      # Set Sketch Plane
      sectionPlane = Plane.Create(Frame.Create(Point.Create(M(-8), M(0), M(-4)),
      -Direction.DirX,
      -Direction.DirZ))
      result = ViewHelper.SetSketchPlane(sectionPlane, Info7)
      # EndBlock
      # Set New Sketch
      result = SketchHelper.StartConstraintSketching()
      # EndBlock
      # Sketch Line
      start = Point2D.Create(M(0), M(0))
      end = Point2D.Create(M(0), M(6))
      result = SketchLine.Create(start, end)
      baseSel = SelectionPoint.Create(CurvePoint2)
      targetSel = SelectionPoint.Create(DatumLine2)
      result = Constraint.CreateCoincident(baseSel, targetSel)
      baseSel = SelectionPoint.Create(CurvePoint3)
      targetSel = SelectionPoint.Create(DatumLine2)
      result = Constraint.CreateCoincident(baseSel, targetSel)
      curveSelList = Curve3
      result = Constraint.CreateVertical(curveSelList)
      baseSel = CurvePoint2
      targetSel = Curve4
      result = Constraint.CreateMidpoint(baseSel, targetSel)
      baseSel = SelectionPoint.Create(Curve3)
      targetSel = SelectionPoint.Create(Curve4)
      result = Constraint.CreatePerpendicular(baseSel, targetSel)
      baseSel = SelectionPoint.Create(Curve3)
      targetSel = SelectionPoint.Create(Curve5)
      result = Constraint.CreateParallel(baseSel, targetSel)
      # EndBlock
      # Sketch Line
      start = Point2D.Create(M(0), M(6))
      end = Point2D.Create(M(-8), M(6))
      result = SketchLine.Create(start, end)
      baseSel = SelectionPoint.Create(CurvePoint4)
      targetSel = SelectionPoint.Create(CurvePoint3)
      result = Constraint.CreateCoincident(baseSel, targetSel)
      baseSel = SelectionPoint.Create(Curve6)
      targetSel = SelectionPoint.Create(Curve3)
      result = Constraint.CreatePerpendicular(baseSel, targetSel)
      baseSel = SelectionPoint.Create(CurvePoint4)
      targetSel = SelectionPoint.Create(DatumLine2)
      result = Constraint.CreateCoincident(baseSel, targetSel)
      baseSel = SelectionPoint.Create(Curve6)
      targetSel = SelectionPoint.Create(DatumLine2)
      result = Constraint.CreatePerpendicular(baseSel, targetSel)
      baseSel = SelectionPoint.Create(Curve6)
      targetSel = SelectionPoint.Create(Curve4)
      result = Constraint.CreateParallel(baseSel, targetSel)
      # EndBlock
      # Solidify Sketch
      mode = InteractionMode.Solid
      result = ViewHelper.SetViewMode(mode, Info8)
      # EndBlock
      # Detach Faces
      selBodies = Body2
      result = DetachFaces.Execute(selBodies)
      # EndBlock
      #  System failure: cannot generate record script selection
      #Error = {0}Nullable object must have a value.
      # EndBlock
      # Sweep 1 Face
      selection = Face3
      trajectories = Selection.Create(Curve3, Curve6)
      options = SweepCommandOptions()
      options.ExtrudeType = ExtrudeType.Add
      options.Select = True
      result = Sweep.Execute(selection, trajectories, options, Info9)
      # EndBlock
      # Detach Faces
      selBodies = Body3
      result = DetachFaces.Execute(selBodies)
      # EndBlock
      # Delete Objects
      selection = CurveFolder1
      result = Delete.Execute(selection)
      # EndBlock
      # Delete Selection
      selection = Face4
      result = Delete.Execute(selection)
      # EndBlock
      # Translate Along Z Handle
      selection = Body3
      direction = Direction.DirZ
      options = MoveOptions()
      result = Move.Translate(selection, direction, M(9), options, Info10)
      # EndBlock
      # Delete Selection
      selection = Face5
      result = Delete.Execute(selection)
      # EndBlock
      # Extrude 1 Face
      selection = Face6
      options = ExtrudeFaceOptions()
      options.ExtrudeType = ExtrudeType.Cut
      result = ExtrudeFaces.Execute(selection, M(-1), options, Info11)
      # EndBlock
      # Detach Faces
      selBodies = Body4
      result = DetachFaces.Execute(selBodies)
      # EndBlock
      # Delete Objects
      selection = Body5
      result = Delete.Execute(selection)
      # EndBlock
      # Create Blend
      selection = EdgeSelection.Create(Edge1, Edge2)
      options = LoftOptions()
      options.GeometryCommandOptions = GeometryCommandOptions()
      result = Loft.Create(selection, None, options, Info12)
      # EndBlock
      # Detach Faces
      selBodies = Body6
      result = DetachFaces.Execute(selBodies)
      # EndBlock
      # Rename 'Surface' to 'Left_Buoy_Bottom_Face'
      selection = Body2
      result = RenameObject.Execute(selection,"Left_Buoy_Bottom_Face")
      # EndBlock
      # Rename 'Surface' to 'Left_Buoy_Annulus'
      selection = Body6
      result = RenameObject.Execute(selection,"Left_Buoy_Annulus")
      # EndBlock
      # Rename 'Surface' to 'Left_Lower_Tube_Annulus'
      selection = Body7
      result = RenameObject.Execute(selection,"Left_Lower_Tube_Annulus")
      # EndBlock
      # Rename 'Surface' to 'Horizontal Tube_Annulus'
      selection = Body8
      result = RenameObject.Execute(selection,"Horizontal Tube_Annulus")
      # EndBlock
      # Rename 'Surface' to 'Left_Upper_Tube_Top_Face'
      selection = Body4
      result = RenameObject.Execute(selection,"Left_Upper_Tube_Top_Face")
      # EndBlock
      # Rename 'Surface' to 'Left_Upper_Tube_Annulus'
      selection = Body9
      result = RenameObject.Execute(selection,"Left_Upper_Tube_Annulus")
      # EndBlock
      # Rename 'Surface' to 'Left_Buoy_Top_Face'
      selection = Body10
      result = RenameObject.Execute(selection,"Left_Buoy_Top_Face")
      # EndBlock
      # Create Datum Plane
      selection = Edge3
      result = DatumPlaneCreator.Create(selection, False, Info13)
      # EndBlock
      # Mirror
      selection = Body2
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info14)
      # EndBlock
      # Mirror
      selection = Body6
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info15)
      # EndBlock
      # Mirror
      selection = Body7
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info16)
      # EndBlock
      # Mirror
      selection = Body8
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info17)
      # EndBlock
      # Mirror
      selection = Body4
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info18)
      # EndBlock
      # Mirror
      selection = Body9
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info19)
      # EndBlock
      # Mirror
      selection = Body10
      mirrorPlane = DatumPlane1
      options = MirrorOptions()
      result = Mirror.Execute(selection, mirrorPlane, options, Info20)
      # EndBlock
      # Delete Objects
      selection = DatumPlane1
      result = Delete.Execute(selection)
      # EndBlock
      # Rename 'Left_Buoy_Bottom_Face' to 'Right_Buoy_Bottom_Face'
      selection = Body11
      result = RenameObject.Execute(selection,"Right_Buoy_Bottom_Face")
      # EndBlock
      # Rename 'Left_Buoy_Annulus' to 'Right_Buoy_Annulus'
      selection = Body12
      result = RenameObject.Execute(selection,"Right_Buoy_Annulus")
      # EndBlock
      # Rename 'Left_Lower_Tube_Annulus' to 'Right_Lower_Tube_Annulus'
      selection = Body13
      result = RenameObject.Execute(selection,"Right_Lower_Tube_Annulus")
      # EndBlock
      # Rename 'Left_Upper_Tube_Top_Face' to 'Right_Upper_Tube_Top_Face'
      selection = Body14
      result = RenameObject.Execute(selection,"Right_Upper_Tube_Top_Face")
      # EndBlock
      # Rename 'Left_Upper_Tube_Annulus' to 'Right_Upper_Tube_Annulus'
      selection = Body15
      result = RenameObject.Execute(selection,"Right_Upper_Tube_Annulus")
      # EndBlock
      # Rename 'Left_Buoy_Top_Face' to 'Right_Buoy_Top_Face'
      selection = Body16
      result = RenameObject.Execute(selection,"Right_Buoy_Top_Face")
      # EndBlock
      # Save File
      DocumentSave.Execute(r"C:\Users\kapar\Desktop\Research\U-tube_final.scdoc", FileSettings1)
      # EndBlock

Viewing 0 reply threads
  • You must be logged in to reply to this topic.