75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
#Author- Autodesk
|
|
#Description- Text along path
|
|
|
|
import adsk.core, adsk.fusion, traceback
|
|
|
|
def run(context):
|
|
ui = None
|
|
try:
|
|
app = adsk.core.Application.get()
|
|
ui = app.userInterface
|
|
design = app.activeProduct
|
|
rootComp = design.rootComponent
|
|
sketches = rootComp.sketches
|
|
xyPlane = rootComp.xYConstructionPlane
|
|
sketch = sketches.add(xyPlane)
|
|
|
|
sketchTexts = sketch.sketchTexts
|
|
|
|
horizontalAlignment = adsk.core.HorizontalAlignments.CenterHorizontalAlignment
|
|
|
|
# Get the SketchLines collection from an existing sketch.
|
|
lines = sketch.sketchCurves.sketchLines
|
|
|
|
# Call an add method on the collection to create a new line.
|
|
linePath = lines.addByTwoPoints(adsk.core.Point3D.create(10,10,0), adsk.core.Point3D.create(20,20,0))
|
|
|
|
#Set as centerLineType
|
|
linePath.isCenterLine = True
|
|
|
|
#Addiing/Creating curves
|
|
# Get the SketchCircles collection from an existing sketch.
|
|
circles = sketch.sketchCurves.sketchCircles
|
|
|
|
# Call an add method on the collection to create a new circle.
|
|
circlePath = circles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 10)
|
|
|
|
sketchTextInput = sketchTexts.createInput2('Text Along Path', 1)
|
|
|
|
sketchTextInput.setAsAlongPath(linePath, False, horizontalAlignment, 10)
|
|
|
|
sketchText = sketchTexts.add(sketchTextInput)
|
|
|
|
#Edit WorkFlow
|
|
#here are getting AlongPathTextDefinition
|
|
textDef = sketchText.definition
|
|
textDef.horizontalAlignment = adsk.core.HorizontalAlignments.RightHorizontalAlignment
|
|
|
|
sketchText.redefineAsFitOnPath(circlePath, True)
|
|
|
|
# here are getting FitOnPathTextDefintion
|
|
textDef2 = sketchText.definition
|
|
isTextAbovePath = textDef2.isAbovePath
|
|
|
|
# Create an extrusion input
|
|
extrudes = rootComp.features.extrudeFeatures
|
|
extInput = extrudes.createInput(sketchText, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
|
|
distance = adsk.core.ValueInput.createByReal(0.1)
|
|
extInput.setDistanceExtent(False, distance)
|
|
extInput.isSolid = True
|
|
|
|
# Create the extrusion
|
|
ext = extrudes.add(extInput)
|
|
|
|
m = sketch.sketchTexts.count
|
|
n = sketch.profiles.count
|
|
ui.messageBox("sketchTexts.count: %i \nprofiles .count: %i" % (m, n))
|
|
|
|
#sketch = sketches.item(0)
|
|
#sketchText = sketch.sketchTexts.item(0)
|
|
#sketchText.text = 'new text'
|
|
|
|
except:
|
|
if ui:
|
|
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
|