Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error in addCoincidentConstraint(), and general problems constraining a sketch

Message 1 of 4
167 Views, 3 Replies

Error in addCoincidentConstraint(), and general problems constraining a sketch


I'm trying to write a script to make plywood joints like the one below, and am having problems getting things constrained so that 2 user parameters, 'stock_thickness' and 'clearance', can be updated.

  • joint.PNGThe next image shows the corresponding sketch, which you can see is sketch.PNGnot fully constrained.  The constraints and dimensions I've added include
  • All rectangles have a parallel, perpendicular, and equal constraint.
  • The common lines between narrow and wide rectangles have 2 coincident constraints added.
  • Height of 2 shorter rectangles is dimensioned to 'clearance'.
  • 2 equal constraints are added to vertical lines of the 3 wider rectangles.
  • The horizontal extent is dimensioned to "2*clearance + stock_thickness".
  • 2 coincident constraints are added at diagonal vertices of the projected face.

Since this hasn't fully constrained things, I though that coincident constraints might be needed at the corner of each rectangle.  I tried that, and get


Runtime Error: 5 : Failed to solve. Please try revising dimensions or constraints. 


I've simplified the code so that the only thing I do in a sketch is make a rectangle and try to constrain one corner:



And it still gives the same error.  Can anyone point me to what is happening here, or help me out more generally with how to fully constrain my sketch?

Any help is appreciated!


Message 2 of 4
in reply to: hbrunk

When you generate that sketch without the final constraints, what can you move around? It might be fully constrained 'relatively', but not be anchored to anything (like, you can't change the shape, but you can move it all together). In that case an anchor to origin or locking one element might do it. If that isn't the case, knowing what can move should help you figure out what is missing.


Fwiw, I always put dimensional constraints last as they can change the shape in ways you don't want before things are a little more locked down - not sure if that helps here though.

Message 3 of 4
in reply to: hbrunk

I believe the addCoincident is failing because the lines of the rectangle are already tied together.  In fact, it looks like it's trying to create a coincident constraint between the same point.


The UI does a couple of things to try and make how things are tied together logical, but in this case, it's not a true picture of the internals.  Let's say you start the line command and draw two lines by clicking 3 times.  When you click on the point where the two lines connect, it shows a coincident constraint.  In reality, there's a single sketch point and both lines share the same point.  There is no coincident constraint.  The UI shows it so you can delete the "constraint" which internally creates a new sketch point and modifies one of the lines so it uses it instead of the original sketch point.  So now the lines are no longer tied together.


As far a fully constraining your sketch, I had a hard time following your description, but I would recommend creating the sketch interactively and making note of what you're doing to get it fully constrained.  One difference when creating sketch entities interactively and through the API is that some constraints are inferred as you're sketching and are automatically added.  Through the API, you don't automatically get any constraints.

Brian Ekins
Inventor and Fusion 360 API Expert
Message 4 of 4
in reply to: hbrunk

@BrianEkins , you were right about the sketchpoints in the rectangles.  Instead of using addThreePointRectangle(), I rewrote the code to build the rectangles using separate lines with addByTwoPoints().  This fixed the coincident constraints error.  I added a couple of other constraints, and now the sketch's isFullyConsrained attribute is true.  I thought I was done, but there is strange behavior when I modify the  user parameters.  Here is the fully constrained sketch:


And here is the sketch after I double the width of the center rectangles:


I don't understand how this can happen with a fully constrained sketch.  The only dimensions that I am adding are purely functions of user parameters.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th

Autodesk Design & Make Report