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: 

Set Plane By Distance On Path

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
barbaracc6
323 Views, 5 Replies

Set Plane By Distance On Path

Hello guys,

In one of my models I needed to use the command setByDistanceOnPath to create a plane at various distances from the path. The path is shown on the second picture.
I noticed that, doing the procedure manually, everything goes well (second picture) and the plans are created where I want (proportions:

0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95). 
However, when I try to do the same procedure via API, the plans are created in a section or distance that does not correspond to the intended one.

I'll leave the step model below and the code I've done so far. I also leave images of how the plans are being created via API vs via visual interface.

Need urgent help on this matter...

 

I appreciate any help initiative!

 

 

CODE:

 

barbaracc6_0-1651074210677.png

barbaracc6_1-1651074528786.png

 

Labels (2)
5 REPLIES 5
Message 2 of 6
barbaracc6
in reply to: barbaracc6

CODE:

import
adsk.core, adsk.fusion, traceback
import os.path
from decimal import Decimal
import math

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

        ################################## IMPORT THE CREATED STP FILE #####################################

        # Access the import manager and root component
        importManager = app.importManager
        rootComp = app.activeProduct.rootComponent
               
        # Get a Pop-Up window to appear and ask the user to select the STEP file
        fileDlg = ui.createFileDialog()
        fileDlg.isMultiSelectEnabled = False
        fileDlg.title = 'Open STEP File'
        fileDlg.filter = 'STEP files (*.ste;*.step;*stp)'
       
        # Get the STEP file open
        msg = ''
        dlgResult = fileDlg.showOpen()
        if dlgResult == adsk.core.DialogResults.DialogOK:
            msg += '\nFiles to Open:'
            for filename in fileDlg.filenames:
                msg += '\n\t{}'.format(filename)
        else:
            return        
       
        # Create the input options and import them to the target
        importOptions = importManager.createSTEPImportOptions(filename)
        importManager.importToNewDocument(importOptions)

        ######################################### FIND EDGE OF THE PATH #########################################
        importManager = app.importManager
        rootComp = app.activeProduct.rootComponent
        design = adsk.fusion.Design.cast(app.activeProduct)
        rootC = design.rootComponent
        bodies = rootC.bRepBodies
       
        #Define the body
        Body1 = bodies.item (0)
        Edges_Body1 = Body1.edges
        NrEdges_Body1 = Body1.edges.count

        Edge_Path = None

        for i in range (0, NrEdges_Body1):
            Edge_Body = Edges_Body1.item(i)
           
            StartEdge_x_Body1 = Edge_Body.startVertex.geometry.x
            StartEdge_x_Body1 = abs(StartEdge_x_Body1)
            StartEdge_x_Body1 = round (StartEdge_x_Body1, 1)

            EndEdge_x_Body1 = Edge_Body.endVertex.geometry.x
            EndEdge_x_Body1 = abs (EndEdge_x_Body1)
            EndEdge_x_Body1 = round(EndEdge_x_Body1, 1)

            if StartEdge_x_Body1==0 and EndEdge_x_Body1==36.6 or EndEdge_x_Body1==0 and StartEdge_x_Body1==36.6 and Edge_Path==None:
                Edge_Path = Edges_Body1.item(i)
                #ui.messageBox ('Edge index: {}'.format(i))


        ######################################### MAKE PLANES ALONG THE PATH #########################################
       
                Geodesic_distance = Edge_Path.length
                Geodesic_distance = round (Geodesic_distance,6)
                ui.messageBox ('Geodesic distance: {}'.format(Geodesic_distance))
       
        ######################################### MAKE PLANES ALONG THE PATH #########################################

               
                # Get construction planes
                planes = rootC.constructionPlanes

                # Create construction plane input
                planeInput = planes.createInput()

                # Add construction plane by distance on path
                proportion = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]

                #app = adsk.core.Application.get()
                #ui = app.userInterface

                #edgeSel = ui.selectEntity('Select edge.', 'Edges')
                #selectedEdge = adsk.fusion.BRepEdge.cast(edgeSel.entity)

                for i in range (0, len(proportion)):
                #distance = adsk.core.ValueInput.createByReal (1.0)
                    distance = adsk.core.ValueInput.createByReal (proportion[i])
                    planeInput.setByDistanceOnPath(Edge_Path, distance)
                #planeInput.setByDistanceOnPath(selectedEdge, distance)
                    planes.add(planeInput)
   
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Message 3 of 6

@barbaracc6 This looks to be a bug in API for a non-native (other than .f3d/.f3z) Fusion file. Unfortunately, I am not able to find a workaround. I tried the code on a similar .f3d file and it worked but was able to reproduce the case after exporting the same file as a .step and using it. Any chance you have the original file in .f3d format? It should work on it.

 

