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

User: "shubham Dhokare_21832"
Altair Community Member
Updated by shubham Dhokare_21832

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

Find more posts tagged with

Sort by:
1 - 10 of 101
    User: "Brett Ramsey_20633"
    New Altair Community Member
    Updated by unknown

    *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

    User: "Ben Buchanan"
    Altair Employee
    Updated by Ben Buchanan

    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.

    User: "shubham Dhokare_21832"
    Altair Community Member
    OP
    Updated by shubham Dhokare_21832

    *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
    User: "shubham Dhokare_21832"
    Altair Community Member
    OP
    Updated by shubham Dhokare_21832

    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
    User: "Ben Buchanan"
    Altair Employee
    Updated by Ben Buchanan

    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.

    User: "Hypermesh User"
    Altair Community Member
    Accepted Answer
    Updated by Hypermesh User

    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

    User: "shubham Dhokare_21832"
    Altair Community Member
    OP
    Updated by shubham Dhokare_21832

    Thanks for the reply .

    It worked perfectly and saved a lot time

    User: "Hypermesh User"
    Altair Community Member
    Updated by Hypermesh User

    Thanks for the reply .

    It worked perfectly and saved a lot time

    Welcome..

    User: "shubham Dhokare_21832"
    Altair Community Member
    OP
    Updated by shubham Dhokare_21832
    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.
    User: "Hypermesh User"
    Altair Community Member
    Updated by Hypermesh User
    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 />