Cannot select .shx fonts on SketchText object

Cannot select .shx fonts on SketchText object

matt_bucknall
Participant Participant
21,073 Views
43 Replies
Message 1 of 44

Cannot select .shx fonts on SketchText object

matt_bucknall
Participant
Participant

Hi,

 

If I try setting fontName on a SketchText object to any of the .shx font names ('Iso', 'Romans' etc), I get the following error:

font-error.png

 

This does not happen if I set the font to a system font like 'Arial'.

 

If I get fontName on a SketchText object that has had its font set to an .shx font via the GUI (EDIT TEXT) then the correct font name is returned without the extension (i.e. if 'Iso.shx' is selected, fontName returns 'Iso').

 

I've tried setting fontName to 'Iso' with and without the .shx extension - It makes no difference.

 

Matt.

 

0 Likes
Accepted solutions (1)
21,074 Views
43 Replies
Replies (43)
Message 21 of 44

goyals
Autodesk
Autodesk

.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 22 of 44

goyals
Autodesk
Autodesk

.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 23 of 44

goyals
Autodesk
Autodesk

I am able to reproduce now. Created FUS-74258 to track it. Thank you for sharing the video. 



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 24 of 44

Anonymous
Not applicable

@Anonymous thanks for logging the issue. When can we expect this to be fixed? 

 

The bug that we reported came from the fact that we could not directly amend the text value of textboxes that use .shx fonts and therefore changing fonts was a work around solution. Is this an issue that is also being looked at?

0 Likes
Message 25 of 44

goyals
Autodesk
Autodesk

Most likely it will be part of Fusion Dec. update. Thanks.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 26 of 44

Anonymous
Not applicable

Hi @goyals 

@suraj.rawat2A43P

 

I just a received a notification related to the V.2.0.9313 update that the "the SketchText fontName property maustinQZ9FZwas throwing an unexpected exception, specifically around .shx fonts. Now it should work fine."

 

I have tested it on my side:

1) I am able to change fonts from non-shx to shx type fonts and then it renders correctly.

2) more importantly: if the initial font is shx and is changed to another font (shx/non-shx font) then I still have the RuntimeError  3: invalid input font name. This is the most critical part for me and still not working.

 

@thomasa88 , are you also having the same issue?

 

 

Thanks

0 Likes
Message 27 of 44

thomasa88
Advocate
Advocate

@Anonymous  @goyals 

I can confirm Antoine's assessment. You have only fixed the graphical bug. The original bug in this forum thread has not been fixed.

In fact, no property on a SketchText is settable if the font is an SHX font. Please see the attached video demonstrating this.

I have also attached the Design file that I used.

 

Fusion 360 2.0.9313
Active Plan: Fusion 360, Personal
Windows 10 (18363)

 

import adsk; app = adsk.core.Application.get(); text = app.activeProduct.rootComponent.sketches[0].sketchTexts[0] 

text.text 
TEXT


# Cannot change *ANY* property of the SketchText object
text.fontName = 'Arial' 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/Users/Thomas/AppData/Local/Autodesk/webdeploy/production/ca426f89300c9832c554fb1598dc1364864ea03e/Api/Python/packages\adsk\fusion.py", line 59183, in _set_fontName
    return _fusion.SketchText__set_fontName(self, value)
RuntimeError: 3 : invalid input font name


text.text = 'new text' 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/Users/Thomas/AppData/Local/Autodesk/webdeploy/production/ca426f89300c9832c554fb1598dc1364864ea03e/Api/Python/packages\adsk\fusion.py", line 59161, in _set_text
    return _fusion.SketchText__set_text(self, value)
RuntimeError: 3 : invalid input font name


text.isVerticalFlip = True 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/Users/Thomas/AppData/Local/Autodesk/webdeploy/production/ca426f89300c9832c554fb1598dc1364864ea03e/Api/Python/packages\adsk\fusion.py", line 59244, in _set_isVerticalFlip
    return _fusion.SketchText__set_isVerticalFlip(self, value)
RuntimeError: 3 : invalid input font name


text.textStyle = adsk.fusion.TextStyles.TextStyleBold 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/Users/Thomas/AppData/Local/Autodesk/webdeploy/production/ca426f89300c9832c554fb1598dc1364864ea03e/Api/Python/packages\adsk\fusion.py", line 59205, in _set_textStyle
    return _fusion.SketchText__set_textStyle(self, value)
RuntimeError: 3 : invalid input font name


text.height = 2.0 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/Users/Thomas/AppData/Local/Autodesk/webdeploy/production/ca426f89300c9832c554fb1598dc1364864ea03e/Api/Python/packages\adsk\fusion.py", line 59153, in _set_height
    return _fusion.SketchText__set_height(self, value)
RuntimeError: 3 : invalid input font name


# text.position can not be accessed at all, but that is another bug. Seems to be the same problem with .angle.
# https://forums.autodesk.com/t5/fusion-360-api-and-scripts/bug-sketchtext-position-gt-internalvalidationerror-fusiontext/td-p/9836589
# Internal ticket: FUS-74257

 

 

 

0 Likes
Message 28 of 44

goyals
Autodesk
Autodesk

We are able to reproduce these issues and team is working on fix. We will update you with progress. Thanks.



Shyam Goyal
Sr. Software Dev. Manager
Message 29 of 44

suraj.rawat2A43P
Autodesk
Autodesk

