NX Lab

Suppress và Unsuppress component: tắt tạm chi tiết để tối ưu hoặc so sánh cấu hình

#Python#Assembly1 lượt xem

  1. Quản trị viênQuản trị· 0 điểm

    Câu hỏi ·

    Tắt tạm component (suppress) là cách nhanh nhất để giảm tải khi làm việc với assembly lớn hoặc kiểm tra cấu hình khác nhau. API nhận danh sách component để làm hàng loạt.

    Suppress và Unsuppress component Suppress và Unsuppress component

    Các bước thực hiện

    1. Lọc component. Chọn theo tên, ví dụ mọi bu lông.
    2. Suppress. SuppressComponents(danh sách).
    3. Kiểm tra trạng thái. component.IsSuppressed.
    4. Unsuppress. UnsuppressComponents(danh sách, arrangement).
    5. Thao tác theo cấu hình. Dùng Arrangement nếu có nhiều cấu hình.

    Code tham khảo (Python)

    import re
    import NXOpen
    
    def loc_theo_ten(root, mau):
        kq, ngan_xep = [], list(root.GetChildren())
        rx = re.compile(mau, re.IGNORECASE)
        while ngan_xep:
            c = ngan_xep.pop()
            if rx.search(c.DisplayName):
                kq.append(c)
            ngan_xep.extend(c.GetChildren())
        return kq
    
    def main():
        session = NXOpen.Session.GetSession()
        lw = session.ListingWindow
        lw.Open()
        part = session.Parts.Work
        root = part.ComponentAssembly.RootComponent if part else None
        if root is None:
            return
        bu_long = loc_theo_ten(root, r"BU_?LONG|BOLT|SCREW")
        lw.WriteLine("Tìm thấy %d component bu lông/vít" % len(bu_long))
        if not bu_long:
            return
        session.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Suppress")
        loi = part.ComponentAssembly.SuppressComponents(bu_long)
        lw.WriteLine("Sau suppress, số component đang bị tắt: %d" % sum(1 for c in bu_long if c.IsSuppressed))
        # ... làm việc cần thiết rồi bật lại ...
        part.ComponentAssembly.UnsuppressComponents(bu_long, [part.ComponentAssembly.ActiveArrangement])
        lw.WriteLine("Sau unsuppress, còn bị tắt: %d" % sum(1 for c in bu_long if c.IsSuppressed))
    
    if __name__ == "__main__":
        main()
    

    Giải thích code

    • SuppressComponents trả về ErrorList; kiểm tra để biết component nào lỗi.
    • Biểu thức chính quy BU_?LONG|BOLT|SCREW bắt nhiều cách đặt tên bu lông.
    • ActiveArrangement là cấu hình đang dùng; unsuppress theo đúng cấu hình đó.

    Lỗi thường gặp

    • Suppress trong một cấu hình không ảnh hưởng cấu hình khác; kiểm tra kỹ cấu hình đang bật.
    • Component bị suppress không còn tham gia đo khối lượng hay kiểm tra va chạm.

    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.