
Tìm expression do một feature sử dụng và feature phụ thuộc vào một expression
#Python#Expression#Feature1 lượt xem
Quản trị viênQuản trị· 0 điểm
Câu hỏi ·
Trước khi đổi một kích thước, bạn cần biết nó ảnh hưởng tới feature nào. NX Open cho phép đi theo cả hai chiều: từ feature ra expression và từ expression ra feature.
Tìm expression do một feature sử dụng và…Các bước thực hiện
- Từ feature ra expression. feature.GetExpressions().
- Từ expression ra feature. expression.GetUsingFeatures().
- Tìm expression tham chiếu. expression.GetReferencingExpressions().
- In bản đồ phụ thuộc. Một dòng cho mỗi expression.
- Cảnh báo expression mồ côi. Expression không được dùng ở đâu.
Code tham khảo (Python)
import NXOpen def ban_do_phu_thuoc(part): ket_qua = [] for e in part.Expressions: if e.Type != "Number": continue dung_boi = [f.GetFeatureName() for f in e.GetUsingFeatures()] tham_chieu = [x.Name for x in e.GetReferencingExpressions()] ket_qua.append((e.Name, e.RightHandSide, dung_boi, tham_chieu)) return ket_qua def main(): session = NXOpen.Session.GetSession() lw = session.ListingWindow lw.Open() part = session.Parts.Work if part is None: return mo_coi = [] for ten, ct, fs, refs in ban_do_phu_thuoc(part): lw.WriteLine("%s = %s" % (ten, ct)) if fs: lw.WriteLine(" dùng bởi feature: " + ", ".join(fs)) if refs: lw.WriteLine(" được expression khác tham chiếu: " + ", ".join(refs)) if not fs and not refs and not ten.startswith("p"): mo_coi.append(ten) if mo_coi: lw.WriteLine("Expression có thể không dùng tới: " + ", ".join(mo_coi)) if __name__ == "__main__": main()Giải thích code
GetUsingFeaturesvàGetReferencingExpressionshai chiều của đồ thị phụ thuộc.- Expression không có feature và không có expression nào dùng, và không phải biến hệ thống, được coi là 'mồ côi'.
- Danh sách này là cơ sở dọn dẹp mô hình trước khi giao hàng.
Lỗi thường gặp
- Expression được dùng trong khung bản vẽ hoặc PMI có thể không hiện qua
GetUsingFeatures. - Part lớn có hàng nghìn expression: lọc theo tiền tố để giảm kết quả.
Code mang tính tham khảo, viết cho NX 12 trở lên (Python journal). Tên menu và một số lớp có thể khác theo phiên bản NX; hãy chạy thử trên bản sao của chi tiết trước khi dùng cho dữ liệu thật.
Điểm: 0
Trả lời
Đăng nhập để tham gia thảo luận.