Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

SketchTexts.createInput2 Method Height Parameter Not Applied

edjohnson100
Participant

SketchTexts.createInput2 Method Height Parameter Not Applied

edjohnson100
Participant
Participant

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

 

0 Likes
Reply
Accepted solutions (1)
956 Views
7 Replies
Replies (7)

boopathi.sivakumar
Autodesk
Autodesk
Accepted solution

Hi @edjohnson100 

Definitely it something looks like latest update with the text causes the issue. Its been reported to the team and they are looking into it.

Thanks for reporting this


Boopathi Sivakumar
Senior Technology Consultant

1 Like

Anonymous
Not applicable

Any workaround suggestions for this please?

Even manually setting .height is ignored. I have a client who replies on this to produce work and now they cannot produce anything of use.

Can the createInput2 be scaled/corrected to the specified height value, using the api?

 

Urgently need to deploy a fix for this bug please, if anything can be suggested till its fixed in the next update?

0 Likes

kandennti
Mentor
Mentor

Hi @Anonymous .

 

Currently, I think the only way to do this is to use TextCommands.

・・・
        input.fontName = 'Comic Sans MS'
        txt = texts.add(input)

        changeTxtHeight(txt, 0.75)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def changeTxtHeight(
    txt :adsk.fusion.SketchText,
    height :float):

    if txt.height == height:
        return

    app = adsk.core.Application.get()
    ui = app.userInterface
    sels :adsk.core.Selections = ui.activeSelections

    skt :adsk.fusion.Sketch = txt.parentSketch
    sels.clear()
    sels.add(skt)
    app.executeTextCommand(u'Commands.Start SketchActivate')

    sels.clear()
    sels.add(txt)
    cmds =[
        u'Commands.Start EditMTextCmd',
        u'Commands.SetDouble TextHeight {}'.format(height),
        u'NuCommands.CommitCmd',
        u'Commands.Start SketchStop',
    ]
    [app.executeTextCommand(cmd) for cmd in cmds]

    sels.clear()

 

However, it is very slow.

0 Likes

Anonymous
Not applicable

@kandennti wrote:

Hi @Anonymous .

 

Currently, I think the only way to do this is to use TextCommands.

 

・・・
        input.fontName = 'Comic Sans MS'
        txt = texts.add(input)

        changeTxtHeight(txt, 0.75)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def changeTxtHeight(
    txt :adsk.fusion.SketchText,
    height :float):

    if txt.height == height:
        return

    app = adsk.core.Application.get()
    ui = app.userInterface
    sels :adsk.core.Selections = ui.activeSelections

    skt :adsk.fusion.Sketch = txt.parentSketch
    sels.clear()
    sels.add(skt)
    app.executeTextCommand(u'Commands.Start SketchActivate')

    sels.clear()
    sels.add(txt)
    cmds =[
        u'Commands.Start EditMTextCmd',
        u'Commands.SetDouble TextHeight {}'.format(height),
        u'NuCommands.CommitCmd',
        u'Commands.Start SketchStop',
    ]
    [app.executeTextCommand(cmd) for cmd in cmds]

    sels.clear()

 

 

However, it is very slow.



@kandennti wrote:

Hi @Anonymous .

 

Currently, I think the only way to do this is to use TextCommands.

 

・・・
        input.fontName = 'Comic Sans MS'
        txt = texts.add(input)

        changeTxtHeight(txt, 0.75)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def changeTxtHeight(
    txt :adsk.fusion.SketchText,
    height :float):

    if txt.height == height:
        return

    app = adsk.core.Application.get()
    ui = app.userInterface
    sels :adsk.core.Selections = ui.activeSelections

    skt :adsk.fusion.Sketch = txt.parentSketch
    sels.clear()
    sels.add(skt)
    app.executeTextCommand(u'Commands.Start SketchActivate')

    sels.clear()
    sels.add(txt)
    cmds =[
        u'Commands.Start EditMTextCmd',
        u'Commands.SetDouble TextHeight {}'.format(height),
        u'NuCommands.CommitCmd',
        u'Commands.Start SketchStop',
    ]
    [app.executeTextCommand(cmd) for cmd in cmds]

    sels.clear()

 

 

However, it is very slow.


@kandennti Thank you. Thankfully it's only the first letter that uses the createInput2 method, any following use the simple method, so it should not be overly slow.

Can I use a path to scale the letter that uses createInput2 instead of using TextCommands, after its added to the sketch?

I had a look at scaling through the UI but I need to use the bottom left point of the entity to scale from, via the api.

Are the points stored as an index, in an intuitive order, so I can identify that specific point?

 

0 Likes

edjohnson100
Participant
Participant

I just noticed this bug has been fixed. The SketchTexts.createInput2 method height parameter is working as expected we're no longer stuck using a 10mm font height.

edjohnson100_0-1623953499376.png

 

Thank you to the development team for fixing this so quickly. Very impressive response!

 

0 Likes

Anonymous
Not applicable
Awesome, thanks for the update.
0 Likes