Getting constraint information from a double curve mid point constraint

kevinJS92Z
Explorer
Explorer

Getting constraint information from a double curve mid point constraint

kevinJS92Z
Explorer
Explorer

 

Hello.  I am using the python fusion api, and I am trying to get the information from a mid point constraint.  When the curve/line terminates at the mid point, everything is fine and I am able to get all the information I need.  Specifically getting the information about the point that exists at the midpoint.

my_constraints.point()

 

However, when I have a double line mid point constraint as shown in the image below, when I run the above line,

kevinJS92Z_0-1734483736381.png

I get the following error:

  File "<string>", line 1, in <module>
  File "/Users/.../Library/Application Support/Autodesk/webdeploy/production/18bb3b1bcf969ed58454a634b918acc287ad6414/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/fusion.py", line 78315, in _get_point
    return _fusion.MidPointConstraint__get_point(self)

I wish to be able to access the id's (tokens) for each of the lines associated with the mid point constraint, but the other "point" isnt a point but a line.
Is there a way to access this information?  Thank you so much for you help
I have attached the f3d file for the above, but I would hope that it would be pretty easy to replicate. 

0 Likes
Reply
Accepted solutions (1)
131 Views
3 Replies
Replies (3)

BrianEkins
Mentor
Mentor

There is a problem with the API for this. I don't know if the midpoint constraint has changed lately or if the original design of the API was wrong. The API expects that the constraint is always between a sketch point and the midpoint of a line or arc. This isn't always true, as shown in your case, where it's between the midpoint of two lines. The API needs to be updated to support this.

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

kevinJS92Z
Explorer
Explorer

Two follow up questions:

  1. Are there any hacky ways around this to get the data?
  2. Is there a way to get the API patched to be fixed?
0 Likes

Accepted solution

When I first responded, I couldn't think of a workaround, but I realized there might be one and have verified that it works. If you get a midpoint constraint where the point property fails, you can iterate over all the lines and the arcs in the sketch. For each entity, you can get the geometric constraints that affect it. You can compare those constraints with the midpoint constraint. If it's the same, then that line or arc is using that constraint. Of course, you'll need to skip over the line or arc that's returned by the constraint's midPointCurve property.

 

Here's a function I came up with that takes the MidPointConstraint and the known line or arc you got from the midPointCurve property. It will then return the other line or arc.

 

 

def FindOtherCurve(midPointConst: adsk.fusion.MidPointConstraint, knownCurve: adsk.fusion.SketchCurve) -> adsk.fusion.SketchCurve:
    sk = knownCurve.parentSketch
    for skLine in sk.sketchCurves.sketchLines:
        if not skLine == knownCurve:
            for constraint in skLine.geometricConstraints:
                if constraint == midPointConst:
                    return skLine

    for skArc in sk.sketchCurves.sketchArcs:
        if not skArc == knownCurve:
            for constraint in skArc.geometricConstraints:
                if constraint == midPointConst:
                    return skArc

    return None    

 

The API team is aware of this issue and have added it to their backlog, but I don't know when it might be addressed.

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