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:

## How can I use an edge as a profile for a not solid sweep (surface)?

4 REPLIES 4
SOLVED
Message 1 of 5
245 Views, 4 Replies

## How can I use an edge as a profile for a not solid sweep (surface)?

I use rotated sweeps as basis to draw electrical coils. This works best on lines or arcs and not good on splines.

The basis curve is done by a formular. So I get points and normaly I would draw a spline along, but in this case it is better to draw arcs along. Then I do this rotated sweeps along the arcs.

But there is a problem: Each surface has its own profile and they do not connect.
To connect them to one surface I want to use the end-edge of an arc-sweep as profile for the next arc-sweep.

In my script you see out comanded lines where I try this. But Fusion does not accept the edge as a profile.
Does someone know a solution?

def run(context):
ui = None
try:
ui = app.userInterface
design = app.activeProduct
# Get the root component of the active design.
root_comp = design.rootComponent
# Create a new sketch on the xy plane.
sketches = root_comp.sketches
xyPlane = root_comp.xYConstructionPlane
points = adsk.core.ObjectCollection.create() # Create an object collection for the points.

windings = 10
pointsPerRound = 4 # Number of points that splines are generated.
i = -pointsPerRound*windings #Startwert, der in der Schleife runtergezählt wird
r = 0.5
h = 0

while i <= 0:
t = (math.pi/(pointsPerRound*windings))*i*2
h = 1.5+((-r)*(math.sin(t*windings)))
xCoord = (h)*(math.sin(t))
yCoord = (h)*(math.cos(t))
zCoord = ((-r)*(math.cos(t*windings)))
i = i + 1

#Combining the points to arcs
for j in range(0,int((windings*pointsPerRound)/2)):

"""
# The right way would be: define a start profile for the sweep...
if j==0:
# ..and then use the edge of the last sweep as profile for the next:
else:
itemIndex = root_comp.bRepBodies.count-1
body = root_comp.bRepBodies.item(itemIndex)
profil=	body.edges.item(3)  #it is not clear witch of the four items
"""
prof = root_comp.createOpenProfile(profil, False)
path = root_comp.features.createPath(arc, False)
sweeps = root_comp.features.sweepFeatures
sweepInput1.isSolid = False

for j in range(0,10):
arcs[j].startSketchPoint.merge(arcs[j+1].endSketchPoint)

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

4 REPLIES 4
Message 2 of 5

It looked interesting, so I gave it a try.

I decided to create only one SketchLine, which would be the profile of the first Sweep, and use the edge of the previous Sweep for the rest of the Sweeps.

# Fusion360API Python script

def run(context):
ui = None
try:
ui = app.userInterface
design = app.activeProduct
# Get the root component of the active design.
root_comp = design.rootComponent

windings = 10
pointsPerRound = 4 # Number of points that splines are generated.
i = -pointsPerRound*windings #Startwert, der in der Schleife runtergezählt wird
r = 0.5
h = 0

# create points
points = []
while i <= 0:
t = (math.pi/(pointsPerRound*windings))*i*2
h = 1.5+((-r)*(math.sin(t*windings)))
xCoord = (h)*(math.sin(t))
yCoord = (h)*(math.cos(t))
zCoord = ((-r)*(math.cos(t*windings)))
points.append(
)
i = i + 1

# create sketch
sketches = root_comp.sketches
xyPlane = root_comp.xYConstructionPlane
sketch.arePointsShown = False

# create arcs
sketch.isComputeDeferred = True
sktArcs = sketch.sketchCurves.sketchArcs
for p1, p2, p3 in zip(points[0::2], points[1::2], points[2::2])]

# create start line & OpenProfile
points[0].x,
points[0].y,
points[0].z - 0.2
),
points[0].x,
points[0].y,
points[0].z - 0.01
)
)
sketch.isComputeDeferred = False

# create paths
paths = [root_comp.features.createPath(arc, False) for arc in arcs]

# create SweepFeatureInput - This is only temporary.
profile,
paths[0],
)
sweepIpt.isSolid = False
sweepIpt.twistAngle = twistAngle

# create SweepFeature
# Create a SweepFeature while modifying SweepFeatureInput.
# Find the edge that will be the next profile from the SweepFeature.
for path in paths:
sweepIpt.profile = profile
sweepIpt.path = path

profile = root_comp.createBRepEdgeProfile(edge, False)

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