Hello @thomasa88 @antoine_rousseau

Thanks for your inputs, we are working on all the issues around the .shx font, and the correction will be part of fusion's next update.


Please check the attachment and let us know, incase it is not capturing all the expected behaviours.

 

Thanks,

suraj

0 Likes
Message 30 of 44

thomasa88
Advocate
Advocate

Hi @suraj.rawat2A43P .

 

It looks like it solves the font changing problem. Great!

 

 

Just for completeness, can you check that other variables can be set as well, when the font is SHX?

 

Like this:

# Create a sketch text with an SHX font (e.g. Weidner.shx) in the GUI

import adsk; app = adsk.core.Application.get(); text = app.activeProduct.rootComponent.sketches[0].sketchTexts[0]

text.text = 'new text'
text.isVerticalFlip = True
text.textStyle = adsk.fusion.TextStyles.TextStyleBold
text.height = 2.0

 

 

Message 31 of 44

Anonymous
Not applicable

Thanks for working on this @suraj.rawat2A43P  @goyals 

As mentioned  by @thomasa88 , if we could also get other properties such as .text to work for SHX. 

Message 32 of 44

suraj.rawat2A43P
Autodesk
Autodesk

Hello ,

 

Yes , we will be able to set all the other attributes in case of shx font also. 

Thanks,

Suraj

0 Likes
Message 33 of 44

Anonymous
Not applicable

@suraj.rawat2A43P , @goyals 

 

I have updated fusion and I am now able to change fonts as well as changing properties on shx fonts.

Thanks very much for the work on this

0 Likes
Message 34 of 44

Anonymous
Not applicable

actually I have noticed an odd behavior for all fonts:

See below text boxes samples

pre 1.JPG

 

if I use the API to modify the text then the rendering changes to the following:

after modification with plug in.JPG

 

I need to go in the sketch / textbox and need to press "OK" to get the expected rendering as per the below. 

after modification and update manually.JPG

It seems that the spacing between letter is changed by the API. As a side note, I also noticed that all my templates look to have this issue and I need to go in the textbox to update the rendering. Do you have a solution or workaround to avoid making the changes manually?

@thomasa88 @goyals @suraj.rawat2A43P 

0 Likes
Message 35 of 44

thomasa88
Advocate
Advocate

@goyals 

 

I notice the exact same thing as @Anonymous from version 2.0.9440. (I'm using Windows 10). I have attached a video.

 

Texts edited using the API get extreme letter-spacing. This basically breaks my ParametricText add-in.

 

I had a document with a text created using the old text editor. This text was not affected by the problem.

 

I want to re-iterate a request that I have made in other places: Let add-in developers get beta access.

 

Also, please add some automatic tests for testing the APIs.

Message 36 of 44

Anonymous
Not applicable

Hello @goyals @suraj.rawat2A43P

 

Can you please help with this issue ?

Thanks

Antoine 

0 Likes
Message 37 of 44

suraj.rawat2A43P
Autodesk
Autodesk

Hello @Anonymous @matt_bucknall @thomasa88,

 

Sorry for the inconvenience, we have done some changes regarding the spacing of text. Could you please check with the latest update of fusion and let us know, if still facing the issue.

 

Thanks, 

0 Likes
Message 38 of 44

Anonymous
Not applicable

Hello @suraj.rawat2A43P 

 

I m using version 2.0.9512 and that's the version that introduced the spacing issue. Is there a more recent version?

Thanks 

Antoine

0 Likes
Message 39 of 44

Anonymous
Not applicable

I just tried again and still having the same spacing issue.

0 Likes
Message 40 of 44

kandennti
Mentor
Mentor

Hi there.

If it can be modified with the OK button in the GUI, then it can be modified with text commands.

#Fusion360API Python script
# Fusion360 ver2.0.9512
import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface
        des :adsk.fusion.Design = _app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        # Modifying text with API
        skt :adsk.fusion.Sketch = root.sketches[0]
        sktTxt :adsk.fusion.SketchText = skt.sketchTexts[0]
        sktTxt.text = sktTxt.text
        _ui.messageBox('Modifying text with API')

        # Correct spacing
        correctSpacing(sktTxt)
        _ui.messageBox('Corrected spacing')

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def correctSpacing(
    txt :adsk.fusion.SketchText
    ):

    app = adsk.core.Application.get()
    ui = app.userInterface

    try:
        des :adsk.fusion.Design = app.activeProduct

        isSketchWorkSpaceFg = False
        if adsk.fusion.Sketch.cast(des.activeEditObject):
            # currently a sketch workspace
            isSketchWorkSpaceFg = True

        sels :adsk.core.Selections = ui.activeSelections

        if not isSketchWorkSpaceFg:
            sels.clear()
            sels.add(txt.parentSketch)
            app.executeTextCommand(u'Commands.Start SketchActivate')

        sels.clear()
        sels.add(txt)
        _app.executeTextCommand(u'Commands.Start EditMTextCmd')
        _app.executeTextCommand(u'NuCommands.CommitCmd')

        if not isSketchWorkSpaceFg:
            app.executeTextCommand(u'NaFusionUI.SketchStopCmd')

        sels.clear()
        _app.executeTextCommand(u'NuCommands.SelectCmd')

    except:
        ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

It is not a desirable method by any means, but I think it is faster than manually fixing each one.

 

Considering other issues, I think it is preferable to make SketchText a different object for the old type and the new type.

 

0 Likes