- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been working on a script for some time that sketches text using similar code as found in this example: Sketch Text API Sample API Sample
I don't think I broke anything in my code and it seems like it might be coincidentally tied to the recent update that allows managing text height via parameters (a great update BTW!)
Did the update maybe break something in the API or is there something else I need to do to set the font height? If I run this script, no matter what I set the height parameter to, I always get a 10mm high font.
This code is the same as the sample linked above but fixes an error related to the rootComp variable.
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = app.activeProduct
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a new sketch on the XY construction plane.
sk = rootComp.sketches.add(rootComp.xYConstructionPlane)
# Get the SketchTexts collection object.
texts = sk.sketchTexts
# Add multi-line text.
input = texts.createInput2('This is a long line that is broken automatically.\n\nAnd this is a defined line break.', 0.5)
input.setAsMultiLine(adsk.core.Point3D.create(0, 0, 0),
adsk.core.Point3D.create(10, 5, 0),
adsk.core.HorizontalAlignments.LeftHorizontalAlignment,
adsk.core.VerticalAlignments.TopVerticalAlignment, 0)
texts.add(input)
# Draw an arc to use to create text along a curve.
arc = sk.sketchCurves.sketchArcs.addByThreePoints(adsk.core.Point3D.create(-10, 0, 0),
adsk.core.Point3D.create(-5, 3, 0),
adsk.core.Point3D.create(0, 0, 0))
# Create text along the arc.
input = texts.createInput2('Text Along a Curve', 0.75)
input.setAsAlongPath(arc, False, adsk.core.HorizontalAlignments.CenterHorizontalAlignment, 0)
input.isHorizontalFlip = True
input.isVerticalFlip = True
input.fontName = 'Comic Sans MS'
texts.add(input)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.