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: 

Selecting the specific sketch

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
pragadeeshbaskar289.pb
191 Views, 4 Replies

Selecting the specific sketch

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 

4 REPLIES 4
Message 2 of 5

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...).

Message 3 of 5

pragadeeshbaskar289pb_0-1642038904144.png

The above picture is the result I want. 

@tykapl.breuil 

@BrianEkins 

Message 4 of 5

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.

Message 5 of 5

@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.

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