Why is one line not visible

Why is one line not visible

RubyRedRick
Enthusiast Enthusiast
368 Views
3 Replies
Message 1 of 4

Why is one line not visible

RubyRedRick
Enthusiast
Enthusiast

Screenshot 2023-02-26 at 1.30.58 PM.png

 

I'm playing with an add-on script to make a sketch of a 2020 extrusion.

I've refactored the code to have a function to draw one quadrant.  It is called four times.  The quadrants are in clockwise  order NE

def makeQuadrant(quadrant,
    sketchLines, sketchArcs, sketchGeometryConstraints,
    xSign, ySign):
    elements = dict()
    lines = []
    posArray = [0,1,2,3,4,5]
    xArray = [0, .225, .55, .55, .31, .31, .85]
    yArray = [.31, .31, .635, .85, .85, 1.0, 1.0]
    firstPoint = adsk.core.Point3D.create(xSign * xArray[1], ySign * yArray[1])
    elements["first_point"] = firstPoint
    lastPoint = adsk.core.Point3D.create(xSign * yArray[1], ySign * xArray[1])
    elements["last_point"] = lastPoint
    for i in posArray:
        startPoint = adsk.core.Point3D.create(xSign * xArray[i], ySign * yArray[i])
        endPoint = adsk.core.Point3D.create(xSign * xArray[i+1], ySign * yArray[i+1])
        if i > 0 & i < 5:
         lines.append(sketchLines.addByTwoPoints(startPoint, endPoint))
    elements["arcStart"] = adsk.core.Point3D.create(xSign * 0.85, ySign * 1, 0)
    elements["arcCenter"] = adsk.core.Point3D.create(xSign * 0.85, ySign * 0.85, 0)
    elements["arc"] = sketchArcs.addByCenterStartSweep(elements["arcCenter"], elements["arcStart"], xSign * ySign * -1.578  )
    for i in posArray:
        startPoint = adsk.core.Point3D.create(xSign * yArray[i], ySign * xArray[i])
        endPoint = adsk.core.Point3D.create(xSign * yArray[i+1], ySign * xArray[i+1])
        if i > 0 & i < 5:
         lines.append(sketchLines.addByTwoPoints(startPoint, endPoint))
    i = 1
    lines[i].isConstruction = True
    
    adsk.core.Application.log("{},{},{},{},{},{} isValid {}, isVisible {}, isConstruction {}".format(
            quadrant,
            i,
            lines[i].startSketchPoint.geometry.x,
            lines[i].startSketchPoint.geometry.y,
            lines[i].endSketchPoint.geometry.x,
            lines[i].endSketchPoint.geometry.y,
            lines[i].isValid,
            lines[i].isVisible,
            lines[i].isConstruction
            ))
    elements["lines"] = lines
    return elements

 

The code at the end is for debugging it is intended to show that the second line in each quadrant is the problem child by marking it as construction.  It also shows that that line in each quadrant has different endpoints, so one line isn't on top of another.

 

Here's the section of the code which calls make quadrant:

# first quadrant
        quadOneElements = makeQuadrant(1, sketchLines, sketchArcs, sketchGeometryConstraints, 1, 1)
        arcCenter = quadOneElements["arcCenter"]
        radialTextPoint = adsk.core.Point3D.create(arcCenter.x + .15,arcCenter.y + .15,arcCenter.z)
        sketchDimensions.addRadialDimension(quadOneElements["arc"],radialTextPoint)
        # second quadrant
        quadTwoElements = makeQuadrant(2, sketchLines, sketchArcs, sketchGeometryConstraints, 1, -1)
        # third quadrant
        quadThreeElements = makeQuadrant(3, sketchLines, sketchArcs, sketchGeometryConstraints, -1, -1)
        # fourth quadrant
        quadFourElements = makeQuadrant(4, sketchLines, sketchArcs, sketchGeometryConstraints, -1, 1)

 

I'm at my wits end to come up with a theory why that line is missing.

 

0 Likes
Accepted solutions (1)
369 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor

Hi @RubyRedRick .

 

I don't know where you are talking about the line, but I interpreted it to mean this red marked line.

1.png

 

This is because you are trying not to draw it in an IF statement.

・・・
    for i in posArray:
        startPoint = adsk.core.Point3D.create(xSign * yArray[i], ySign * xArray[i])
        endPoint = adsk.core.Point3D.create(xSign * yArray[i+1], ySign * xArray[i+1])
        # if i > 0 & i < 5:
            # lines.append(sketchLines.addByTwoPoints(startPoint, endPoint))
        lines.append(sketchLines.addByTwoPoints(startPoint, endPoint))
・・・

 

The other thing I interpreted was that the endpoints of each line were not in alignment.
If you drag the resulting sketch line, you will see that the endpoints are not aligned.

1.png

This is because the Point3D object is used to execute the addByTwoPoints method.
If you want to match endpoints, you must create a SketchPoint in advance and use SketchPoint.

# Fusion360API Python script

