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: 

Possible bug in breakCurve

6 REPLIES 6
Reply
Message 1 of 7
dirktheeng
446 Views, 6 Replies

Possible bug in breakCurve

I tried to use breakCurve on a sketchLine to split it and then make one part of it a construction element.  I got the line to split, but the documentation says that if I split in the middle, it should dele the original and return two sketchLines.  It returns an ObjectCollection object with a count of 1.  item(0) is one part, but item(1) is a NullType.  I would have expected item(1) to be the other line segment and have a count of 2 or for the function to return a tuple with two sketchLine objects in it.

 

As it appears now, I can't get acces to the other line segment without going through a search of all sketchLines and assigning a new one based on exclusion of all the other line segments that I created earlier.

 

I am using the Python API in Winows 7.

 

Either I don't know what I am doing (which is a real possibility) or there is a bug in the API

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
Tags (1)
6 REPLIES 6
Message 2 of 7
ekinsb
in reply to: dirktheeng

Thank you for posting these issues.  If we don't know about them then they won't get fixed.

 

I just ran a simple test of the break method and it worked as expected in my test.  This could be for two reasons; either my test case is different and the problem is case specific or the problem has been fixed because I'm using the next release.  Below is the code I used to test.  I drew a single line that crossed the origin and drew an arc and circle that intersected it.  Breaking the curve by specifying (0,0,0) as the split point results in three lines.  The breakCruve method returned the 3 unique lines.

 

import adsk.core, adsk.fusion, traceback

def main():
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        sk = app.activeEditObject        
        
        ln = sk.sketchCurves.sketchLines.item(0)

        results = ln.breakCurve(adsk.core.Point3D.create(0,0,0), True)        

        for i in range(0, results.count):
            ln = results.item(i)
            ui.messageBox('Line length: ' + str(ln.length))

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

main()

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 7
dirktheeng
in reply to: ekinsb

Here's a trimmed code section that fails to send back 2 line segments.  I tried to cut down as much of it as possible out of a larger program I am working on.  The code of interest is "linereturn".  This code editor should have line numbers added to it so people can reference the line number.

 

#Author Dirk Van Essendelft
#Copyright 12/25/2014 21st Century Woodworking

import adsk.core, adsk.fusion, traceback, math, time

class SegRing:
    
    def __init__(self):
        try:
            self.app = adsk.core.Application.get()
            self.core = adsk.core
            self.ui = self.app.userInterface
            self.product = self.app.activeProduct
            self.design = adsk.fusion.Design.cast(self.product)
            self.rootComp = self.design.rootComponent
            self.sketches = self.rootComp.sketches
            self.pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062
            self.globalOrigin = adsk.core.Point3D.create(0,0,0)
            self.extrudes = self.rootComp.features.extrudeFeatures
        except:
            if self.ui:
                self.ui.messageBox('Problem in __init__:\n{}'.format(traceback.format_exc()))
                
    def createSegmentComp(self,n,iD,oD,height):

        newOcc = self.rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
        comp = newOcc.component
        comp._set_name('Single_Segment')
        sketches = comp.sketches
        sketch = sketches.add(comp.xZConstructionPlane)
        sketch._set_isVisible(False)
        sketch._set_name('SegmentOutline')
        sketchLines = sketch.sketchCurves.sketchLines
        sketchPoints = sketch.sketchPoints
        angle = 2.0*self.pi/n
        halfAngle = angle/2.0
        drawingOrigin = self.globalOrigin.copy()
        sketchPointOrigin = sketchPoints.add(drawingOrigin)
        sketchPointOrigin._set_isFixed(True)
        
        #Create Lower Line
        lowerLineStart = drawingOrigin.copy()
        lowerLineEnd = drawingOrigin.copy()
        lowerLineEnd.x = lowerLineEnd.x + math.cos(halfAngle) * oD * 2
        lowerLineEnd.y = lowerLineEnd.y - math.sin(halfAngle) * oD * 2
        lowerLine = sketchLines.addByTwoPoints(lowerLineStart,lowerLineEnd)
        
        #Create Upper Line        
        upperLineStart = drawingOrigin.copy()
        upperLineEnd = drawingOrigin.copy()
        upperLineEnd.x = upperLineEnd.x + math.cos(halfAngle) * oD * 2
        upperLineEnd.y = upperLineEnd.y + math.sin(halfAngle) * oD * 2
        upperLine = sketchLines.addByTwoPoints(upperLineStart,upperLineEnd)
        
        #Create Outter Line
        oDLineStart = drawingOrigin.copy()
        oDLineStart.x += oD
        oDLineStart.y += oD
        oDLineEnd  = oDLineStart.copy()
        oDLineEnd.y -= 2 * oD
        odLine = sketchLines.addByTwoPoints(oDLineStart,oDLineEnd)
        
        #Create Inner Line        
        idLineStart = drawingOrigin.copy()
        idLineEnd = drawingOrigin.copy()
        idLineStart.x = math.cos(halfAngle) * iD
        idLineStart.y = -1.0 * oD
        idLineEnd.x = idLineStart.x
        idLineEnd.y = -1.0 * idLineStart.y
        idLine = sketchLines.addByTwoPoints(idLineStart,idLineEnd)
        
        #Trim Lines to Create Trapizoid
        lowerLine.trim(lowerLineEnd)
        upperLine.trim(upperLineEnd)
        odLine.trim(oDLineStart)
        odLine.trim(oDLineEnd)
        idLine.trim(idLineStart)
        idLine.trim(idLineEnd)
                
        lineReturn = lowerLine.breakCurve(idLine.startSketchPoint.geometry,True)
        print(lineReturn.count)

