In TCL How to skip command if it dosen't have any entity to select.

john stan
john stan Altair Community Member
edited August 2022 in Community Q&A

Hello everyone,

I have created a sample script attached below. I want a modification in it. For example if I want to move knuckle solid in knuckle comps, but If I didn't receive the knuckle geometry from my client and I run the script. If this solid is not there to select then this command file stops and execute an error. So I want to skip the particular commands if there is no solid for selection.

*createentity comps includeid=0 name="KNUCKLE"
*createmarkpanel solids 1 "Select Knuckle Geometry";
*movemark solids 1 "KNUCKLE"
*createmark components 3 "KNUCKLE"
*createstringarray 2 "elements_off" "geometry_on"
*hideentitybymark 3 1 2
*clearmark solids 1
*createentity comps includeid=0 name="DISC"

 

so in the createmarkpanel if I didn't have any geometry to select .... and without selecting any geometry if I proceed it should skip the commands till createenity comps includeid=0

So if solution available please guide

Answers

  • Adriano_Koga
    Adriano_Koga
    Altair Employee
    edited August 2022

    you can use TCL programming syntax, such as 'if' statement.

    *createmarkpanel....

    set solids_list [hm_getmark solids 1]

    #check if the solid list is empty

    if {[llength $solids_list == 0]} {

       #do nothing

    } else {

       #do something

    }

     

     

     

    also TCL catch command handles some errors wihout stopping your code.

    https://www.tcl.tk/man/tcl8.4/TclCmd/catch.html

     

  • john stan
    john stan Altair Community Member
    edited August 2022

    Thank you for the reply Adriano,

    I tried the syntax you have given, but now with selecting the solid if I proceed and Without selecting the solid If proceed I am getting error. I use the catch command but the problem is still there.

     

    *createentity comps includeid=0 name="KNUCKLE"
    *createmarkpanel solids 1 "Select Knuckle Geometry";
    set solids_list [ hm_getmark solids 1]
    if {[llength $solids_list == 0]} {
    *clearmark solids 1
    } else {
    *movemark solids 1 "KNUCKLE"
    }
    *createentity comps includeid=0 name="DISC"

     

    If any modification please do suggest.

  • Adriano_Koga
    Adriano_Koga
    Altair Employee
    edited August 2022
    john stan said:

    Thank you for the reply Adriano,

    I tried the syntax you have given, but now with selecting the solid if I proceed and Without selecting the solid If proceed I am getting error. I use the catch command but the problem is still there.

     

    *createentity comps includeid=0 name="KNUCKLE"
    *createmarkpanel solids 1 "Select Knuckle Geometry";
    set solids_list [ hm_getmark solids 1]
    if {[llength $solids_list == 0]} {
    *clearmark solids 1
    } else {
    *movemark solids 1 "KNUCKLE"
    }
    *createentity comps includeid=0 name="DISC"

     

    If any modification please do suggest.

    maybe the problem is that when you perform hm_getmark, the selection is cleared.

    Maybe you'll need to do createmark one more time based on your solids_list.

    eval "*createmark solids 1 $solids_list"

    *movemark solids 1 ...

     

  • john stan
    john stan Altair Community Member
    edited August 2022

    Thank you Adriano.

    Actually I used If with [ ! Null ] command to solve this error. but now I got another problem. 

    I get 50 to 60 solids in a hm. and I need only 16 solids from it. So I want to move remaining solids in a single component. And for that I have a criteria to mask required geometry by using their volume, surface area and COG so that only this solids can display on hm window.

    If you have any Idea regarding this please guide.

     

     

  • Adriano_Koga
    Adriano_Koga
    Altair Employee
    edited August 2022
    john stan said:

    Thank you Adriano.

    Actually I used If with [ ! Null ] command to solve this error. but now I got another problem. 

    I get 50 to 60 solids in a hm. and I need only 16 solids from it. So I want to move remaining solids in a single component. And for that I have a criteria to mask required geometry by using their volume, surface area and COG so that only this solids can display on hm window.

    If you have any Idea regarding this please guide.

     

     

    If you go to the help of HyperWorks reference guide, under 'Tcl Query commands' you will find some useful commands.

     

    image

     

    image

     

    image