3D Design

3D Design

Type ERROR in Script on SpaceClaim Wizard

    • valentin miguel
      Subscriber

      Hello,

      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

    • Aniket
      Ansys Employee

      Can you please give some more information about this error? At which line do you get this? Are you using a recorded script?

      -Aniket

      How to access Ansys help links

      Guidelines for Posting on Ansys Learning Forum

      • valentin miguel
        Subscriber

        I use recorded script but i modifided it for create a wizard.

        My code :

        import System
        import clr
        import sys
        import os
        import math
        import zipimport
        import __builtin__
        import commands
        import 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 = None
         
        def oninit(context):
            return
         
        def GenerateBF(step):
            global part
            win = Window.ActiveWindow
            context = win.ActiveContext
            part = context.ActivePart
         
            if part==None:
                win = Window.ActiveWindow
                context = win.ActiveContext
                part = context.ActivePart.Master
            body = 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 = None

         

        There 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

         

         

Viewing 1 reply thread
  • You must be logged in to reply to this topic.