Sketch.referencePlane Property Functionality Changed?

Sketch.referencePlane Property Functionality Changed?

alden_360
Contributor Contributor
134 Views
2 Replies
Message 1 of 3

Sketch.referencePlane Property Functionality Changed?

alden_360
Contributor
Contributor

I have an add-in that has been used successfully for more than a year now and recently started seeing an error within on of my functions when attempting to get the reference plane for a sketch. Below is the error, which indicates that I need to roll back before the sketch is created to get the sketch plane. Is this an intended change and if so is it documented anywhere?

 

File "C:\Users/ALDEN/fusion-add-in\commands\modeling\generate_laser_features.py", line 1038, in get_centerpoints
    sketch_plane = centerpoint_sketch.referencePlane  # Get plane sketch was created on to add another sketch to later
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/ALDEN/AppData/Local/Autodesk/webdeploy/production/f0877c667ada77b44502b5b3316b697a2ba18ad4/Api/Python/packages\adsk\fusion.py", line 68638, in _get_referencePlane
    return _fusion.Sketch__get_referencePlane(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
RuntimeError: 3 : referencePlane is a BRefFace - need to roll timeline back before sketch

 

0 Likes
Accepted solutions (1)
135 Views
2 Replies
Replies (2)
Message 2 of 3

corbin2
Enthusiast
Enthusiast
Accepted solution

Hi Alden,

I've encountered this too -- it isn't necessarily new, as I reported it a while back

 Here's the workaround I use:

 

def _referencePlaneWithTimelineRolledBack(sketch: Sketch) -> (BRepFace | None):
    # sketch.referencePlane throws "need to roll timeline back to access reference plane" when the
    # sketch's plane is a BRepFace and the timeline is positioned after the sketch (which it normally
    # is, since we're running after the whole design has been built). Roll back to right before the
    # sketch to read it, then restore the timeline position.
    savedTimelineObject = currentTimelineObject()
    try:
        sketch.timelineObject.rollTo(rollBefore=True)
        refPlane = sketch.referencePlane
        return refPlane if isinstance(refPlane, BRepFace) else None
    except:
        return None
    finally:
        savedTimelineObject.rollTo(False)

 

Granted, the face will/may become invalid later in the future if you modify that face.  My full code for getting the reference; some of my helper methods are left out, but should be obvious what they do based on the name. 

 

def getOrCreateSketchPlane(sketch: Sketch) -> Base:
    # see https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/runtimeerror-2-internalvalidationerror-rmatrix-gt/m-p/13829024#M22221
    try:
        refPlane = sketch.referencePlane # This is what throws (sometimes)
        if isinstance(refPlane, ConstructionPlane):
            return refPlane
        if isinstance(refPlane, BRepFace):
            return refPlane
        if isinstance(refPlane, Profile):
            return refPlane
        # Sketches aren't supposed to work??
        if isinstance(refPlane, Sketch):
            return refPlane
    except:
        # "need to roll timeline back to access reference plane" is the error you get.
        # So, try rolling back first. 
        refPlaneFace: BRepFace | None = _referencePlaneWithTimelineRolledBack(sketch) # catches exceptions
        if refPlaneFace is not None and refPlaneFace.isValid:
            # This works...but the BRepFace reference may be stale, so we check if it is still valid..although we may invalidate it later on if we modify the face that it was generated on
            return refPlaneFace

    return _createConstPlaneAtSketchesLocation(sketch, "Sketch Reference Plane")

 

Message 3 of 3

alden_360
Contributor
Contributor

Thanks for the reply @corbin2, I ended up in just about the same place. It does shake my confidence in using the API that something like this would suddenly start occurring.

0 Likes