TAGGED: cad, ironpython, python-scripting, spaceclaim
-
-
September 17, 2025 at 1:39 am
vspenergyofficial
SubscriberHello,
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:
Define geometry in SpaceClaim.
Expose parameters for optimization.
Safely integrate with Python + AQWA.
Any guidance, examples, or references would be greatly appreciated.
Thanks,
Surya TejaBelow is my recorded script, please test it and rectify the errors:
# Python Script, API Version = V21# Set Sketch PlanesectionPlane = Plane.PlaneXYresult = ViewHelper.SetSketchPlane(sectionPlane, Info1)# EndBlock# Set New Sketchresult = SketchHelper.StartConstraintSketching()# EndBlock# Sketch Circleorigin = 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 Sketchmode = InteractionMode.Solidresult = ViewHelper.SetViewMode(mode, Info2)# EndBlock# Translate Along X Handleselection = Body1direction = Direction.DirXoptions = MoveOptions()result = Move.Translate(selection, direction, M(-8), options, Info3)# EndBlock# Extrude 1 Faceselection = Face1options = ExtrudeFaceOptions()options.ExtrudeType = ExtrudeType.Addresult = ExtrudeFaces.Execute(selection, M(4), options, Info4)# EndBlock# Extrude 1 Faceselection = Face2options = ExtrudeFaceOptions()options.ExtrudeType = ExtrudeType.Addresult = ExtrudeFaces.Execute(selection, M(4), options, Info5)# EndBlock# Set Sketch Planeselection = Face2result = ViewHelper.SetSketchPlane(selection, Info6)# EndBlock# Set New Sketchresult = SketchHelper.StartConstraintSketching()# EndBlock# Sketch Circleorigin = Point2D.Create(M(0), M(0))result = SketchCircle.Create(origin, M(1))baseSel = Curve1targetSel = Curve2result = Constraint.CreateConcentric(baseSel, targetSel)# EndBlock# Set Sketch PlanesectionPlane = Plane.Create(Frame.Create(Point.Create(M(-8), M(0), M(-4)),-Direction.DirX,-Direction.DirZ))result = ViewHelper.SetSketchPlane(sectionPlane, Info7)# EndBlock# Set New Sketchresult = SketchHelper.StartConstraintSketching()# EndBlock# Sketch Linestart = 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 = Curve3result = Constraint.CreateVertical(curveSelList)baseSel = CurvePoint2targetSel = Curve4result = 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 Linestart = 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 Sketchmode = InteractionMode.Solidresult = ViewHelper.SetViewMode(mode, Info8)# EndBlock# Detach FacesselBodies = Body2result = DetachFaces.Execute(selBodies)# EndBlock#Â System failure: cannot generate record script selection#Error = {0}Nullable object must have a value.# EndBlock# Sweep 1 Faceselection = Face3trajectories = Selection.Create(Curve3, Curve6)options = SweepCommandOptions()options.ExtrudeType = ExtrudeType.Addoptions.Select = Trueresult = Sweep.Execute(selection, trajectories, options, Info9)# EndBlock# Detach FacesselBodies = Body3result = DetachFaces.Execute(selBodies)# EndBlock# Delete Objectsselection = CurveFolder1result = Delete.Execute(selection)# EndBlock# Delete Selectionselection = Face4result = Delete.Execute(selection)# EndBlock# Translate Along Z Handleselection = Body3direction = Direction.DirZoptions = MoveOptions()result = Move.Translate(selection, direction, M(9), options, Info10)# EndBlock# Delete Selectionselection = Face5result = Delete.Execute(selection)# EndBlock# Extrude 1 Faceselection = Face6options = ExtrudeFaceOptions()options.ExtrudeType = ExtrudeType.Cutresult = ExtrudeFaces.Execute(selection, M(-1), options, Info11)# EndBlock# Detach FacesselBodies = Body4result = DetachFaces.Execute(selBodies)# EndBlock# Delete Objectsselection = Body5result = Delete.Execute(selection)# EndBlock# Create Blendselection = EdgeSelection.Create(Edge1, Edge2)options = LoftOptions()options.GeometryCommandOptions = GeometryCommandOptions()result = Loft.Create(selection, None, options, Info12)# EndBlock# Detach FacesselBodies = Body6result = DetachFaces.Execute(selBodies)# EndBlock# Rename 'Surface' to 'Left_Buoy_Bottom_Face'selection = Body2result = RenameObject.Execute(selection,"Left_Buoy_Bottom_Face")# EndBlock# Rename 'Surface' to 'Left_Buoy_Annulus'selection = Body6result = RenameObject.Execute(selection,"Left_Buoy_Annulus")# EndBlock# Rename 'Surface' to 'Left_Lower_Tube_Annulus'selection = Body7result = RenameObject.Execute(selection,"Left_Lower_Tube_Annulus")# EndBlock# Rename 'Surface' to 'Horizontal Tube_Annulus'selection = Body8result = RenameObject.Execute(selection,"Horizontal Tube_Annulus")# EndBlock# Rename 'Surface' to 'Left_Upper_Tube_Top_Face'selection = Body4result = RenameObject.Execute(selection,"Left_Upper_Tube_Top_Face")# EndBlock# Rename 'Surface' to 'Left_Upper_Tube_Annulus'selection = Body9result = RenameObject.Execute(selection,"Left_Upper_Tube_Annulus")# EndBlock# Rename 'Surface' to 'Left_Buoy_Top_Face'selection = Body10result = RenameObject.Execute(selection,"Left_Buoy_Top_Face")# EndBlock# Create Datum Planeselection = Edge3result = DatumPlaneCreator.Create(selection, False, Info13)# EndBlock# Mirrorselection = Body2mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info14)# EndBlock# Mirrorselection = Body6mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info15)# EndBlock# Mirrorselection = Body7mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info16)# EndBlock# Mirrorselection = Body8mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info17)# EndBlock# Mirrorselection = Body4mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info18)# EndBlock# Mirrorselection = Body9mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info19)# EndBlock# Mirrorselection = Body10mirrorPlane = DatumPlane1options = MirrorOptions()result = Mirror.Execute(selection, mirrorPlane, options, Info20)# EndBlock# Delete Objectsselection = DatumPlane1result = Delete.Execute(selection)# EndBlock# Rename 'Left_Buoy_Bottom_Face' to 'Right_Buoy_Bottom_Face'selection = Body11result = RenameObject.Execute(selection,"Right_Buoy_Bottom_Face")# EndBlock# Rename 'Left_Buoy_Annulus' to 'Right_Buoy_Annulus'selection = Body12result = RenameObject.Execute(selection,"Right_Buoy_Annulus")# EndBlock# Rename 'Left_Lower_Tube_Annulus' to 'Right_Lower_Tube_Annulus'selection = Body13result = RenameObject.Execute(selection,"Right_Lower_Tube_Annulus")# EndBlock# Rename 'Left_Upper_Tube_Top_Face' to 'Right_Upper_Tube_Top_Face'selection = Body14result = RenameObject.Execute(selection,"Right_Upper_Tube_Top_Face")# EndBlock# Rename 'Left_Upper_Tube_Annulus' to 'Right_Upper_Tube_Annulus'selection = Body15result = RenameObject.Execute(selection,"Right_Upper_Tube_Annulus")# EndBlock# Rename 'Left_Buoy_Top_Face' to 'Right_Buoy_Top_Face'selection = Body16result = RenameObject.Execute(selection,"Right_Buoy_Top_Face")# EndBlock# Save FileDocumentSave.Execute(r"C:\Users\kapar\Desktop\Research\U-tube_final.scdoc", FileSettings1)# EndBlock
-
- You must be logged in to reply to this topic.
- FSAE CFD – Lesson 1 Preparation question (Using Discovery)
- Project lines/edges into a face with the direction normal to the face
- Script for subtracting models
- Multiple Instances of SpaceClaim taking multiple licenses
- No preview in explorer with scdox file
- Spaceclaim file reference error
- Issues after installing new service pack 2024R1 (sp5)
- Add-in Error Excel
- Problems with loading my Discovery Mesh into Fluent
- Missing SubDivWrapper.dll
-
3872
-
1414
-
1241
-
1118
-
1015
© 2025 Copyright ANSYS, Inc. All rights reserved.