Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XCAFDoc_Dimension.DownCast returned a result with an exception set #1336

Open
aruig666 opened this issue May 24, 2024 · 6 comments
Open

XCAFDoc_Dimension.DownCast returned a result with an exception set #1336

aruig666 opened this issue May 24, 2024 · 6 comments

Comments

@aruig666
Copy link

aruig666 commented May 24, 2024

I think it's possible because TDF_Attribute No constructor defined

        doc = TDocStd_Document("MDTV-CAF")
        # self.doc = TDocStd_Document(TCollection_ExtendedString("pythonocc-doc"))
        m_dimTolTool = XCAFDoc_DocumentTool.DimTolTool(doc.Main())
        step_reader = STEPCAFControl_Reader()
        step_reader.ReadFile(step_filename)
        step_reader.Transfer(doc)
        root_labels = TDF_LabelSequence()
        m_dimTolTool.GetDimensionLabels(root_labels)
        if root_labels.Length() > 0:
            for i in range(root_labels.Length()):
                label = root_labels.Value(i + 1)
                baseAttr = Standard_Transient()
                aDimAttr = XCAFDoc_Dimension()
                if label.HasAttribute():
                    label.FindAttribute(XCAFDoc_Dimension.GetID(), XCAFDoc_Dimension.DownCast(baseAttr))

微信图片_20240524151947

@tpaviot
Copy link
Owner

tpaviot commented May 25, 2024

Can you please post a code that can be run (add all the required imports, insert the example file as a zip archive)

@aruig666
Copy link
Author

aruig666 commented May 27, 2024

@tpaviot It is the whole code.

from OCC.Core.Quantity import Quantity_Color, Quantity_TOC_RGB
from OCC.Core.STEPCAFControl import STEPCAFControl_Reader
from OCC.Core.Standard import Standard_Transient
from OCC.Core.TCollection import TCollection_ExtendedString
from OCC.Core.TDF import TDF_LabelSequence, TDF_Attribute
from OCC.Core.TDocStd import TDocStd_Document
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool_ColorTool, XCAFDoc_DocumentTool_ShapeTool
from OCC.Extend.TopologyUtils import TopologyExplorer

from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool, XCAFDoc_Dimension
from OCC.Core.Geom import Geom_BSplineCurve

if __name__ == "__main__":
    step_filename = r"C:\Users\agem\Desktop\aaapmi_stp.stp"# import a step with a dimension pmi
    doc = TDocStd_Document("MDTV-CAF")
    m_dimTolTool = XCAFDoc_DocumentTool.DimTolTool(doc.Main())
    step_reader = STEPCAFControl_Reader()
    step_reader.ReadFile(step_filename)
    step_reader.SetColorMode(True)
    step_reader.SetGDTMode(True)
    step_reader.SetSHUOMode(True)
    step_reader.SetMatMode(True)
    step_reader.SetNameMode(True)
    step_reader.SetLayerMode(True)
    step_reader.SetPropsMode(True)
    step_reader.SetViewMode(True)
    step_reader.Transfer(doc)
    root_labels = TDF_LabelSequence()
    m_dimTolTool.GetDimensionLabels(root_labels)
    if root_labels.Length() > 0:
        for i in range(root_labels.Length()):
            label = root_labels.Value(i + 1)
            baseAttr = Standard_Transient()
            aDimAttr = XCAFDoc_Dimension()
            if label.HasAttribute():
                label.FindAttribute(XCAFDoc_Dimension.GetID(), XCAFDoc_Dimension.DownCast(baseAttr)) # the error line. It is also wrong to ues Attribute.DownCast(baseAttr)
            aobj = aDimAttr.GetObject() # in 7.5.1,  could not get the object of attribute

Output error message:

SystemError: <built-in function Handle_XCAFDoc_Dimension_DownCast> returned a result with an exception set

Their inheritance relationship is XCAFDoc_Dimension to TDF_Attribute to Standard_Transient
The second input parameter of the label.FindAttribute is of type TDF_Attribute
in pythonocc-core 7.7.2  
Attribute.DownCast(baseAttr) or XCAFDoc_Dimension.DownCast(baseAttr) return error
in pythonocc-core 7.5.1  
Attribute.DownCast(baseAttr) return none and label.FindAttribute(XCAFDoc_Dimension.GetID(), XCAFDoc_Dimension.DownCast(baseAttr)) executed successfully but could not get the object of attribute

@tpaviot
Copy link
Owner

tpaviot commented May 27, 2024

insert the aaa_pmi step file, the same you're using

@aruig666
Copy link
Author

aruig666 commented May 28, 2024

attachFiles.zip
@tpaviot I upload my test files. aaapmi_stp.stp has a dimension pmi as figure:
Snipaste_2024-05-28_13-27-39
nist_ctc_05.stp has many different pmi, and you can find other test step files in:
https://www.nist.gov/services-resources/software/step-file-analyzer-and-viewer

@tpaviot
Copy link
Owner

tpaviot commented May 28, 2024

ok, I think this comes from a missing wrapping method for FindAttribute https://github.com/Open-Cascade-SAS/OCCT/blob/master/src/TDF/TDF_Label.hxx#L147

@aruig666
Copy link
Author

aruig666 commented May 30, 2024

Thanks, how can I update the local wrapping method?
I find the INSTALL.md instructions.

How can I build pythoocc from source code on windows platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants