Extracting Volume from Inventor part files

I’m working on a subprogram of a large project that’s fetching parametrical data from 3D files and CAM files for data analytics. I’ve been trying to walk through a large article database containing 3D files from Inventor (.ipt files) from which I want to compute the volume.

I’m doing this by using the pywin32 module to interact with Inventor 2022 API. It works fine for most files but I have some problems handling corrupt and/or unresolved file links. These files make Inventor freeze and stop working which halts the python program:

import time
import win32com.client
import psutil
from pathlib import Path


def close_inventor():
    for proc in psutil.process_iter():
        try:
            if "Inventor.exe" in proc.name():
                proc.kill()
                print("Autodesk Inventor process forcefully terminated.")
        except Exception as e:
            print("Error:", e)

def IptScraper(ipt_filename, ipt_file_path, timeout=10):
    start_time = time.time()
    try:
        InventorApp = win32com.client.Dispatch("Inventor.Application")
        InventorApp.Visible = True
        Document = InventorApp.Documents.Open(ipt_file_path)
        part_doc = Document.ComponentDefinition
        Volume = part_doc.MassProperties.Volume
        Document.Close(False)
        Ipt_Information =  {"FileName" : ipt_filename,
                            "Volume"   : Volume}
    except Exception as e:
        if time.time() - start_time > timeout:
            print("Autodesk Inventor has not responded for 8 seconds. Attempting to close it.")
            close_inventor()
        Ipt_Information = {"FileName" : "N/A",
                           "Volume"   : "N/A"
                           }
        print("Error" + str(e))

    return Ipt_Information

# Example usage
ipt_filename = str(Path(r"690561.A.105_0"))
ipt_file_path = str(Path(r"D:\Test\690561.A.105_0 (Spanmiddelen) (FLAGGED).ipt"))
ipt_file_path2 = str(Path(r"D:\Test\632.006.442_003.ipt"))

print(IptScraper(ipt_filename, ipt_file_path))

I’ve tried using a timeout to forcefully close Inventor but the program gets stuck while opening the document:

Document = InventorApp.Documents.Open(ipt_file_path)

I need to manually force close Inventor before the program proceeds and calls the Exception.
I have filtered out a normal file and corrupt one to test. I have tried to use a context manager before but the problem solemnly lies in opening the document. I want to try and keep this program as simple as it can be. Inventor just gets unresponsive because it cant find the unresolved filelink to build the 3D model and keeps looking for it in the Workspace. After manually closing Inventor with task manager the program continues:

Autodesk Inventor has not responded for 10 seconds. Attempting to close it.
Error(-2147023170, 'The remote procedure call failed.', None, None)
{'FileName': 'N/A', 'Volume': 'N/A'}

I want to try and skip the iteration if it takes longer than 10 seconds, forcefully close Inventor and then go to the next .ipt file without having to interact manually.

New contributor

Gerben is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật