79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
#Author-Autodesk Inc.
|
|
#Description-Select a path to create a pipe.
|
|
|
|
import adsk.core, adsk.fusion, traceback
|
|
|
|
pipeRadius = 2.5
|
|
pipeThickness = '5mm'
|
|
|
|
def run(context):
|
|
ui = None
|
|
try:
|
|
app = adsk.core.Application.get()
|
|
ui = app.userInterface
|
|
|
|
product = app.activeProduct
|
|
design = adsk.fusion.Design.cast(product)
|
|
if not design:
|
|
ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
|
|
return
|
|
|
|
sel = ui.selectEntity('Select a path to create a pipe', 'Edges,SketchCurves')
|
|
selObj = sel.entity
|
|
|
|
comp = design.rootComponent
|
|
|
|
# create path
|
|
feats = comp.features
|
|
chainedOption = adsk.fusion.ChainedCurveOptions.connectedChainedCurves
|
|
if adsk.fusion.BRepEdge.cast(selObj):
|
|
chainedOption = adsk.fusion.ChainedCurveOptions.tangentChainedCurves
|
|
path = adsk.fusion.Path.create(selObj, chainedOption)
|
|
path = feats.createPath(selObj)
|
|
|
|
# create profile
|
|
planes = comp.constructionPlanes
|
|
planeInput = planes.createInput()
|
|
planeInput.setByDistanceOnPath(selObj, adsk.core.ValueInput.createByReal(0))
|
|
plane = planes.add(planeInput)
|
|
|
|
sketches = comp.sketches
|
|
sketch = sketches.add(plane)
|
|
|
|
center = plane.geometry.origin
|
|
center = sketch.modelToSketchSpace(center)
|
|
sketch.sketchCurves.sketchCircles.addByCenterRadius(center, pipeRadius)
|
|
profile = sketch.profiles[0]
|
|
|
|
# create sweep
|
|
sweepFeats = feats.sweepFeatures
|
|
sweepInput = sweepFeats.createInput(profile, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
|
|
sweepInput.orientation = adsk.fusion.SweepOrientationTypes.PerpendicularOrientationType
|
|
sweepFeat = sweepFeats.add(sweepInput)
|
|
|
|
# create shell
|
|
startFaces = sweepFeat.startFaces
|
|
endFaces = sweepFeat.endFaces
|
|
|
|
objCol = adsk.core.ObjectCollection.create()
|
|
for startFace in startFaces:
|
|
objCol.add(startFace)
|
|
for endFace in endFaces:
|
|
objCol.add(endFace)
|
|
|
|
if objCol.count == 0:
|
|
bodies = sweepFeat.bodies
|
|
for body in bodies:
|
|
objCol.add(body)
|
|
|
|
shellFeats = feats.shellFeatures
|
|
shellInput = shellFeats.createInput(objCol, False)
|
|
shellInput.insideThickness = adsk.core.ValueInput.createByString(pipeThickness)
|
|
shellFeats.add(shellInput)
|
|
|
|
app.activeViewport.refresh()
|
|
|
|
except:
|
|
if ui:
|
|
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
|