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

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
Best 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"
1
Answers
-
*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
0 -
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
EXPORT QUERY DATA FOR DISPLAYED NODES
hwc mark component "displayed"hwi OpenStack
hwi GetActiveClientHandle currClient
currClient GetModelHandle currModel [currClient GetActiveModel]currModel GetQueryCtrlHandle currQuery
currQuery SetQuery $QUERY_STRINGset selId [currModel AddSelectionSet Part]
currModel GetSelectionSetHandle temp_sel $selId
temp_sel Cleartemp_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
1 -
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
0 -
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
0 -
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"
1 -
This comment is made by mistake, /Kindly ignore this comment0 -
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.
0