NX Lab

Nhập file STEP vào part mới bằng Step214Importer: chọn đích, sửa hình học và đặt layer

#Python#STEP#Nhập file1 lượt xem

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

    Câu hỏi ·

    Nhận mô hình từ đối tác dưới dạng STEP rồi nhập vào NX là tác vụ thường xuyên. Step214Importer tạo part mới hoặc nhập vào part đang mở, với tùy chọn khâu bề mặt và đơn giản hóa hình học.

    Nhập file STEP vào part mới bằng… Nhập file STEP vào part mới bằng…

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

    1. Tạo importer. session.DexManager.CreateStep214Importer().
    2. Đặt file nguồn và đích. InputFile, OutputFile (file .prt mới).
    3. Đặt cách nhập. ImportTo, FlattenAssembly.
    4. Tùy chọn hình học. SewSurfaces, SimplifyGeometry.
    5. Commit và mở kết quả. FileOpenFlag.

    Code tham khảo (Python)

    import os
    import NXOpen
    
    def nhap_step(session, duong_dan_stp, duong_dan_prt, khau_be_mat=True):
        if not os.path.isfile(duong_dan_stp):
            raise FileNotFoundError(duong_dan_stp)
        os.makedirs(os.path.dirname(duong_dan_prt), exist_ok=True)
        cau_hinh = os.path.join(session.GetEnvironmentVariableValue("UGII_BASE_DIR"), "step214ug", "ugstep214.def")
        im = session.DexManager.CreateStep214Importer()
        try:
            im.InputFile = duong_dan_stp
            im.OutputFile = duong_dan_prt
            im.ImportTo = NXOpen.Step214Importer.ImportToOption.NewPart
            im.FlattenAssembly = False
            im.SewSurfaces = khau_be_mat
            im.SimplifyGeometry = True
            im.FileOpenFlag = False
            if os.path.isfile(cau_hinh):
                im.SettingsFile = cau_hinh
            im.Commit()
        finally:
            im.Destroy()
        return os.path.isfile(duong_dan_prt)
    
    def main():
        session = NXOpen.Session.GetSession()
        lw = session.ListingWindow
        lw.Open()
        nguon = "D:/Nhan_ve/bo_phan_A.stp"
        dich = "D:/Du_an/nhap/bo_phan_A.prt"
        try:
            ok = nhap_step(session, nguon, dich)
            lw.WriteLine("Nhập " + ("thành công: " + dich if ok else "xong nhưng không thấy file .prt đầu ra"))
        except Exception as ex:
            lw.WriteLine("Lỗi nhập STEP: %s" % ex)
    
    if __name__ == "__main__":
        main()
    

    Giải thích code

    • SewSurfaces khâu các mặt rời thành khối đặc nếu có thể, tránh nhận mô hình toàn mặt rời.
    • ImportToOption.NewPart tạo part mới; chọn tùy chọn khác để nhập vào part đang mở.
    • FileOpenFlag = False không mở file sau khi nhập, hợp để chạy hàng loạt.

    Lỗi thường gặp

    • STEP từ phần mềm khác có thể sai đơn vị; kiểm tra kích thước hộp bao sau khi nhập.
    • Dữ liệu khó nhập (bề mặt lỗi) cần công cụ sửa hình học; kiểm tra IsSolidBody của 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.