Ellipses offset

Ellipses offset

dinocoglitore
Advocate Advocate
1,163 Views
6 Replies
Message 1 of 7

Ellipses offset

dinocoglitore
Advocate
Advocate

Hi forumlanders,

there is something I do not understand ! (Just to learn something more)

In the first picture I used the user interface and created an ellipse on a sketch. Then with Sketch offset I created a second ellipse on the same sketch. When I tested the number of curves I found 4 curves.

These are the types of sketchCurves: the first three are sketchEllipse, sketchLine, sketchLine, the last is a sketchFilletSpline (I aspected an ellipse !!!)

doubt1 v1.png

In the second example (always created with the user interface) I have two sketch:

In the first I created an ellipse. I created a new sketch and copy this ellipse with ctrl-c / ctrl-v in the second sketch. Then I used Sketch offset to expand the second ellipse. I tested the type of curves here it what I found:

In the first sketch: SketchEllipse, SketchLine, SketchLine (all right)

In the second sketch: SketchEllipse, SketchEllipse (????)

Is it correct ????? I loose the axes of the ellipses and there is no more the  SketchFilletSpline

doubt2 v1.png

 

Here is the script I used to test the curves type:

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)
        
        for s in design.rootComponent.sketches:     
            for e in s.sketchCurves:
                tipo = e.objectType
                ui.messageBox("Sketch: " + str(s.name)+" -- Curve type: "+str(tipo))
            
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

  

I wrote a script in which I duplicated an ellipse with the scketch.offset method  and I found the behavior of the first example. When I try to delete the curves, I cannot delete alle the curves. Almost an half of the curves !

 

What am I doing wrong ?

 

Here is the code

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:

        # new document
        app = adsk.core.Application.get()
        ui  = app.userInterface
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        design = adsk.fusion.Design.cast(app.activeProduct)
        design.designType = adsk.fusion.DesignTypes.DirectDesignType

        # Get the root component of the active design.
        rootComp = design.rootComponent
        
        # START - create ellipse on sketch 1 -----------------------------------
        # Create sketch1 on the xz plane.
        sketch1 = rootComp.sketches.add(rootComp.xZConstructionPlane)

        # create collection of ellipses
        ellipses1 = sketch1.sketchCurves.sketchEllipses
        
        centerPoint = adsk.core.Point3D.create(0, 0, 0)
        majorAxisPoint = adsk.core.Point3D.create(10, 0, 0)
        minorpoint =  adsk.core.Point3D.create(0, 5, 0)    
        
        # draw an ellipse
        ellipse1 = ellipses1.add(centerPoint, majorAxisPoint, minorpoint)
        # END - create ellipse on sketch 1 -----------------------------------

        # create a collection of object and add ellipse1
        ellipseCol = adsk.core.ObjectCollection.create()     
        ellipseCol.add(ellipse1)

        # add ellipses (???) to sketch1
        for i in range(1,7):
            
            offset = 1*i
            
            # Create the offset.
            x = minorpoint.x + 2
            y = minorpoint.y 
            dirPoint = adsk.core.Point3D.create(x, y, 0)
            
            # create a new ellipse with offset 
            # !!!!!!!!!!!--------(but is a SketchFittedSpline)------!!!!!!
            sketch1.offset(ellipseCol, dirPoint, offset)
            
        ui.messageBox("Number of curves on sketch: "+str(sketch1.sketchCurves.count))
        
        i=0
        for e in sketch1.sketchCurves:
            e.deleteMe()
            i=i+1
            
        ui.messageBox("Number of curves deleted: "+str(i))
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

I have attached the simple sketchs if you want to test the code.

Thanks

Dino

0 Likes
Accepted solutions (1)
1,164 Views
6 Replies
Replies (6)
Message 2 of 7

yqliu
Alumni
Alumni

Hi Dino,

 

What you observed about the offset result are both correct. Yes, it's a bit confusing.

 

The reason is, theoretically the non-zero offset of an ellipse will never be an ellipse. This is why you get sketchFilletSpline in your first example. However, many people may expect to get an approximated ellipse. So Fusion gives an opportunity to do it - if you drag at a position that is close to the axis of the ellipse, you will get an ellipse, which is what you saw in the second example. 

 

Richard

0 Likes
Message 3 of 7

dinocoglitore
Advocate
Advocate

Hi Richard,

thank you for the reply. Now I understand a little more!

But I cannot undestand why in the second ellipse, although I have ellipses in the second sketch, I loose the axes.

And what about the fact that  I cannot delete all the curves. There is something wrong in my code ?

 

Many thanks

Dino

0 Likes
Message 4 of 7

yqliu
Alumni
Alumni

When you say "I loose the axes", do you mean there is no axes for the second ellipse?

 

Yes, something is wrong in your code:

for e in sketch1.sketchCurves:
            e.deleteMe()
            i=i+1

You should not modify sketchCurves in a for-loop.

 

 

Richard

 

       

 

0 Likes
Message 5 of 7

liujac
Alumni
Alumni
Accepted solution

Hi Dino,

 

It’s able to select the axes when copy the ellipse, so that the axes can be copied along with ellipse.

 

Deleting curve causes the count of sketch curve collection updated, so you need to cache the sketch curves to be deleted in a local array. And the ellipse axes are deleted when deleting the ellipse, so you need to check if the API object is valid before deleting it.

        i=0
        curves = []
        for e in sketch1.sketchCurves:
            curves.append(e)
            
        for c in curves:
            if not c.isValid:
                continue
            c.deleteMe()
            i=i+1

 

 

Regards,

Jack

0 Likes
Message 6 of 7

dinocoglitore
Advocate
Advocate

Many thanks, Richard and Jack.

 

A lot of basic information in few words ! 

I did not think about it.

 

I am going to use your code in my script.

 

Dino

0 Likes
Message 7 of 7

dinocoglitore
Advocate
Advocate

 

May I do another question ?

There is a way to convert the SketchFilletSpline in SketchEllipse ? 

 

Thanks

Dino

 

0 Likes