How to count the Number of Displayed components in hyperview (TCL Script)

Anuj Nandal_21993
Anuj Nandal_21993 Altair Community Member
edited February 19 in Community Q&A

Hi,

I am trying to automate postprocessing through tcl scripting. Can someone help me with the code that would help me count the displayed components in Hyperview (Output should be the number of components displayed). Is there a function that directly does this, would really appreciate any help here.

PS I use 2024.1 Version

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

  • Adriano_Koga
    Adriano_Koga
    Altair Employee
    Answer ✓

    the number of components is written at the TCL console, by the following commands.
    using TCL you could get these written some other ways, but you would need to tweek a little.

    These commands below write the number of displayed comps into a variable named 'numSEL'.

    set numSEL [currQuery GetSelectionSetSize]

    puts "number of displayed comps is: $numSEL"

    image.png

Answers

  • jloenartz
    jloenartz Altair Community Member

    *createmark comps 1 "displayed"
    puts [llength [hm_getmark comps 1]]

    the first command filters out all displayed commands, the second counts them and outputs them to the console

  • Adriano_Koga
    Adriano_Koga
    Altair Employee

    not really fancy, but you could use this:

    set QUERY_STRING "component.id component.name" ; #sets the query syntax to be used when exporting results in CSV

    hwc mark clear
    hwc mark component "displayed"

    EXPORT QUERY DATA FOR DISPLAYED NODES

    hwi OpenStack
    hwi GetActiveClientHandle currClient
    currClient GetModelHandle currModel [currClient GetActiveModel]

    currModel GetQueryCtrlHandle currQuery
    currQuery SetQuery $QUERY_STRING

    set selId [currModel AddSelectionSet Part]
    currModel GetSelectionSetHandle temp_sel $selId
    temp_sel Clear

    temp_sel Add displayed

    currQuery SetSelectionSet $selId
    set numSEL [currQuery GetSelectionSetSize]
    puts "number of displayed comps is: $numSEL"

    currQuery GetIteratorHandle qciter

    #queries COMP data
    for {qciter First} {[qciter Valid]} {qciter Next} {
    puts "COMP ID: [lindex [qciter GetDataList] 0] | COMP NAME: [lindex [qciter GetDataList] 1]"
    }
    qciter ReleaseHandle

    #currQuery WriteData [file join $outputDir "results.csv"]

    temp_sel ReleaseHandle

    currQuery ReleaseHandle

    hwi CloseStack

  • Anuj Nandal_21993
    Anuj Nandal_21993 Altair Community Member
    edited February 20

    Hi jloenartz, this code has thrown an error, I am still new to tcl scripting, if I miss some basics that needs to be done before typing this code I have not done that. I simply copy pasted the code here

    image.png
  • Anuj Nandal_21993
    Anuj Nandal_21993 Altair Community Member

    Hi Adriano,

    Thanks for the quick reply. Your code works great, however since I am new to scripting and coding in general, it'll take me some understanding this code. Is there a function, code that would give me output as a number (just the count of displayed components). I have tried hm_count, that isn't working. Really appreciate the help here

  • Adriano_Koga
    Adriano_Koga
    Altair Employee
    Answer ✓

    the number of components is written at the TCL console, by the following commands.
    using TCL you could get these written some other ways, but you would need to tweek a little.

    These commands below write the number of displayed comps into a variable named 'numSEL'.

    set numSEL [currQuery GetSelectionSetSize]

    puts "number of displayed comps is: $numSEL"

    image.png
  • Anuj Nandal_21993
    Anuj Nandal_21993 Altair Community Member
    edited February 22

    This comment is made by mistake, /Kindly ignore this comment

  • Anuj Nandal_21993
    Anuj Nandal_21993 Altair Community Member

    Thank you for the response, I have incorporated the code and it works as intended perfectly.

    On similar grounds is there any code to get the number of notes displayed. Ex: If there are 3 Nots on the screen the output is 3.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.