Calculate the total area of a list of components with fixed name

FaForno
FaForno Altair Community Member
edited September 2022 in Community Q&A

Dear All,

I have a list of components with one surface each.

I need to calculate the total area of these surfaces.

Do you have any idea on how I could fix this task in tcl/tk code?

 

Thanks a lot in advance,

Fabio

Answers

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited September 2022

    Seems like there must me a command to do this for multiple surfaces but all I found was one that does it for one surface so you would have to use expr to add them mainly after getting the area for each surface.

    Help page for hm_getareaofsurface

    https://2022.help.altair.com/2022.1/hwdesktop/hwd/topics/reference/hm/hm_getareaofsurface.htm?zoom_highlight=get+surface+area

    So something like this should work for you:

    set totalArea 0.0

    foreach surfID $surfList {

        set totalArea [expr {$totalArea + [hm_getareaofsurface surfs $surfID]}]

    }

  • Nagahashi Kouta
    Nagahashi Kouta Altair Community Member
    edited September 2022

    *createmarkpanel comps 1 "Please select components"
    set comp_id_list [hm_getmark comps 1]
    set total_surf_area 0
    foreach comp_id $comp_id_list {
        *createmark surfs 1 "by comp id" $comp_id
        set surf_id_list [hm_getmark surfs 1]
        foreach surf_id $surf_id_list {
            set surf_area [hm_getareaofsurface surfs $surf_id]
            set total_surf_area [expr {$total_surf_area+$surf_area}]
        }
    }
    tk_messageBox -message "The total area is ${total_surf_area}"

  • FaForno
    FaForno Altair Community Member
    edited September 2022

    I used this code and it works perfectly!

     

    Thanks a lot All for your help!

     

    Regards,

    Fabio