RuntimeError: 2 : InternalValidationError : rMatrix->getTargetObjectPath(objectPath)

RuntimeError: 2 : InternalValidationError : rMatrix->getTargetObjectPath(objectPath)

corbin2
Participant Participant
175 Views
12 Replies
Message 1 of 13

RuntimeError: 2 : InternalValidationError : rMatrix->getTargetObjectPath(objectPath)

corbin2
Participant
Participant

Hello! I get this error:

 

RuntimeError: 2 : InternalValidationError : rMatrix->getTargetObjectPath(objectPath)

 

Basic code to reproduce (attached, along with the project):

product = app.activeProduct
root = adsk.fusion.Design.cast(product).rootComponent
s = root.sketches[1]
s.referencePlane
^^^^^^^^^^^^^^
 
It seems to happen when I attempt to get the referencePlane of a Sketch, when the referencePlan is a BRepFace of a Body that was turned into a component. 
 
Any ideas on how to work around this?
 
Thanks,
Corbin
 
0 Likes
176 Views
12 Replies
Replies (12)
Message 2 of 13

Jorge_Jaramillo
Collaborator
Collaborator

Hi @corbin2 ,

 

It seems to loose the reference when you create the component from the body.

A workaround that worked on my environment was to create the component from the body before creating the sketch.

Jorge_Jaramillo_0-1759094190891.png

 

Regards,

Jorge Jaramillo

 

0 Likes
Message 3 of 13

corbin2
Participant
Participant

Hi Jorge,

Yup -- that is what I noted in the post.  I isolated the issue in this simple test case.

 

I'm trying to create an abstract plugin that wouldn't require the user to fix up their model. Any ways I can work around this in code?

 

Corbin

0 Likes
Message 4 of 13

Jorge_Jaramillo
Collaborator
Collaborator

Hi @corbin2 ,

 

I believe the source of the problem is to reference from the sketch an object that is in the future in the timeline.

I tried to redefine the plane in case there is an exception accessing it, but once it was assigned Fusion generate a warning (highlighting the sketch in yellow) asking to re-define the sketch plane.  So, the problem remained the same.

 

The new solution is to define a construction plane which is at the same level of the top face of the body.

Here is the snipped code:

import adsk
import adsk.core
import adsk.fusion
import traceback

app = adsk.core.Application.get()

def run(context) -> None:

    doc = app.activeDocument
    des: adsk.fusion.Design = adsk.fusion.Design.cast(doc.products.itemByProductType('DesignProductType'))
    root = des.rootComponent
    try:
        sketch: adsk.fusion.Sketch = root.sketches[1]
        try:
            app.log(f'{sketch.referencePlane=}')
        except RuntimeError:
            target_body = root.occurrences[0].component.bRepBodies[0].createForAssemblyContext(root.occurrences[0])
            parent_comp = sketch.parentComponent
            cons_plane_inp = parent_comp.constructionPlanes.createInput()
            cons_plane_inp.setByOffset(
                parent_comp.xYConstructionPlane, 
                adsk.core.ValueInput.createByReal(target_body.boundingBox.maxPoint.z))
            cons_plane = parent_comp.constructionPlanes.add(cons_plane_inp)
            sketch.referencePlane = cons_plane
            app.log('referencePlane redefined!')
    except Exception:
        app.log('Failed:\n{}'.format(traceback.format_exc()))
    adsk.terminate()

 

The first run, it catches the exception, and then redefine the sketch plane.

An in the following runs, it just can access the reference plane and print it to the Text Command window.

 

In my opinion, both body and sketch plane should be parametric.  That way there is not restriction on which one is created before and both will have the same definition.

I hope this can help.

 

Regards,

Jorge Jaramillo

 

0 Likes
Message 5 of 13

corbin2
Participant
Participant

Hi Jorge,

Thanks! I do appreciate you looking into this, but I'm going to just assume it is an Autodesk bug that needs to be fixed, right? 

 

One can do this "manually" without the error, so Fusion is doing something else to make it work (creating a new sketch using the original sketch as a reference plane).

 

