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()))