import traceback
import adsk
import adsk.core
import adsk.fusion

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root:adsk. fusion.Component = des.rootComponent

        skt: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)

        skt.isComputeDeferred = True

        make_quadrant(1, skt, 1, 1)
        make_quadrant(2, skt, 1, -1)
        make_quadrant(3, skt, -1, -1)
        make_quadrant(4, skt, -1, 1)

        skt.isComputeDeferred = False

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


def make_quadrant(
    quadrant: int,
    sketch: adsk.fusion.Sketch,
    xSign: float,
    ySign: float) -> dict:

    xArray = [0, .225, .55, .55, .31, .31, .85]
    yArray = [.31, .31, .635, .85, .85, 1.0, 1.0]

    # this side lines
    points = [adsk.core.Point3D.create(xSign * x, ySign * y, 0) 
        for x, y in zip(xArray, yArray)]

    sketchPoints: adsk.fusion.SketchPoints = sketch.sketchPoints
    sktPointsThis = [sketchPoints.add(p) for p in points]

    sketchLines: adsk.fusion.SketchLines = sketch.sketchCurves.sketchLines
    linesThis = [sketchLines.addByTwoPoints(p1, p2) 
        for p1, p2 in zip(sktPointsThis, sktPointsThis[1:])]

    # other side lines
    points = [adsk.core.Point3D.create(xSign * x, ySign * y, 0) 
        for x, y in zip(yArray, xArray)]

    sktPointsOther = [sketchPoints.add(p) for p in points]
    linesOther = [sketchLines.addByTwoPoints(p1, p2) 
        for p1, p2 in zip(sktPointsOther, sktPointsOther[1:])]

    # arc
    sketchArcs: adsk.fusion.SketchArcs = sketch.sketchCurves.sketchArcs
    arc: adsk.fusion.SketchArc = sketchArcs.addFillet(
        linesThis[-1],
        linesThis[-1].endSketchPoint.geometry,
        linesOther[-1],
        linesOther[-1].endSketchPoint.geometry,
        0.15
    )


    linesThis.extend(linesOther)
    return {
        'lines': linesThis,
        'arc': arc
    }

 

You can also use the SketchPoint.merge method to match, but this is easier than finding the other point.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-78a405d9-b50f-4da2-aade-8617a7e37a37 

0 Likes
Message 3 of 4

RubyRedRick
Enthusiast
Enthusiast

No look at the circles. I drew those lines as construction to show I was looking at equivalent lines in each quadrant. All the lines are drawn by the same code. I know about the constraint problem, that’s on the to-do list.B5BFE260-1036-4E46-802B-C764D5A56A1B.jpeg

0 Likes
Message 4 of 4

BrianEkins
Mentor
Mentor
Accepted solution

It looks like it's a problem with the if statement when you draw the lines. You're using the "&" operator which is a bitwise and where I think you want to "and" which is a logical and. Here's a good description of the difference between the two. https://www.geeksforgeeks.org/difference-between-and-and-in-python/

 

Here's a modified version of your code that draws the complete shape.

def makeQuadrant(quadrant,
    sketchLines, sketchArcs, sketchGeometryConstraints,
    xSign, ySign):
    elements = dict()
    lines = []
    posArray = [0,1,2,3,4,5]
    xArray = [0, .225, .55, .55, .31, .31, .85]
    yArray = [.31, .31, .635, .85, .85, 1.0, 1.0]
    firstPoint = adsk.core.Point3D.create(xSign * xArray[1], ySign * yArray[1])
    elements["first_point"] = firstPoint
    lastPoint = adsk.core.Point3D.create(xSign * yArray[1], ySign * xArray[1])
    elements["last_point"] = lastPoint
    for i in posArray:
        startPoint = adsk.core.Point3D.create(xSign * xArray[i], ySign * yArray[i])
        endPoint = adsk.core.Point3D.create(xSign * xArray[i+1], ySign * yArray[i+1])
        if i >= 0 and i <= 5:
         lines.append(sketchLines.addByTwoPoints(startPoint, endPoint))
    elements["arcStart"] = adsk.core.Point3D.create(xSign * 0.85, ySign * 1, 0)
    elements["arcCenter"] = adsk.core.Point3D.create(xSign * 0.85, ySign * 0.85, 0)
    elements["arc"] = sketchArcs.addByCenterStartSweep(elements["arcCenter"], elements["arcStart"], xSign * ySign * -1.578  )
    for i in posArray:
        startPoint = adsk.core.Point3D.create(xSign * yArray[i], ySign * xArray[i])
        endPoint = adsk.core.Point3D.create(xSign * yArray[i+1], ySign * xArray[i+1])
        if i >= 0 and i <= 5:
         lines.append(sketchLines.addByTwoPoints(startPoint, endPoint))
    
    adsk.core.Application.log("{},{},{},{},{},{} isValid {}, isVisible {}, isConstruction {}".format(
            quadrant,
            i,
            lines[i].startSketchPoint.geometry.x,
            lines[i].startSketchPoint.geometry.y,
            lines[i].endSketchPoint.geometry.x,
            lines[i].endSketchPoint.geometry.y,
            lines[i].isValid,
            lines[i].isVisible,
            lines[i].isConstruction
            ))
    elements["lines"] = lines
    return elements
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes