Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SketchTexts.createInput2 Method Height Parameter Not Applied

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
edjohnson100
397 Views, 7 Replies

SketchTexts.createInput2 Method Height Parameter Not Applied

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

 

Labels (3)
7 REPLIES 7
Message 2 of 8

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

Message 3 of 8

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?

Message 4 of 8

Hi @oranje3.interactive .

 

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.

Message 5 of 8


@kandennti wrote:

Hi @oranje3.interactive .

 

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 @oranje3.interactive .

 

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?

 

Message 6 of 8
Message 7 of 8
edjohnson100
in reply to: edjohnson100

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!

 

Message 8 of 8

Awesome, thanks for the update.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report