使用NXOpen删除螺孔
刚学习使用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"是空的。
哪位大侠帮忙看看,该如何删除螺孔这个功能呢?
本帖最后由 hustmse0510 于 2023-11-17 19:20 编辑
<img src="https://www.ugsnx.com/forum.php?mod=image&aid=403414&size=300x300&key=78c0d4e438214915&nocache=yes&type=fixnone" border="0" aid="attachimg_403414" alt=""><img src="https://www.ugsnx.com/forum.php?mod=image&aid=403415&size=300x300&key=903a08b3e315fce7&nocache=yes&type=fixnone" border="0" aid="attachimg_403415" alt="">import NXOpen
import NXOpen
import NXOpen_Features
theSession: NXOpen.Session = NXOpen.Session.GetSession()
update: NXOpen.Update = theSession.UpdateManager
workPart: NXOpen.Part = theSession.Parts.Work
features: NXOpen_Features.FeatureCollection = workPart.Features
f: NXOpen_Features.Feature
del_holes_mark = theSession.SetUndoMark(
NXOpen.SessionMarkVisibility.Visible,
'deleteholes')
for f in features:
if isinstance(f, NXOpen_Features.HolePackage):
builder: NXOpen_Features.HolePackageBuilder = features.CreateHolePackageBuilder(
f)
if builder.TapDrillDiameter.Value < 40.0:
update.AddObjectsToDeleteList()
update.DoUpdate(del_holes_mark)
页:
[1]