In TCL How to skip command if it dosen't have any entity to select.
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
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*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
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 againThere 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
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.
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
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 />
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
*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