UG爱好者
标题:
使用NXOpen删除螺孔
[打印本页]
作者:
vaughn0223
时间:
2023-11-17 10:47
标题:
使用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:19
本帖最后由 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
复制代码
删除前.png
(80.06 KB, 下载次数: 24)
下载附件
2023-11-17 19:19 上传
删除后.png
(77.09 KB, 下载次数: 18)
下载附件
2023-11-17 19:19 上传
作者:
hustmse0510
时间:
2023-11-17 19:24
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([f])
update.DoUpdate(del_holes_mark)
复制代码
欢迎光临 UG爱好者 (https://www.ugsnx.com/)
Powered by Discuz! X3.2