I have reported the case to the API team for future analysis. Thank you for reporting it.

 

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed

  




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


Message 4 of 6

@Rushikesh.kadam thank you for the answer. Unfortunately, i do not have the .f3d or .f3z file, only the .STEP one. Do you know if this bug will be solved shortly? Is there any other way to do what i am trying to do?
Message 5 of 6

@barbaracc6 After some deep analysis found out that the issue is observed only when the design type is Direct modeling. After import of the file if I changed the design type to Parametric modeling using 

design.designType = 1 , the planes are generated correctly. Below is the modified code. I also took the liberty to remove some lines of code that were redundant.
import adsk.core, adsk.fusion, traceback
import os.path
from decimal import Decimal
import math

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

        ################################## IMPORT THE CREATED STP FILE #####################################

        # Access the import manager
        importManager = app.importManager
               
        # Get a Pop-Up window to appear and ask the user to select the STEP file
        fileDlg = ui.createFileDialog()
        fileDlg.isMultiSelectEnabled = False
        fileDlg.title = 'Open STEP File'
        fileDlg.filter = 'STEP files (*.ste;*.step;*stp)'
       
        # Get the STEP file open
        msg = ''
        dlgResult = fileDlg.showOpen()
        if dlgResult == adsk.core.DialogResults.DialogOK:
            msg += '\nFiles to Open:'
            for filename in fileDlg.filenames:
                msg += '\n\t{}'.format(filename)
        else:
            return        
       
        # Create the input options and import them to the target
        importOptions = importManager.createSTEPImportOptions(filename)
        importManager.importToNewDocument(importOptions)

        ######################################### FIND EDGE OF THE PATH #########################################
        design = adsk.fusion.Design.cast(app.activeProduct)
        # Change the design type to Paramteric
        design.designType = 1
        rootC = design.rootComponent
        bodies = rootC.bRepBodies
       
        #Define the body
        Body1 = bodies.item (0)
        Edges_Body1 = Body1.edges
        NrEdges_Body1 = Body1.edges.count

        Edge_Path = None

        for i in range (0, NrEdges_Body1):
            Edge_Body = Edges_Body1.item(i)
           
            StartEdge_x_Body1 = Edge_Body.startVertex.geometry.x
            StartEdge_x_Body1 = abs(StartEdge_x_Body1)
            StartEdge_x_Body1 = round (StartEdge_x_Body1, 1)

            EndEdge_x_Body1 = Edge_Body.endVertex.geometry.x
            EndEdge_x_Body1 = abs (EndEdge_x_Body1)
            EndEdge_x_Body1 = round(EndEdge_x_Body1, 1)

            if StartEdge_x_Body1==0 and EndEdge_x_Body1==36.6 or EndEdge_x_Body1==0 and StartEdge_x_Body1==36.6 and Edge_Path==None:
                Edge_Path = Edges_Body1.item(i)
                #ui.messageBox ('Edge index: {}'.format(i))


        ######################################### MAKE PLANES ALONG THE PATH #########################################
       
                Geodesic_distance = Edge_Path.length
                Geodesic_distance = round (Geodesic_distance,6)
                ui.messageBox ('Geodesic distance: {}'.format(Geodesic_distance))
       
        ######################################### MAKE PLANES ALONG THE PATH #########################################

               
                # Get construction planes
                planes = rootC.constructionPlanes

                # Create construction plane input
                planeInput = planes.createInput()

                # Add construction plane by distance on path
                proportion = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]

                #app = adsk.core.Application.get()
                #ui = app.userInterface

                #edgeSel = ui.selectEntity('Select edge.', 'Edges')
                #selectedEdge = adsk.fusion.BRepEdge.cast(edgeSel.entity)

                for i in range (0, len(proportion)):
                #distance = adsk.core.ValueInput.createByReal (1.0)
                    distance = adsk.core.ValueInput.createByReal (proportion[i])
                    planeInput.setByDistanceOnPath(Edge_Path, distance)
                #planeInput.setByDistanceOnPath(selectedEdge, distance)
                    planes.add(planeInput)
   
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 For the issue observed when the design type is direct modeling (the original issue reported in this post) a bug is reported.

Hope this helps.

 

------------------------------------------------------------------------------------------------------------------------------

If my reply was helpful, please click the "Accept as Solution" button. It helps others get the answer quickly! A "Like" is always welcomed.

 




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


Message 6 of 6

Can't thank you enough for all the help provided in such a quick time!
Keep up with the good job!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report