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 trim

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
dirktheeng
751 Views, 8 Replies

Possible Bug in trim

I created a triangle of sketchLines with one vertex at the origin of the sketch.  I then created a line that intersects (and extends past) both sides that share the origin at the vertex.  I can use trim on the intersecting line and give it the Point3D of either end of the intersecting line and it functions fine.  However, when I try to use trim on either sketchLine that contains the origin and give it the Point3D of the origin, it does not trim the lines.  I have give it some point between the origin and the intersecting line to work.  Not sure if this is a bug or just a result of the algorithm that finds the distance to the trim side.

21st Century Woodworking

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

Hi Dirk,

 

I'm not sure I fully understand what you're trying to do?  Can you post of screenshot of the geometry and what you're trying to trim?  Can  you perform the desired trim interactively in Fusion?


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

Here's the code that fails to trim unless you move the trim point off zero,zero in the +x direction

 

If you uncomment the "trimPoint.x += iD/2" line, it will work as expected

 

#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 9
dirktheeng
in reply to: dirktheeng

BTW, the code still failed if I moved off the zero, zero position to the negative x direction.  According to the docs, I should be able to feed it a Poind3D object the is closest to the side of the trim and have it function correctly.  In this example, any -x position should be closer than any point that is betweeen 0 and cos(iD) so it should trim the line, but it doesnt.

21st Century Woodworking

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

I think I stated that incorrectly.  any -x position should be closer to the side of the trim line than any point with an x value grater than cos(iD).  Basically I would expect it to trim correctly with any point with an x less than cos(iD) wich would include 0,0 or anything y,<0 but it doesn't.

21st Century Woodworking

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

Using your code as-is it creates the triangle with the mid-line but fails to trim the top and bottom lines.  However, if I uncomment the line:

 

    trimPoint.x += iD/2

 

I get the expected results.  This makes sense to me because specifying the trim point at the origin is ambiguous.  When trimming the bottom line and specifying the origin as the trim point it could assume you want to trim to the top line, which results in no change.  Moving the point in the positive direction, anywhere along the red area I've highlighted below should perorm the trim as expected and that's the result I'm seeing.

 

ValidPoint.png

 

Here's what I get after uncommenting the line to modify the X coordinate of the trim point.

 

Result.png


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

I kind of disagree.  There should be no ambiguity becasue I am calling the trim method within the sketchLine instance.  To me that means the trim method is only going to ack on that specific sketchLine instance.  How is that ambiguous as to which sketchLine is going to get trimmed?  Thats why there are two calls to trim for each sketchLine instance, one for lowerLine and one for upperLine.  How can a method in one instance act on another?

21st Century Woodworking

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

I wasn't clear in my last post.  Which line to trim isn't ambiguous, but where to trim the line is.  The trim operation finds all entities that intersect the entity you want to trim and then you specify the section between intersections to be trimmed by specifying a point in the area to trim.  What's ambiguous is if this point is the same as one of the intersection points.  Fusion doesn't know which side of the point to remove.  In your case the origin is the same point as the intersection of the bottom and top lines.


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

That makes sense to me.  I understand now.  Thats why a negative x value wouldn't work eigher because there would be nothing to trim on that side of the intersection point at the origin.  I get it now.  Wish I could read the code for the operations.  It would make life a bit easier.

21st Century Woodworking

-Blending 21st Century Woodworking with Old World Skill

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