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

shubham Dhokare_21832
shubham Dhokare_21832 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

Thanks & Regards,

Shubham Dhokare

Tagged:

Best Answer

  • Hypermesh User
    Hypermesh User Altair Community Member
    edited August 2022 Answer ✓

    Hi Shubham,

      hope this will help you..

     

    #create the list of part name to be created.

    #APpend your 16 solid name in the list.

    #create the list of part name to be created.


    set Listpartname { KNUCKLE DISC }

    foreach {partname} $Listpartname {

     

    *createmarkpanel solids 1 "Select $partname Geometry";

    if {[llength [hm_getmark solids 1]] > 0} {

    *createentity comps includeid=0 name="$partname"
    *movemark solids 1 "$partname"
    *createmark components 3 "$partname"
    *createstringarray 2 "elements_off" "geometry_on"
    *hideentitybymark 3 1 2
    *clearmark solids 1
    }

    }

     

     

    Regards,

     

    Manoj

Answers

  • Brett Ramsey_20633
    Brett Ramsey_20633 New Altair Community Member
    edited August 2022

    *createentity comps includeid=0 name="KNUCKLE"
    *createmarkpanel solids 1 "Select Knuckle Geometry";

    if {llegnth [hm_getmark solid 1] == 0}{

    continue

    } elseif {llegnth [hm_getmark solid 1] != 0}{ 
    *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"

     

    This should do the trick. Hope it helps

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited August 2022

    There are probably a few different ways to do this.  The most straight forward to me is to just do an if statement to check the length of the list like this

    if {[llength [hm_getmark solids 1]] > 0} {

    <your other commands>

    }

    Hope that helps.

  • shubham Dhokare_21832
    shubham Dhokare_21832 Altair Community Member
    edited August 2022

    *createentity comps includeid=0 name="KNUCKLE"
    *createmarkpanel solids 1 "Select Knuckle Geometry";

    if {llegnth [hm_getmark solid 1] == 0}{

    continue

    } elseif {llegnth [hm_getmark solid 1] != 0}{ 
    *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"

     

    This should do the trick. Hope it helps

    Thanks for reply Brett, Your syntax work fine for me .... But I want to make some modification in it. Like I have 16 solid and for each solid I have to write this code ... Is it possible to use loop function Or can you suggest any other idea to reduce this syntax length
  • shubham Dhokare_21832
    shubham Dhokare_21832 Altair Community Member
    edited August 2022

    There are probably a few different ways to do this.  The most straight forward to me is to just do an if statement to check the length of the list like this

    if {[llength [hm_getmark solids 1]] > 0} {

    <your other commands>

    }

    Hope that helps.

    Thank you Ben , your syntax work for me. I have 16 solid and Now I just want to decrease the syntax length ... So if you have any suggestions please do reply Thanks again
  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited August 2022

    Thank you Ben , your syntax work for me. I have 16 solid and Now I just want to decrease the syntax length ... So if you have any suggestions please do reply Thanks again

    Actually if that is the case you can probably just use a foreach loop instead of the if statement.

    foreach solidID [hm_getmark solid 1] {

    *movemark solids 1 "KNUCKLE"
    *createmark components 3 "KNUCKLE"
    *createstringarray 2 "elements_off" "geometry_on"
    *hideentitybymark 3 1 2
    *clearmark solids 1

    }

    So if the list is empty it won't do any of the commands which addresses your first question but if the list is longer it will do it for each one.

  • Hypermesh User
    Hypermesh User Altair Community Member
    edited August 2022 Answer ✓

    Hi Shubham,

      hope this will help you..

     

    #create the list of part name to be created.

    #APpend your 16 solid name in the list.

    #create the list of part name to be created.


    set Listpartname { KNUCKLE DISC }

    foreach {partname} $Listpartname {

     

    *createmarkpanel solids 1 "Select $partname Geometry";

    if {[llength [hm_getmark solids 1]] > 0} {

    *createentity comps includeid=0 name="$partname"
    *movemark solids 1 "$partname"
    *createmark components 3 "$partname"
    *createstringarray 2 "elements_off" "geometry_on"
    *hideentitybymark 3 1 2
    *clearmark solids 1
    }

    }

     

     

    Regards,

     

    Manoj

  • shubham Dhokare_21832
    shubham Dhokare_21832 Altair Community Member
    edited August 2022

    Thanks for the reply .

    It worked perfectly and saved a lot time

  • Hypermesh User
    Hypermesh User Altair Community Member
    edited August 2022

    Thanks for the reply .

    It worked perfectly and saved a lot time

    Welcome..

  • shubham Dhokare_21832
    shubham Dhokare_21832 Altair Community Member
    edited August 2022
    How to calculate volume and area for SOLID using tcl ? I tried hm_getmass but it supports only for elements and comps. And in comps it only supports to elements.
  • Hypermesh User
    Hypermesh User Altair Community Member
    edited August 2022
    Hope this helps you..<br /><img src="https://us.v-cdn.net/6038102/uploads/attachments/7a037eb7db459914cfd5f6a4e29619d9/Community-Pasted-Attachment-1659965549105.png" /><br /><img src="https://us.v-cdn.net/6038102/uploads/attachments/7a037eb7db459914cfd5f6a4e29619d9/Community-Pasted-Attachment-1659965746315.png" /><br /><br /><br />