Skip to content

Example for loading XmlXCAF or BinXCAF file? #76

@fuyb1992

Description

@fuyb1992

cad.xmlxcaf.zip
having a hard time getting the load XCAF files, here is my code:

import os
from OCC.Core.TDocStd import TDocStd_Document
from OCC.Core.TDF import TDF_LabelSequence

from OCC.Core.XmlXCAFDrivers import xmlxcafdrivers
from OCC.Core.XCAFApp import XCAFApp_Application
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool
from OCC.Core.TCollection import TCollection_ExtendedString


def read_xml_file(file_path):
    # Initialize the application
    print("Initializing application...")
    app = XCAFApp_Application.GetApplication()
    xmlxcafdrivers.DefineFormat(app)
    if app is None:
        raise Exception("Failed to initialize application")

    # Create a new document
    print("Creating new document...")
    doc = TDocStd_Document("pythonocc-doc")
    if doc is None:
        raise Exception("Failed to create document")

    # Create the storage driver

    # Read the XML file
    app.Open(file_path, doc)

    # Access the shape tool
    print("Accessing shape tool...")
    shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main())
    if shape_tool is None:
        raise Exception("Failed to access shape tool")
    labels = TDF_LabelSequence()
    shape_tool.GetFreeShapes(labels)
    # Debug information
    print(f"Number of shapes at root : {labels.Length()}")

I got 0 shape , xml file in zip file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions