Community
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.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flip the direction of distance dimension

4 REPLIES 4
Reply
Message 1 of 5
Padarom
1173 Views, 4 Replies

Flip the direction of distance dimension

I'm writing a Python script to generate components for me. I first create new sketch points roughly where they're going to be and then constrain them properly. However, one distance dimension for a line length keeps flipping the points of the line around.

 

Please take a look at the attachments to see what I mean. Both sketches are identical in their constraints and dimensions. As long as I don't add the dimension to the horizontal line the correct orientation is with the diagonal lines on the right side. However once I add a dimension, the two end points of the line swap places and thus the whole sketch flips.

 

 

horizontal = lines.addByTwoPoints(point(5, 0), point(-5, 0))
horizontal.isConstruction = True
constraints.addHorizontal(horizontal)
constraints.addMidPoint(sketch.originPoint, horizontal)
dimensions.addDistanceDimension(horizontal.startSketchPoint, horizontal.endSketchPoint, adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, point(1, 1)).parameter._set_expression(str(referenceDiameterGear))

This is the code with which I add the horizontal line and its dimensions. I have also tried swapping the places of startSketchPoint and endSketchPoint, but that doesn't change anything.

 

How can I make sure these points aren't being flipped after adding the dimension? The same problem also occurred to me occasionally while manually creating sketches and I couldn't figure out how to deal with it manually either.

4 REPLIES 4
Message 2 of 5
goyals
in reply to: Padarom

We tried with below script but unable to reproduced it. Let me know If anything is missing in it.

 

app = adsk.core.Application.get()

root = app.activeProduct.rootComponent

sketches = root.sketches

sketch = sketches.add(root.xYConstructionPlane)

lines = sketch.sketchCurves.sketchLines

pt1 = adsk.core.Point3D.create(5,0,0)

pt2 = adsk.core.Point3D.create(-5,0,0)

horizontal = lines.addByTwoPoints(pt1,pt2)

horizontal.isConstruction = True

constraints = sketch.geometricConstraints

constraints.addHorizontal(horizontal)

constraints.addMidPoint(sketch.originPoint, horizontal)

dimensions = sketch.sketchDimensions

dimensions.addDistanceDimension(horizontal.startSketchPoint, horizontal.endSketchPoint, adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, adsk.core.Point3D.create(1,1,0))

 

By the way what version of Fusion you noticed this issue?



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 5
Padarom
in reply to: goyals

I'm sorry, I didn't think to include a full reproducible example, I just grabbed the part of the code that was relevant to this single dimension. I am using Fusion 360 2.0.5688

 

point = lambda x, y : adsk.core.Point3D.create(x, y, 0)
newOccurrence = occurrences.addNewComponent(matrix)
newComponent = adsk.fusion.Component.cast(newOccurrence.component)
sketches = newComponent.sketches

xzPlane = newComponent.xZConstructionPlane
sketch = sketches.add(xzPlane)

lines = sketch.sketchCurves.sketchLines
constraints = sketch.geometricConstraints
dimensions = sketch.sketchDimensions

vertical = lines.addByTwoPoints(point(0, 5), point(0, -5))
vertical.isConstruction = True
constraints.addVertical(vertical)
constraints.addMidPoint(sketch.originPoint, vertical)

horizontal = lines.addByTwoPoints(point(5, 0), point(-5, 0))
horizontal.isConstruction = True
constraints.addHorizontal(horizontal)
constraints.addMidPoint(sketch.originPoint, horizontal)
dimensions.addDistanceDimension(horizontal.startSketchPoint, horizontal.endSketchPoint, adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, point(-1, -1)).parameter._set_expression(str(referenceDiameterGear))

rootCone = lines.addByTwoPoints(vertical.endSketchPoint, horizontal.endSketchPoint)
rootCone.isConstruction = True
dimensions.addAngularDimension(vertical, rootCone, point(1, 0)).parameter._set_expression(str(referenceConeAngleGear) + " deg")

The expected shape is a cross with the top and right point connected via a construction line (rootCone). What it ends up as is however the bottom and left point being connected.

 

The angular dimension of rootCone doesn't have anything to do with the horizontal line flipping. I did manage to circumvent the issue by connecting rootCone to horizontal.startSketchPoint (rather than endSketchPoint), but that's only a solution in this case.

 

Once I add this piece of code I have the exact same issue, but can't solve it with the solution above:

 

backConeAddendum = lines.addByTwoPoints(backCone.startSketchPoint, point(0, 0))
constraints.addCollinear(backConeAddendum, backCone)
dimensions.addDistanceDimension(backConeAddendum.endSketchPoint, backCone.startSketchPoint, adsk.fusion.DimensionOrientations.AlignedDimensionOrientation, point(1, 1)).parameter._set_expression(str(addendumGear))

See attachments. CaptureRight is what I'd expect to see, CaptureWrong is what it ends up as.

Message 4 of 5
us.shadow.op
in reply to: Padarom

same thing happening to me, i'll post details to person researching the issue.

Message 5 of 5
us.shadow.op
in reply to: goyals

I have the exact same issue though it is happening to me when using the UI and not programatically.

The quality of the video is low so i'm including the fusion 360 file so it can be tested on your own.
https://youtu.be/qGlUmNBdNIs

When editing d33, d44 inverts visually though nothing is changed in its parameter value. It can be fixed by changing d44 to a negative number, then back to a positive number. This has to be done every time d33 is edited.

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