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:

## Creating a SketchArc

2 REPLIES 2
SOLVED
Message 1 of 3
162 Views, 2 Replies

## Creating a SketchArc

I could use some help.  Sorry in advance since this is probably something very basic to some.

I want to create an arc in a sketch.  I have the startPoint, endPoint and radius.   There are two possible apis available.

`sketchArcs.addByCenterStartSweep(centerPoint, startPoint, sweepAngle)andsketchArcs.addByThreePoints(startPoint, alongPoint, endPoint) `

I was surprised that there was not a more direct route, giving the endpoints, radius and a direction point the way sketch.offset is handled.  So I've been trying to use the addByCenterStartSweep and I'm struggling.

To get the centerPoint and sweep I was thinking (very likely wrongly) that I needed to do the following

• get the midPoint between startPoint and endPoint
• create a vector from midPoint to startPoint called it lineVector
• create a Matrix3D call it rotate90 and setToRoation(pi / 2, axis, midPoint).  ?? axis = Z axis
• rotate lineVector  90 degrees  with lineVector.transformBy(rotate90)
• create centerPoint using the lineVector's x,y,z. ???
• create vector1 = centerPoint.vectorTo(startPoint) and vector2 = centerPoint.vectorTo(endPoint)
• sweep = vector1.angleTo(vector2)
• create the arc with sketchArcs.addByCenterStartSweep(centerPoint, startPoint, sweep)

Tags (1)
Labels (1)
2 REPLIES 2
Message 2 of 3

Hi @balunist .

If the only conditions are startPoint, endPoint, and radius, four arcs are candidates. I think that is why the method cannot be prepared.

I have created a sample that finds 4 transit points and creates all arcs.

``````# Fusion360API Python script

import traceback
import math
import itertools

def run(context):
try:
ui = app.userInterface

msg: str = 'Select Sketch Point(start)'
selFilter: str = 'SketchPoints'
if not sel:
return

msg = 'Select Sketch Point(end)'
sel = selectEnt(msg, selFilter)
if not sel:
return

length = startPnt.worldGeometry.distanceTo(
endPnt.worldGeometry
)

msg += f'({unitMgr.formatInternalValue(length * 0.5)} or more)'
res, cancelled = ui.inputBox(
msg,
'',
str(
unitMgr.convert(
length * 0.5,
unitMgr.internalUnits,
unitMgr.defaultLengthUnits
) + 1
)
)

if cancelled:
return

if not isFloat(res):
return

float(res),
unitMgr.defaultLengthUnits,
unitMgr.internalUnits
)

if radius < length * 0.5:
return

startPnt,
endPnt,
)

except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def isFloat(s) -> bool:
try:
float(s)
return True
except:
return False

def getMidPoint(

(sPnt.x + ePnt.x) * 0.5,
(sPnt.y + ePnt.y) * 0.5,
(sPnt.z + ePnt.z) * 0.5,
)

def getOffsetVector(

p1.vectorTo(p2)
)
v.normalize()

return v

def getCenterPoints(
r: float,

l1 = sPnt.distanceTo(mPnt)
theta = math.acos(l1 / r)

vec.scaleBy(
math.tan(theta) * l1
)

centers = []
for scl in [1, -1]:
v.scaleBy(scl)

p.translateBy(v)

centers.append(p)

return centers

def getTransitPoints(
centers: list,
r: float,

vec.scaleBy(r)

vecs = []
for s in [1, -1]:
v.scaleBy(s)
vecs.append(v)

pnts = []
for pnt, v in itertools.product(centers, vecs):
p = pnt.copy()
p.translateBy(v)
pnts.append(p)

return pnts

def createArcs(
transitPoints: list):

arcLst = []
skt.isComputeDeferred = True
for mPnt in transitPoints:

skt.isComputeDeferred = False

# ********

# midPoint

# offset vector
sPnt,
ePnt,
skt.xDirection.crossProduct(
skt.yDirection
)
)

# center points
centers = getCenterPoints(
sPnt,
midPnt,
vec
)

# transit points
transitPnts = getTransitPoints(
centers,
vec
)

# arcs
createArcs(
skt,
sPnt,
ePnt,
transitPnts
)

def selectEnt(
msg: str,

try:
ui = app.userInterface
sel = ui.selectEntity(msg, filterStr)
return sel
except:
return None``````
Message 3 of 3

Kandennti,

Excellent, thank you much!!   So some more background on the reason for my question.   I'm trying to gain a better understanding why an SVG file that I created is being misinterpreted by the sketch.importSVG api for which a fusion defect has been created.   I hoping to see the defect fixed soon since it is needed for some optimization for my add-in.

My goal is to perform a round trip by importing the SVG and you have provided the last piece to the puzzle, the Arc.   I did leave out some additional known arguments in my description,  the large-arc-flag and sweep-flag, which would narrow the 4 possible arcs you created down to one.

`A rx ry x-axis-rotation large-arc-flag sweep-flag`

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