|
刚学习使用NXOpen,在做一个项目。其中有一个需求,删除部件上的所有直径小于40的螺孔。如下是实现代码:
- def remove_holes(file:str, out_file:str, diameter:int):
- theSession = NXOpen.Session.GetSession()
- basePart1, partLoadStatus1 = theSession.Parts.OpenActiveDisplay(file, NXOpen.DisplayPartOption.AllowAdditional)
-
- workPart = theSession.Parts.Work
- displayPart = theSession.Parts.Display
- partLoadStatus1.Dispose()
- theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
-
- # loop for holes
- for feature in workPart.Features:
- print(f'{feature.Name}')
- if isinstance(feature, NXOpen.Features.Hole):
- holeDiameter = feature.GetDiameter()
- print(f'{feature.Name}, hole diameter: {holeDiameter}')
- if holeDiameter < diameter:
- workPart.Features.Delete(feature)
-
- # save
- partSaveStatus1 = workPart.SaveAs(out_file)
- partSaveStatus1.Dispose()
复制代码 使用这种方式,feature都识别不出来,即"workPart.Features"是空的。
哪位大侠帮忙看看,该如何删除螺孔这个功能呢?
|
|