Hi,
I would like to write a macro in which given an arbitrary multiblock dataset, apply Extract Blocks to every leaf block in that dataset.
Hi @boonth, here is a function that returns all selectors of leaf nodes in a multiblock dataset or a partitioned dataset collection:
def get_selectors(source):
dataInfo = source.GetDataInformation()
dataAssembly = dataInfo.GetDataAssembly()
if dataAssembly == None:
dataAssembly = dataInfo.GetHierarchy()
childNodeIds = [x for x in dataAssembly.GetChildNodes(0) if dataAssembly.GetNumberOfChildren(x) == 0]
blockSelectors = [dataAssembly.GetNodePath(x) for x in childNodeIds]
return blockSelectors
You can then iterate over the list of selectors returned to create an Extract Blocks filter for each selector with something like:
blockSelectors = get_selectors(source)
for selector in blockSelectors:
extract = ExtractBlock(Input=source)
if source.GetDataInformation().GetDataAssembly():
extract.Assembly = 'Assembly'
else:
extract.Assembly = 'Hierarchy'
extract.Selectors = [selector]
Note the lines like source.GetDataInformation().GetDataAssembly()
distinguish between dataset types where the hierarchy is encoded in a separate data assembly (partitioned dataset collections) and where the hierarchy is encoded as part of the data structure itset (multiblock dataset).
Thanks, Cory! The code worked perfectly. I’m attaching the final macro for completeness sake.
extract_all_blocks.py (7.9 KB)
1 Like