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
Find more posts tagged with
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"
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
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
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"
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"
*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