[bug]Getting wrong SketchEntities from ProfileLoop

[bug]Getting wrong SketchEntities from ProfileLoop

jiri.manak
Contributor Contributor
419 Views
0 Replies
Message 1 of 1

[bug]Getting wrong SketchEntities from ProfileLoop

jiri.manak
Contributor
Contributor

After two updates of Fusion 360 this bug still remains unsolved.

I didn't received any response.

Python script below reproduces the behaviour.

The script run successfully  only in a sketch mode with valid profile.

To really reproduce the bug, the profile must be created specific way. The bug occurs if sketch profile is extended by joining two loops and trimmed. 

A guaranteed  way is (look also at the picture attached)

  1. create  new sketch on XY plane
  2. draw fit spline
  3. add 3 line segments 
  4. add a rectangle crossing bottom line
  5. trim the segments to extend the profile
  6. run the script
  7. script creates 'curves.txt' file with a listing of the Sketch Curves with start and end point.
    Define a path for 'curves.txt' to find the file easier.
    You will see that one Sketch Curve is missing and another is doubled. (If you follow exactly described  way, it is always 1 and 5. This is wrong.
  8. If you export this sketch as dxf, and import it again this effect disappears. The sketch is somehow corrected.
    There is also no problem to work with this profile in Fusion.  The problem has developer, who receives wrong data for another processing.

If you run this script without sketch and profile loop it will fail. (its only for test)

# Author-JiriManak
# Description-Demonstration of the bug

import adsk.core, adsk.fusion, adsk.cam, traceback


def point2str(p):
    return "[{:4.2f}, {:4.2f}, {:4.2f}]".format(p.x, p.y, p.z)


def get_curve_info(profile_curve):
    sketch_entity = profile_curve.sketchEntity
    class_type = sketch_entity.objectType
    sketch_curve = None
    start_p = None
    end_p = None
    if class_type == adsk.fusion.SketchLine.classType():
        sketch_curve = adsk.fusion.SketchLine.cast(sketch_entity)
    if class_type == adsk.fusion.SketchArc.classType():
        sketch_curve = adsk.fusion.SketchArc.cast(sketch_entity)
    if class_type == adsk.fusion.SketchConicCurve.classType():
        sketch_curve = adsk.fusion.SketchConicCurve.cast(sketch_entity)
    if class_type == adsk.fusion.SketchEllipticalArc.classType():
        sketch_curve = adsk.fusion.SketchEllipticalArc.cast(sketch_entity)
    if class_type == adsk.fusion.SketchFittedSpline.classType():
        sketch_curve = adsk.fusion.SketchFittedSpline.cast(sketch_entity)
    if class_type == adsk.fusion.SketchFixedSpline.classType():
        sketch_curve = adsk.fusion.SketchFixedSpline.cast(sketch_entity)

    if sketch_curve:
        start_p = adsk.core.Point3D.cast(sketch_curve.startSketchPoint.geometry)
        end_p = adsk.core.Point3D.cast(sketch_curve.endSketchPoint.geometry)
    return class_type, start_p, end_p


def publish_curve_info(index, curve_info):
    s = ""
    class_type, start_p, end_p = curve_info
    s += "[{:02d}] Sketch Curve: {}\n".format(index, class_type)
    s += "     start point: {}\n".format(point2str(start_p))
    s += "     end point:   {}\n".format(point2str(end_p))
    s += "\n"
    return s


def find_duplicates(collection):
    a_index = 0

    for info_a in collection:
        b_index = 0
        for info_b in collection:
            if a_index == b_index:
                continue
            a_class_type, a_start_p, a_end_p = info_a
            b_class_type, b_start_p, b_end_p = info_b
            if adsk.core.Point3D.cast(a_start_p).isEqualToByTolerance(b_start_p, 0.001):
                if adsk.core.Point3D.cast(a_end_p).isEqualToByTolerance(b_end_p, 0.001):
                    return a_index, b_index,
            b_index += 1
        a_index += 1
    return -1, -1


def run(context):
    ui = None

    try:
        s = "HandDrawnCurvesBug\n"
        s += "List of curves:\n"
        app = adsk.core.Application.get()
        ui = app.userInterface
        active_sketch = app.activeEditObject
        profiles = active_sketch.profiles

        collection = list()

        txtCmd = 'Debug.EntitlementString'
        ui.messageBox(app.executeTextCommand(txtCmd))

        # Individual: Personal / Hobbyist
        # Startup: Startup / Enthusiast
        # Commercial / EE: Commercial
        # Educational
        # Institution: Student

        if profiles.count < 1:
            ui.messageBox("Profile not found !")
        else:
            profile = profiles.item(0)
            profile_loops = profile.profileLoops
            if profile_loops.count > 0:
                profile_loop = profile_loops.item(0)
                profile_curves = profile_loop.profileCurves
                index = 0
                for profile_curve in profile_curves:
                    curve_info = get_curve_info(profile_curve)
                    collection.append(curve_info)
                    s += publish_curve_info(index, curve_info)
                    index += 1

        d0, d2 = find_duplicates(collection)
        if d0 > -1:
            s += "DUPLICATES FOUND: [{:02d}] == [{:02d}]\n".format(d0, d2)

        output = open("D:\\tmp\\curves.txt", 'w')
        output.writelines(s)
        output.close()


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

 Jiri

0 Likes
420 Views
0 Replies
  • bug
Replies (0)