Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Selecting the specific sketch

pragadeeshbaskar289.pb
Participant

Selecting the specific sketch

pragadeeshbaskar289.pb
Participant
Participant

Hello,

I recently started using API. I was about to create a porous structure by randomly generating spheres.

pragadeeshbaskar289pb_0-1641991122172.png

I was able to create a circle and its axis, but I face problem while I try to revolve it. Seems like sketch.profiles.item() is selecting profiles in no defined order. As a result, this is what I get.

pragadeeshbaskar289pb_1-1641991335600.png

 

r = random.randint(2,6)/10
        circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(x[i], y[i], z[i]), r)
        p1 = adsk.core.Point3D.create(x[i], y[i]-r, z[i])
        p2 = adsk.core.Point3D.create(x[i], y[i]+r, z[i])
        axis = sketchLines.addByTwoPoints(p1, p2)
        prof = sketch.profiles.item(0)
        revInput = revolves.createInput(prof, axis, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        angle = adsk.core.ValueInput.createByReal(2*math.pi)
        revInput.setAngleExtent(False, angle)
        ext = revolves.add(revInput)

 Thanks 

0 Likes
Reply
Accepted solutions (1)
397 Views
4 Replies
Replies (4)

tykapl.breuil
Advocate
Advocate

It isn't clear to me what the intended result actually is but detecting if the profile is a profile you want to revolve using characteristics of it's underlying geometry is often best practice (ie the number of edges, are those edges circles...).

0 Likes

pragadeeshbaskar289.pb
Participant
Participant

pragadeeshbaskar289pb_0-1642038904144.png

The above picture is the result I want. 

@tykapl.breuil 

@BrianEkins 

0 Likes

j.han97
Advocate
Advocate

Hi @pragadeeshbaskar289.pb ,

 

An easier way to achieve this is to add temporary spheres using TemporaryBRepManager, then add them to existing components. You can read more here Fusion 360 Help | TemporaryBRepManager.createSphere Method | Autodesk.

1 Like

tykapl.breuil
Advocate
Advocate
Accepted solution

@j.han97is probably right for your specific case that would be a better solution but here is what I was thinking :

r = random.randint(2, 6)/10
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(x[i], y[i], z[i]), r)
p1 = adsk.core.Point3D.create(x[i], y[i]-r, z[i])
p2 = adsk.core.Point3D.create(x[i], y[i]+r, z[i])
axis = sketchLines.addByTwoPoints(p1, p2)
circleProf = sketch.profiles.item(0)
for prof in sketch.profiles:
    prof: adsk.fusion.Profile
    if prof.profileLoops.count == 1:
        loop = prof.profileLoops.item(0)
        curveEntity = loop.profileCurves.item(0).sketchEntity
        if curveEntity == circle1:
            circleProf = prof
revInput = revolves.createInput(prof, axis, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
angle = adsk.core.ValueInput.createByReal(2*math.pi)
revInput.setAngleExtent(False, angle)
ext = revolves.add(revInput)

This is not clean code because we check every profile for each sphere we create but it works.

The point is before revolving we loop through all profiles, only consider the ones with one edge loop, then check if the sketch entity behind the loop's first curve is the circle we created.

0 Likes