#        trimPoint = upperLine.startSketchPoint.geometry.copy()
#        trimPoint.x += iD/2
#        lowerLine.trim(trimPoint)
#        upperLine.trim(trimPoint)

        
def main():
    try:
        
        nSeg = 8          # Number of Segments
        inerDia = 3          # inner diameter
        outterDia = 4          # outter diameter
        ringHeight = 1      # height of ring
        
        sR = SegRing()
        sR.createSegmentComp(nSeg,inerDia,outterDia,ringHeight)

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

main()

 

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
Message 4 of 7
dirktheeng
in reply to: dirktheeng

At least with the current version of the API, you will find that the lower line does indeed split into two parts, but only the part that is returned in the API is the part belonging to the trapizoid (not the part that is belonging to the triangle who's vertex shares the origin).  I sincerely hope this is fixed in the version you have that is part of the next release.

 

BTW, I am a software developer myself and am interested in developing API programs for Fusion 360 in my spare time (I am a python and C++ power user).  Any chance I could get included in users with access to the beta program?  I'd be willing to email you with bug reports and user feedback in exchange.  Having a solid and easy to use Fusion 360 API is in both our best interest I think.  You want an expandable and extensible product, and I want to make products to use your geometry and CAM capabilities so I don't have to maintain those as part of my products.  Win win for business.

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
Message 5 of 7
dirktheeng
in reply to: ekinsb

Also, I hope you are not discouraged if I post a bug or two.  I am really excited to get a full API to market as I am sure you are.  It means some tremendous business opportunities, especially as the CAM capabilities become exposed.  The CEO of Shopbot was interviewed a while ago and asked what he thought about the future of CNC technology and basically he said the next wave of technology would be getting closer to the one click manufacture for individuals.  He listed the 123D applications as an example of how the industry is trending.  I don't think he was aware of the Fusion 360 API at the time, but if you start to expose the CAM and CAD capabilities as part of this enterprize, the possibilities for business are extremely exciting.  This could be a market changing, truely revolutionizing movement in personal, small business, and enterprize software development and could bring us closer to the 1 click manufacturing scinario that Mr. Hall was talking about.  To complete the 1 click manufacture, you need to buy Mach 3 cnc  (now newfangled solutions) and the G-wizzard calculator by cnccookbook.  This could bring CAD to digital signal capabilities for the first time in history, and you need ot offer it in the kind of price scheme you are offering with Fusion 360.  This will truely revolutionize the entire manufactring market.

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill
Message 6 of 7
ekinsb
in reply to: dirktheeng

Thank you for your feedback and know that we are not discouraged when you report problems but welcome the reports because it will help us to make the API better . 

 

I am able to reproduce the problem with the breakCurve method not returning all of the curves and have filed a report (ID 16865) and expect it to be fixed in an upcoming release.  I also re-wrote the documentation because I found the current description to be very confusing an difficult to understand.  Basically, I expect the returned ObjectCollection to contain all of the curves created/modified by the breakCurve method.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7
neil.liu
in reply to: ekinsb

We are working on the issue, you will see the fix soon. Thanks much for reporting the issue. 

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