NX Journal Get child parts
2019/12/11 categories:NX Journal| tags:NX Journal|Python|
I have created a program to get child parts.
In this program, the components of the work part are acquired, the child parts are acquired, and if there are child parts, they are acquired recursively, and all the child parts are acquired.
The retrieved component goes into components1 and becomes a list of [Hierarchy, Components].
Python Code
import NXOpen
def main():
theSession = NXOpen.Session.GetSession()
workPart = theSession.Parts.Work
theComponent = workPart.ComponentAssembly.RootComponent
rank1 = 0
# アセンブリトップを追加
components1 = [ [rank1, theComponent] ]
# 子部品の属性を再帰で取得
recursion( theComponent, rank1 + 1, components1 )
def recursion( component1, rank2, components2 ):
for child1 in component1.getChildren():
components2.append( [rank2, child1] )
recursion( child1, rank2 + 1, components2 )
if __name__ == '__main__':
main()