Your work around will solve the issue for this particular bug test case, but my actual use is a lot more generic. The referencePlane could be on any given BRepFace; like at a 45 degree angle, so grabbing the bounding box z max and x/y construction plane won't work.  

 

But this does get me thinking: I could probably create a construction plane based on the origin point and the xDirection and yDirection of the sketch to generate a Plane.  Seems like such a hacky work around!

 

Is there a way to formally log bugs? This *should* work, right?

 

0 Likes
Message 6 of 13

corbin2
Participant
Participant

In my opinion, both body and sketch plane should be parametric.  

I wish I could enforce good modelling practices, but I just want my plugin to work with whatever people could create.

0 Likes
Message 7 of 13

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

The plane example I posted was just that, an example.  You can make something more complex if you need it.

 

I believe you can post the case to the Fusion Support Forum as a bug.  Here is the link of the forum: https://forums.autodesk.com/t5/fusion-support-forum/bd-p/fusion-support-forum-en

 

Regards,

Jorge Jaramillo

 

0 Likes
Message 8 of 13

corbin2
Participant
Participant

Thanks - I posted on that forum referencing here. 

 

I haven't quite come up with a work around; my plane idea based on the Sketch origin/xDirection/yDirection won't work, because a Plane based ConstructionPlane will only work in non-parametric mode. Ah well.... I'll have to wait to see what support says.

 

Corbin

0 Likes
Message 9 of 13

BrianEkins
Mentor
Mentor

This isn't a bug but is the expected behavior. You'll see this same behavior with a lot of other functions. The issue is as Jorge described, you're trying to get an entity that no longer exists. However, there is a simple solution. You can roll the timeline back to a point where the face does exist and then get it. 

 

Many functions in Fusion contain a statement similar to the one shown below in their documentation. Most of these are strict about it and will immediately fail if it isn't rolled back. However, the referencePlane property is more lenient and will work as long as the entity still exists.

 

To set this property, you need to position the timeline marker to immediately before this joint. This can be accomplished using the following code: thisJoint.timelineObject.rollTo(True)

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 10 of 13

corbin2
Participant
Participant

 


@BrianEkins wrote:

This isn't a bug but is the expected behavior.

 


I don't understand how simply touching sketch.referencePlane and having it throw an exception could be expected behavior. 

 

Many functions in Fusion contain a statement similar to the one shown below in their documentation. Most of these are strict about it and will immediately fail if it isn't rolled back. However, the referencePlane property is more lenient and will work as long as the entity still exists

So, this is a documentation bug? 

 

I am still curious why this would work when I do the operations manually in fusion (ie: create a new Sketch using the original "dead referencePlane" Sketch), but fail when done in code.. It has to be referencing something, and it isn't rolling back....so what is it doing?

 

I did come up with a work around for now:

def getOrCreateSketchPlane(sketch: Sketch) -> ConstructionPlane:
    # see https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/runtimeerror-2-internalvalidationerror-rmatrix-gt/m-p/13829024#M22221
    try:
        return sketch.referencePlane # I know it might not be a ConstructionPlane
    except:
        # try to create a construction plane at the same place
        comp = sketch.parentComponent
        planeInput: ConstructionPlaneInput = comp.constructionPlanes.createInput()
        planeInput.setByOffset(sketch, ValueInput.createByReal(0))

        result = comp.constructionPlanes.add(planeInput)
        result.name = "Hack work around for fusion bug"
        return result

I hadn't tried this before, because the documentation for ConstructionPlane.setByOffset doesn't mention a Sketch instance being an acceptable option...but I tried in code and it works.

 

 

Corbin

 

 

 

0 Likes
Message 11 of 13

BrianEkins
Mentor
Mentor

I don't know the specific steps you're doing because I don't see a difference between the API and manually doing it, so I must be doing something different.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 12 of 13

corbin2
Participant
Participant

@BrianEkins wrote:

I don't know the specific steps you're doing because I don't see a difference between the API and manually doing it, so I must be doing something different.


My bad - I should have included steps. Given the file I posted, here's a video of the steps to reproduce "by hand".

 

0 Likes
Message 13 of 13

corbin2
Participant
Participant

Adding the video as an attachment, as uploading and inserting in place seems to take a long time.

 

0 Likes