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: 

Issue trimming lines in a sketch

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
dylan.k.scott
898 Views, 4 Replies

Issue trimming lines in a sketch

Hello,

 

I have script which creates a sketch curve based on my chosen sketch plane's intersection with a body, I am then programmatically intersecting this sketch curve with straight line segments along its length; this all works fine, but I end up with some strange results in the next step where I trim the lines such that their endpoints are coincident with the sketch curve previously created.  What I expect/want to happen is the trim operation (set to trim the lines at their start and end points) will trim the line up to the point where the sketch curve and the line segment intersect.  This does in fact happen with some of the lines, however several of the line segments are not trimmed as expected, instead it is as if one of the intersection points is not registering.  I've checked to see that everything is 2D on the active sketch plane and it is and have used SketchCurve intersections method to see if it was picking up both intersection points, which it is not in some cases -- I've also checked to see if I can reproduce the behavior in the UI and it also occurs there.  Images are attached to demonstrate what I am trying to explain.

 

Pre-trim.pngPost-trim_bot.pngUI Based Trim (green circle is where cursor is placed).jpgUI Based Trim (expected result).jpg

if bodySelected.name == 'Mandible':
        planeOffsetValue = adsk.core.ValueInput.createByReal(6)
    else:
        planeOffsetValue = adsk.core.ValueInput.createByReal(0)
        
    planeInput.setByOffset(rootComponent.yZConstructionPlane, planeOffsetValue)
    
    # Generate sketch plane and create new sketch
    profilePlane = planes.add(planeInput)
    profileSketch = sketches.add(profilePlane)
    
    # Create a collection to hold the spline fit points
    points = adsk.core.ObjectCollection.create()
    
    # Create a sketch curve from the intersection of the selected body with the previously created sketch plane
    bodyOutline = profileSketch.projectCutEdges(rootComponent.bRepBodies.itemByName(bodySelected.name))

The code snippet above demos the creation of the SketchCurve via projected cut

 

 else:
        segments = int(sketchX)     
        for index in range(1, segments - 1):
            fibLine_StartPoint = adsk.core.Point3D.create(boundsMin.x + index, boundsMin.y - 1, 0)
            fibLine_EndPoint = adsk.core.Point3D.create(boundsMin.x + index, boundsMax.y + 1, 0)
            fibLine = profileSketch.sketchCurves.sketchLines.addByTwoPoints(fibLine_StartPoint, fibLine_EndPoint)
            
            # Trim the line
            fibLine.trim(fibLine_StartPoint)

and this code snippet shows how the lines are generated and trimmed

 

Thank you for any and all help,

 

Dylan

 

 

4 REPLIES 4
Message 2 of 5
ekinsb
in reply to: dylan.k.scott

Can you provide the model where this is happening?  I've tried to reproduce it with some models I have and it's working as expected.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 5
dylan.k.scott
in reply to: ekinsb

Model attached -- thanks for the reply

Message 4 of 5
ekinsb
in reply to: dylan.k.scott

It appears to be a geometry specific problem.  I can reproduce the problem with your model and have filed a bug against the Trim command.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 5
dylan.k.scott
in reply to: ekinsb

Thanks for the help Brian

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