Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi
I'm trying to make an asynchronous app that help automate some processes.
is it possible to iterate through all parts/sub assemblies in an assembly and add all components with a specific file name (test.prt for example) and add them to the selection buffer?
I want the user to have the option to right click and hide/exclude/delete the selected components.
any example of how to add components to selection buffer will be appreciated.
thanks
Hey,
You have to go through the following procedure to achieve what you need.
1. Visit all the features of Assembly thru ProSolidFeatureVisit.
2. Get ProSelection reference to all the features in it.
3. These ProSelection objects can be added to a ProSelbuffer object.
But I'm afraid that you might not need to add all the components in the Selection Buffer. Because once you add a component in the buffer those components will be actively selected in the graphics window and it affects the User Experience.
Asyn Session, proc developed without Creo restart.
# final call with model name pattern c*
# c* will add parts and assemblies, for sure this works as well without wildcards 😁
# see image for some Debug output
::TEST::Add_To_Buffer c*
namespace eval ::TEST {
#::TEST::Add_To_Buffer fly*
proc Add_To_Buffer {match} {
# configure selction Object
ps_sel selBuff -modelitem SelMiBuf -comppath SelCPBuf
# Get current Assembly
set MODEL [ps_model cur]
# Comppath Model/owner is always this assy
SelCPBuf config -model $MODEL
# Get component Datta NAME1 PATH1 NAME2 PATH2 NAMEX PATHX
set compData [ps_visit compo -model $MODEL]
# clear current buffer
selBuff buffclear
#walk through
foreach {model path} $compData {
#Debug_Var model path
if { ![string match -nocase $match $model] } {
Debug "Not matching '$model'"
continue
}
Debug "match '$model' path $path"
# configure the path
SelCPBuf config -path $path
# Get the modelname from this path this is index end
set SelMdl [SelCPBuf model end]
# get the model type equal to modelitem type
ps_model to_modelitem -model $SelMdl -- SelMiBuf
Debug "cp exist [SelCPBuf exist] "
Debug "mi exist [SelMiBuf exist] "
Debug "sel exist [selBuff exist] "
# now add to the buffer
selBuff buffadd
}
}
}
# plain code without comments and type check
proc Add_To_BufferPlain {match} {
ps_sel selBuff -modelitem SelMiBuf -comppath SelCPBuf
set MODEL [ps_model cur]
SelCPBuf config -model $MODEL
set compData [ps_visit compo -model $MODEL]
selBuff buffclear
foreach {model path} $compData {
if { ![string match -nocase $match $model] } {
continue
}
SelCPBuf config -path $path
set SelMdl [SelCPBuf model end]
ps_model to_modelitem -model $SelMdl -- SelMiBuf
selBuff buffadd
}
}
Did some changes, ToModelItem may better.
Hello @EA_8293306,
It looks like you have some responses from some community members. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution.
Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.
Thanks,
Vivek N.
Community Moderation Team.