-
-
December 14, 2022 at 2:53 pm
valentin miguel
SubscriberHello,
In my projet have big error of Type. For example :
TypeError: expected IDesignBody, got DesignBody
TypeError: expected ISelection, got Selection
In a document API_Scripting_Class_Library.chm in C:\Program Files\ANSYS Inc\v222\scdm\SpaceClaim.Api.V22, ISelection is interface, but I don't know use it.
For instance, function "SpaceClaim.Api.V22.Scripting.Helpers.MeasureHelper.BodyExtrema(selection_example).X" need as input a ISelection (selection_example) and have for ouput a float
What is a right code for selection_example is a ISelection ? Or how to change Selection type to ISelection type?
thanks for the help
Miguel Valentin
-
December 19, 2022 at 2:39 pm
Aniket
Ansys EmployeeCan you please give some more information about this error? At which line do you get this? Are you using a recorded script?
-Aniket
-
December 22, 2022 at 6:04 pm
valentin miguel
SubscriberI use recorded script but i modifided it for create a wizard.
My code :
import Systemimport clrimport sysimport osimport mathimport zipimportimport __builtin__import commandsimport random"""'SpaceClaim':, , 'Commands':, 'System':, """clr.AddReference("SpaceClaim.Api.V22")clr.AddReference("SpaceClaim.Api.V22.Scripting")#clr.AddReference("AnsysSCPlugin.22.2")#from SpaceClaim.Api.V22 import Geometry#from SpaceClaim.Api.V22.Scripting import Commands,Helpers,Selection#from AnsysSCPlugin import *from SpaceClaim.Api.V22 import *from SpaceClaim.Api.V22.Scripting import *from System import *part = Nonedef oninit(context):returndef GenerateBF(step):global partwin = Window.ActiveWindowcontext = win.ActiveContextpart = context.ActivePartif part==None:win = Window.ActiveWindowcontext = win.ActiveContextpart = context.ActivePart.Masterbody = part.Bodies#verifier le measurehelper#--------- selection--------------ExtAPI.Log.WriteWarning("TENTATIVE 2")#body = GetRootPart().Bodies[0]#se = Selection.Create(body)#se = Selection.Create(GetRootPart().Bodies[0])#se = PowerSelection.Bodies.AllSolidBodies(PowerSelectOptions(False))#se = Selection.SelectAll()#se = SpaceClaim.Api.V22.Scripting.Selection.ISelection.FilterByVisible#---------------------------------- attempt 1#X = Direction.DirX#Y = Direction.DirY#Z = Direction.DirZ#XMIN = se.GetExtremePoint(-X,Y,Z)#XMAX =se.GetExtremePoint(X,Y,Z)#YMIN = se.GetExtremePoint(-Y,Z,X)#YMAX =se.GetExtremePoint(Y,Z,X)#ZMIN = se.GetExtremePoint(-Z,X,Y)#ZMAX =se.GetExtremePoint(Z,X,Y)#xOverall = abs(XMAX[0]-XMIN[0])#yOverall = abs(YMAX[1]-YMIN[1])#zOverall = abs(ZMAX[2]-ZMIN[2])#----------------------------------- attempt 2#bb = Selection.Create(GetRootPart().Bodies[0])#MAX = bb.BoundingBox.MaxCorner##MIN = bb.BoundingBox.MinCorner#xOverall = abs(MAX[0]-MIN[0])#yOverall = abs(MAX[1]-MIN[1])#zOverall = abs(MAX[2]-MIN[2])#-------------------------------------attempt 3#centre = SpaceClaim.Api.V22.Scripting.Helpers.MeasureHelper.GetCenterOfMass(se)#rX = Direction.DirX#ms = MeasureHelper.BodyExtrema(se).X#bb = SpaceClaim.Api.V22.Scripting.Selection.ISelection.AddToActive(Selection.Create(GetRootPart().Bodies[0]))#rr = SpaceClaim.Api.V22.Scripting.Helpers.MeasureHelper()#cvd=rr.BodyExtrema(bb)selection = SpaceClaim.Api.V22.Scripting.Selection.BodySelection.Create(GetRootPart().Bodies[0])#selection = SpaceClaim.Api.V22.Scripting.Selection.ISelection.SetActive(SpaceClaim.Api.V22.Scripting.Selection.ISelection)#selection = SpaceClaim.Api.V22.Scripting.Selection.xOverall = SpaceClaim.Api.V22.Scripting.Helpers.MeasureHelper.BodyExtrema(selection).X#sele = PartSelection.Create(GetRootPart())#sele = GetRootPart().Bodies[0]part = NoneThere are error on "xOverall=SpaceClaim.Api.V22.Scripting.Helpers.MeasureHelper.BodyExtrema(selection).X"
"selection" is not right, we need an "ISelection" type and we have the "Selection" type. I can't use the "MeasureHelper.BodyExtrema()" function, when I use it in Wizard.
Thank you
-
-
- You must be logged in to reply to this topic.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- How to work with STL file?
- Using Symmetry in DesignModeler and Expanding the Results
- Rotate tool in ANSYS Design Modeler
- drawing a geometry by importing a table of points
- section plane
- material properties
- ANSYS FLUENT – Operation would result in non manifold bodies
- Geometry scaling
- Parameters not imported into Workbench 18.2 from Solidworks/Inventor
- Convert Surface body to solid
-
2524
-
2066
-
1279
-
1096
-
457
© 2023 Copyright ANSYS, Inc. All rights reserved.