Let's run Fusion 360 with Python Part 11 Since there is no point along the path in the API, I thought of an alternative

Introduction

Fusion 360 has a command ** Points along the path ** .. This is a record of twists and turns trying to achieve this with the Fusion 360 API. image.png

Check the reference manual

Specify how to create a build point with the Fusion 360 API [** ConstructionPointInput Object **](http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-b3ffae9a-d7d7-48ee- bd66-b1138536767f) is used. The methods in the reference manual that start with ** setBy ** correspond to each command in the UI, so look for "points along the path". image.png ** setByCenter **> Circle / Sphere / Torus Center Point ** setByEdgePlane **> Points on edges and planes //help.autodesk.com/view/NINVFUS/JPN/?guid=GUID-BF8B03C7-6E09-44E3-A641-E310E3E53FF1) ** setByPoint **> [Top Point](https: // help.autodesk.com/view/NINVFUS/JPN/?guid=GUID-0513EE5B-3A28-425E-AE34-E9E0BFF7D8D1) ** setByThreePlanes **> Points through which the three planes pass ** setByTwoEdges **> Two Edges Passing Point //help.autodesk.com/view/NINVFUS/JPN/?guid=GUID-C0483AF3-AD6E-48C5-8BA7-0443C8AB4D65) that···? ?? ?? Is there a method that corresponds to the line along the path? ?? ??

There was no "point along the path" but there was a "plane along the path"!

With a command similar to a point along the path [** Plane along the path **](https://help.autodesk.com/view/NINVFUS/JPN/?guid=GUID-4ED5A7DB-8EAE-466E- There is A860-8A8968BDD3F8). image.png For some reason, there seems to be ** ConstructionPlaneInput.setByDistanceOnPath method **. is. Why is there a plane but no points? There is nothing that isn't there, so I decided to reopen and think of an alternative.

Create a plane along the path> Let's use the Fusion 360 API to create the intersection of the plane and the path.

procedure

This is the procedure for creating curved points in a sketch. image.png

From the first and last magic to the middle

import adsk.core, adsk.fusion, traceback

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

        # Get the root component of the active design.
        rootComp = design.rootComponent

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

Get the spline in the sketch

Get the spline in Sketch 1 and assign it to crvPath

        #Get sketch 1 in sketch>Get the spline curve in sketch 1
        sketch1 = rootComp.sketches.item(0)
        crvPath = sketch1.sketchCurves.sketchFittedSplines.item(0)

Create a plane along the path

Use setByDistanceOnPath to create a face along the path. I specify a value from 0 to 1 with 0 as the start point and 1 as the end point, but instead of entering the numerical value directly, ** ValueInput ** / ENU /? Guid = GUID-bdeb52e0-a6af-4909-93e8-3b13acd0e39c) Must be specified in the object.

        #Get constructionPlanes object
        planes = rootComp.constructionPlanes
        
        #Get ConstructionPlaneInput object
        planeInput = planes.createInput()

        #Create a plane along the path
        distance = adsk.core.ValueInput.createByReal(0.4)
        planeInput.setByDistanceOnPath(crvPath, distance)
        plane = planes.add(planeInput)

Make an intersection of a plane and a path

Fusion 360 does not have a command to create a plane-path intersection, but [** Sketch.intersectWithSketchPlane method **](http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-1EB28A55 You can create the intersection of the sketch plane and the curve with -7250-4694-A253-582B395AB234). Even if the specified path is a single curve, it seems that it must be an array. Here we add crvPath to the array ʻentities` and put it in the argument of the intersectWithSketchPlane method.

        #Add new sketch
        sketch2 = rootComp.sketches.add(plane)

        #Create the intersection of the sketch plane and the path
        entities = []
        entities.append(crvPath)
        skPoints = sketch2.intersectWithSketchPlane(entities)

When I run this script it looks like this image.png

Summary

It was nice to be able to do it, but it was a lot of work and it was quite troublesome. I tried to draw and execute this code with a faint expectation that pointInput.setByDistanceOnPath is not listed in the reference and can actually be used ... but I got an error and it didn't work!

        # Get construction points
        points = rootComp.constructionPoints
        
        # Create construction point input
        pointInput = points.createInput()

        # Add construction point by distance on path
        distance = adsk.core.ValueInput.createByReal(0.4)
        pointInput.setByDistanceOnPath(crvPath, distance)
        point = points.add(pointInput)

I want it to be implemented in the API as soon as possible!

Recommended Posts

Let's run Fusion 360 with Python Part 11 Since there is no point along the path in the API, I thought of an alternative
I thought about why Python self is necessary with the feeling of a Python interpreter
When reading an image with SimpleITK, there is a problem if there is Japanese in the path
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
The latest NGINX is an application server! ?? I measured the benchmark of NGINX Unit with PHP, Python, Go! !!
How is the progress? Let's get on with the boom ?? in Python
Since there is no description on how to build an environment for nnabla with Docker including GPU, I tried it myself Part 1
List of language codes used in twitter (including API) (with Python dictionary). What is the most commonly used language?
I tried to refactor the template code posted in "Getting images from Flickr API with Python" (Part 2)
I tried to get the authentication code of Qiita API with Python.
I want to color a part of an Excel string in Python
I tried to get the movie information of TMDb API with Python
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
I tried to explain how to get the article content with MediaWiki API in an easy-to-understand manner with examples (Python 3)
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
To automatically send an email with an attachment using the Gmail API in Python
Here is one of the apps with "artificial intelligence" that I was interested in.
[New Corona] Is the next peak in December? I tried trend analysis with Python!
I asked the problem of the tribonacci sequence in C ++ & the number of function calls when writing with the recurrence function (python is also available)
Since I touched Tensorflow for 2 months, I explained the convolutional neural network in an easy-to-understand manner with 95.04% of "handwritten hiragana" identification.