#--------------------------------------------------
# Version: 1.2
# Author: Rajasekaran Natarajan, Kawasaki, Japan.
# www.oocities.org/rajsekarann/
#rajasekaran.natarajan <at> gmail.com
#--------------------------------------------------



#created by Rajasekaran Natarajan
#Creates Midsurfaces for each selected component and places the generated mid-surfaces
    # in a new compoent, the new compoent is named as the Original component name with the prefix of MS
#If required this program can be modified to create the mid-surfaces in the original component
    #by modifying line 23 and 32

proc myMidSurf {mycomp} {

    foreach i $mycomp {
       
        set tcomp [hm_getcollectorname comp $i]
        #tk_messageBox -message "i :$i and name = $tcomp"

        *collectorcreate components "MS_$tcomp" "junk_material" 9
        # Create a component ending in the CompNumber + ms for midsurface
   
        set CompNameMS [hm_getentityvalue components -1 name 1];
   
        *createmark components 1 $tcomp
   
        *createmark surfaces 1 "by comps" $tcomp
   
        *midsurfaceextract surfaces 1 -1 0 0 0 undefined 0 0 0
        *midsurface_remove_edit_bodies
        *createmark surfaces 1 "by comps" $CompNameMS
   
        set SurfsListMS [hm_getmark surfaces 1]
   
        if { ([llength $SurfsListMS] == 0) } {
       
            *createmark surfaces 1 "by comps" $tcomp
            *midsurfaceextract surfaces 1 2 0 0 0 undefined 0 0 0
            *midsurface_remove_edit_bodies

    }
}
   
}

# Clear the component & surface marks to start fresh
*clearmark components 1
*clearmark components 2
*clearmark surfaces 1
*clearmark surfaces 2



eval *createmarkpanel components 1 "Select the components for Mid Surface"

set CompsList [hm_getmark components 1]

if { ([llength $CompsList] == 0) } {

        hm_errormessage "No components were selected: terminating."
       
        } else {
       
            myMidSurf $CompsList
        }