Skip to content

Commit

Permalink
FINALLY fix constraints for constrained mode. Cleaned up some other b…
Browse files Browse the repository at this point in the history
…ugs.
  • Loading branch information
DVE2000 committed Jan 21, 2018
1 parent 6bb7eda commit 24acb1c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
38 changes: 30 additions & 8 deletions Dogbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def readDefaults(self):
elif var == 'circStr': self.circStr = val
elif var == 'circVal': self.circVal = float(val)
elif var == 'upPlane': self.upPlane = val
elif var == 'outputUnconstrainedGeometry': self.outputUnconstrainedGeometry = bool(val)
elif var == 'outputUnconstrainedGeometry': self.outputUnconstrainedGeometry = val == 'True'
elif var == 'benchmark': self.benchmark = val == 'True'
elif var == 'boneDirection': self.boneDirection = val
elif var == 'minimal': self.minimal = val == 'True'
Expand Down Expand Up @@ -343,6 +343,7 @@ def createConsolidatedDogbones(self):

progressMsg = '[%p%] %v / %m dogbones created'
skipped = 0

for (h0, h1), edges in self.groupEdgesByVExtent(self.edges).items():
# Edges with the same vertical extent will be dogboned using one sketch + extrude-cut operation.
progressDialog.message = "{}\nOperating on {} edges with extent {:.03f},{:.03f}".format(
Expand Down Expand Up @@ -451,27 +452,48 @@ def addDogboneCircle(self, cornerEdge0, cornerEdge1, sketch):

# Corner is defined by points c-a-b, a is where the edges meet.
a, b, c = utils.findPoints(line1, line2)


# Used for various dimensions
diameterDimension = adsk.core.Point3D.create(a.geometry.x, a.geometry.y, 0)

if self.boneDirection == 'both':
# This is a temporary point for our Dogbone sketch's centerline to end at
addX = (b.geometry.x + c.geometry.x) / 2
addY = (b.geometry.y + c.geometry.y) / 2

d = adsk.core.Point3D.create(addX, addY, 0)
line0 = sketch.sketchCurves.sketchLines.addByTwoPoints(a, d)
# Add a temp point to be used for a starting point. It will be constrained to a.
new_a = adsk.core.Point3D.create(a.geometry.x, a.geometry.y, a.geometry.z)
line0 = sketch.sketchCurves.sketchLines.addByTwoPoints(new_a, d)
# line0 should form line a-d that bisects angle c-a-b.
sketch.geometricConstraints.addSymmetry(line1, line2, line0)

# Make sure the start of the line always stays at the projected corner
sketch.geometricConstraints.addCoincident(line0.startSketchPoint, a);
# If the bounding box/mortise of the underlying sketch is moved, fusion doesn't handle the symmetry move properly
# So add symmetry to move the line where we want, then delete it, and add a dimensioned constraint
tmpConst = sketch.geometricConstraints.addSymmetry(line1, line2, line0)
tmpConst.deleteMe()
sketch.sketchDimensions.addAngularDimension(line1, line0, diameterDimension)
else:
addX, addY, parallelLine = utils.findDogboneCenterPoint (self.boneDirection, self.circVal / 2, a, b, c)
d = adsk.core.Point3D.create(a.geometry.x + addX,
a.geometry.y + addY, 0)
line0 = sketch.sketchCurves.sketchLines.addByTwoPoints(a, d)
# We can add a constraint to be parallel to a construction line. Problem is, if underlying sketch changes, The dogbones are still messed up
# Add a temp point to be used for a starting point. It will be constrained to a.
new_a = adsk.core.Point3D.create(a.geometry.x, a.geometry.y, a.geometry.z)
line0 = sketch.sketchCurves.sketchLines.addByTwoPoints(new_a, d)
# Make sure the start of the line always stays at the projected corner
sketch.geometricConstraints.addCoincident(line0.startSketchPoint, a);
# We can add a constraint to be parallel to a construction line. Problem is, if underlying sketch changes,
# fusion doesn't work properly. So, add a parallel constraint to move the line, delete it, and then add and angular
# constraint
if parallelLine == 1:
lineToBeParallelTo = line1
else:
lineToBeParallelTo = line2
sketch.geometricConstraints.addParallel(line0, lineToBeParallelTo)
tmpConst = sketch.geometricConstraints.addParallel(line0, lineToBeParallelTo)
tmpConst.deleteMe()
sketch.sketchDimensions.addAngularDimension(line0, lineToBeParallelTo, diameterDimension)


line0.isConstruction = True
line1.isConstruction = True
Expand All @@ -492,7 +514,7 @@ def addDogboneCircle(self, cornerEdge0, cornerEdge1, sketch):
#if self.boneDirection == 'both' and not self.minimal:
# sketch.geometricConstraints.addCoincident(a, circle)
#else:
diameterDimension = adsk.core.Point3D.create(a.geometry.x, a.geometry.y, 0)
#diameterDimension = adsk.core.Point3D.create(a.geometry.x, a.geometry.y, 0)
sketch.sketchDimensions.addDiameterDimension(circle, diameterDimension)

def groupEdgesByVExtent(self, edges):
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ New enhancements by DVE2000:
- Add option to create a minimal Dogbone. See http://fablab.ruc.dk/more-elegant-cnc-dogbones/
The default offset percent is 10%, but it can be changed from 8% to 14.2%.
- Dogbones can be created on any of the three X, Y, or Z planes at one time. If you run the Add-In 3 times, trying
each plane, you can create all the dogbones for a 3D assembly.
each plane, you can create all the dogbones for a 3D assembly. There's a cautionary note in the limitations section below.
- The Add-In now remembers all your inputs from the last time dogbones were created. Even on Fusion 360 restarts.
If you ever want to get to the absolute default settings, delete the defaults.dat file in the Add-In install directory,
while the Dogbone dialog box is closed.
Expand All @@ -46,17 +46,27 @@ New enhancements by DVE2000:
least an 80 degree angle (included) up to a 100 degree angle (100 degrees is not included), dogbones will be cut. Any edges that
are less than 80 degrees or greater or equal to 100 degrees will be left alone. Fillets should no longer be cut. If you
want dogbones on only 90 degree corners, set the minimum angle to 90 degrees and the maximum angle to 91 degrees.
- Constrained dogbone creation is now working properly! This means that if you clear the "Output Unconstrained Geometry" checkbox, while the
dogbone creation will be very slow and could even bog down, once you change parameters or sizes for items in the underlying sketch,
the dogbones will move properly with the corners.

## Limitations
If you run dogbones on an entire body, if the body has holes in other faces, you'll get dogbones created in unexpected places. You'll also
get partial dogbones on steps. See the following blue highlights:
![Caution](./Resources/caution.jpg)
(I did create a solution for steps, but I'm not releasing it yet. Fusion sometimes acts weirdly with extended dogbones on steps, even giving
the incorrect part of the shape for where to create the dogbones. That happened in the design shown in the next paragraph.)

Also, if you have something like the design below, you won't be able to create dogbones by selecting the body. You'll get a traceback dialog.
Make sure to just select edges of the same heights before creating the dogbones. See a problematic edge selection below:
![Problems](./Resources/problems.jpg)


Still TODO:
- Handle acute angles (<90deg) by generating a slot.
- Allow user to specify orientation (i.e. select "vertical" vector) instead of only handling edges.
- Allow user to specify orientation (i.e. select "vertical" vector) instead of only handling edges (i.e. in the X, Y or Z direction only).
- Handle duplicate edges (avoid generating duplicate overlapping geometry)
- Even if you use the slower "constrained" version, once the initial sketch is modified earlier in the timeline, the dogbones will
not be recreated properly. Just add the dogbones last, or delete them before changing the underlying sketch and redo them afterwards.
I need to figure out the appropriate constraints...
- Selecting a body instead of edges for steps in the design

## Usage:

Expand Down
Binary file added Resources/caution.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/problems.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 24acb1c

Please sign in to comment.