def findNextProfileEdge(

nextProfileEdge = None
for edge in sweepFeat.sideFaces[0].edges:
continue

if not idEqualLine(profileGeo, edge.geometry):
nextProfileEdge = edge
break

if not nextProfileEdge:
raise ValueError("Cannot find the next profile!")

return nextProfileEdge

def idEqualLine(

if not l1.isColinearTo(l2):
return False

if l1.startPoint.isEqualTo(p1):
if l1.endPoint.isEqualTo(p2):
return True
elif l1.startPoint.isEqualTo(p2):
if l1.endPoint.isEqualTo(p1):
return True

return False

I don't know about these shapes, but since the Arcs are not smoothly connected, the resulting Surface is not smooth either.

Also, the first and last edges were not connected.
I think it was a problem with the twist angle calculation, but I couldn't figure out what was right.

Message 3 of 5

I forgot to write down the most important thing.
It is the Component.createBRepEdgeProfile method that gets the profile from the edge.

Message 4 of 5

Thank you kandennti, that is a great peace of work!
With the Component.createBRepEdgeProfile method I can now use edges as profiles by simply write:

prof = root_comp.createBRepEdgeProfile(edgeFalse)

But using it in my script worked just for the first three arcs. Then the body.edges.item(2) was the wrong one... somehow the item-number of the ages change by position of the surface... and so further arcs failed.
I wonder how you managed to solve this problem! I will try to understand your code and give further feedback.

Message 5 of 5

Hi Kandennti,
I tested your script. It works very fine. The only change I did was not to calculate all parts (arcs) and enhanced the calculated points so that the arcs are short and the coil is very near to the mathematical optimum.
As you see this script allows very many rotations and can be basis for drawing electrical coils along the edge of the sweeps. I accepted your solution, because this script is your success not mine. I would not have been able to write this nice function to choose allways the right edge.

# Fusion360API Python script

def run(context):
ui = None
try:
# Settings:
windings = 10
pointsPerRound = 20 # Number of points that splines are generated.
calculatedArcs = 20 # All are calculated by windings*pointsPerRound/2
r = 0.5
h = 0
rotations=100

ui = app.userInterface
design = app.activeProduct
root_comp = design.rootComponent

# create points
points = []
i = -pointsPerRound*windings
while i <= 0:
t = (math.pi/(pointsPerRound*windings))*i*2
h = 1.5+((-r)*(math.sin(t*windings)))
xCoord = (h)*(math.sin(t))
yCoord = (h)*(math.cos(t))
zCoord = ((-r)*(math.cos(t*windings)))
points.append(
)
i = i + 1

# create sketch
sketches = root_comp.sketches
xyPlane = root_comp.xYConstructionPlane
sketch.arePointsShown = False

# create arcs
sketch.isComputeDeferred = True
sktArcs = sketch.sketchCurves.sketchArcs
for p1, p2, p3 in zip(points[0::2], points[1::2], points[2::2])]

# create start line & OpenProfile
points[0].x,
points[0].y,
points[0].z - 0.2
),
points[0].x,
points[0].y,
points[0].z - 0.01
)
)
sketch.isComputeDeferred = False

# create paths
paths = [root_comp.features.createPath(arc, False) for arc in arcs]

# create SweepFeatureInput - This is only temporary.
profile,
paths[0],
)
sweepIpt.isSolid = False
sweepIpt.twistAngle = twistAngle

# create SweepFeature
# Create a SweepFeature while modifying SweepFeatureInput.
# Find the edge that will be the next profile from the SweepFeature.
for j in range (0,calculatedArcs):
#for path in paths:
sweepIpt.profile = profile
sweepIpt.path = paths[j] # =path

profile = root_comp.createBRepEdgeProfile(edge, False)

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

def findNextProfileEdge(

nextProfileEdge = None
for edge in sweepFeat.sideFaces[0].edges:
continue

if not idEqualLine(profileGeo, edge.geometry):
nextProfileEdge = edge
break

if not nextProfileEdge:
raise ValueError("Cannot find the next profile!")

return nextProfileEdge

def idEqualLine(

if not l1.isColinearTo(l2):
return False

if l1.startPoint.isEqualTo(p1):
if l1.endPoint.isEqualTo(p2):
return True
elif l1.startPoint.isEqualTo(p2):
if l1.endPoint.isEqualTo(p1):
return True

return False

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