[Bug] intersectWithSketchPlane method doesn't create closed profiles

[Bug] intersectWithSketchPlane method doesn't create closed profiles

JeromeBriot
Mentor Mentor
684 Views
4 Replies
Message 1 of 5

[Bug] intersectWithSketchPlane method doesn't create closed profiles

JeromeBriot
Mentor
Mentor

Hello,

 

I wrote a code that slices a body using the intersectWithSketchPlane method to get sketch profiles.

 

 

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        # Slice spacing in cm
        sliceSpacing = 0.2

        body = ui.selectEntity('Select a body', 'SolidBodies').entity

        if body is None:
            return

        rootComponent = body.parentComponent.parentDesign.rootComponent

        bbPointMax = body.boundingBox.maxPoint
        bbPointMin = body.boundingBox.minPoint

        baseFeats = rootComponent.features.baseFeatures
        baseFeat = baseFeats.add()
        baseFeat.startEdit()

        planes = rootComponent.constructionPlanes
        planeInput = planes.createInput()
        planeInput.targetBaseOrFormFeature = baseFeat

        numSlices = math.floor((bbPointMax.z - bbPointMin.z) / sliceSpacing)

        offset = adsk.core.ValueInput.createByReal(bbPointMin.z)

        planeInput.setByOffset(rootComponent.xYConstructionPlane, offset)

        plane = planes.add(planeInput)

        sketches = rootComponent.sketches

        msg = ''

        for i in range(0, numSlices+1):

            vector = adsk.core.Vector3D.create(0.0, 0.0, bbPointMin.z + i * sliceSpacing)
            transform = adsk.core.Matrix3D.create()
            transform.translation = vector
            plane.transform = transform

            sketch = sketches.add(plane)
            sketch.intersectWithSketchPlane([body])
            sketch.name = 'MySketch_{:03d}'.format(i)
            sketch.isVisible = False

            if sketch.profiles.count == 0:
                sketch.isVisible = True
                msg += 'MySketch_{:03d} : no profile\n'.format(i)

        baseFeat.finishEdit()

        if msg:
            ui.messageBox(msg)

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

 

 

It works well except on some geometries like the one attached to this message.

 

Some intersections don't create closed profiles (forget about the first and the last ones):

 

MySketch_000 : no profile
MySketch_011 : no profile
MySketch_012 : no profile
MySketch_013 : no profile
MySketch_014 : no profile
MySketch_037 : no profile
MySketch_038 : no profile
MySketch_049 : no profile

 

bug-intersectWithSketchPlane-01.PNG

bug-intersectWithSketchPlane-02.PNG

Any ideas?

 

Thank you.

 

0 Likes
685 Views
4 Replies
Replies (4)
Message 2 of 5

MichaelT_123
Advisor
Advisor

Hi Mr Jérôme Briot,

 

... yep ... it is a miracle. It is always good to scrutinize such events to avoid fake ones (given time and level of devotion), so I did.

I took a few body/sketch intersections. Those close to the origin's XY plane were OK.

However, when I moved the offset plane (sketch) to distance -22.0, things became interesting.

The expected intersection profile has not come up (in an active&broken intersection link).

Following the sketch with the broken intersection link, I have found "suspicious free points" at the bottom slopes of the body and removing them one by one, I discovered ... devilish one! ... hence by removing it ... the peace was restored.

The question is ... WHY?

My subjective telepathic whispers induced that there is something suspicious in the bottom slope surface's construction and its successive topological behaviour. Unfortunately, I can't penetrate deeper into the intricacy of the underlying intersection algorithm, so I will cast my trust on TF360 to do so 😎.

 

DevilishPoint.png

 

With Regards

MichaelT

MichaelT
Message 3 of 5

JeromeBriot
Mentor
Mentor

Thank you @MichaelT_123 

 

I keep investigating this issue further on my side.

 

 

Message 4 of 5

BrianEkins
Mentor
Mentor

Do you get the same results when you do the intersection interactively and not using the API?  I would assume so which indicates it's a general problem with the intersect code and nothing that's specific to the API.  In that case, it's probably best to report it in the Fusion 360 Support forum and don't mention anything about the API in your description.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 5 of 5

MichaelT_123
Advisor
Advisor

Hi Mr Jérôme Briot,

I agree,… Mr Ekins explanation is spot on … as at the end, ConstructionPlane is anchored in the model space by Plane3D object, which in term is defined by the rotation matrix + translation (4x4 matrix).

Regarding the "offsetting planes", please find included my sample. I have used planeInput.setByPlane(plane3D) where the ConstructionPlane is derived directly from plane3D (as per above). The method can only be implemented in DirectMode; however, it offers much greater flexibility (and simplicity) by giving access to every element of the rotation matrix and allowing complete control of positioning the plane in 3Dspace.

 

#Author-MT_123
#Description-Test_PlaneOffset

import adsk.core, adsk.fusion, traceback

def run(context):
    try:
        app    = adsk.core.Application.get()
        ui     = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        root   = design.rootComponent
        origin = adsk.core.Point3D.create( 0.0, 0.0,  0.0)

        baseFeats = root.features.baseFeatures
        baseFeat  = baseFeats.add()
        baseFeat.startEdit()

        planes     = root.constructionPlanes
        planeInput = planes.createInput()
        planeInput.targetBaseOrFormFeature = baseFeat

        for direction in [ 'x', 'y','z']:
            for off in [0, 2, 4, 6]:
                if   direction == 'x':
                    vector  = adsk.core.Vector3D.create( off, 0.0, 0.0)
                    normal  = adsk.core.Vector3D.create( 1.0, 0.0, 0.0)
                elif direction == 'y':
                    vector = adsk.core.Vector3D.create( 0.0, off, 0.0)
                    normal = adsk.core.Vector3D.create( 0.0, 1.0, 0.0)
                elif direction == 'z':
                    vector = adsk.core.Vector3D.create( 0.0, 0.0, off)
                    normal = adsk.core.Vector3D.create( 0.0, 0.0, 1.0)

                plane3D = adsk.core.Plane.create(origin, normal)
                planeInput.setByPlane(plane3D)
                plane = planes.add(planeInput)
                transform = plane.transform
                transform.translation = vector
                plane.transform = transform
                plane.name = 'dir_' + direction + '_' + str(off)
        baseFeat.finishEdit()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

PlaneOffset.png

With Regards

MichaelT

 

 

MichaelT
0 Likes