[solved] Basics question. returning f-string doesn't execute.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
llll
Posts: 173
Joined: Fri Nov 12, 2021 1:56 am

[solved] Basics question. returning f-string doesn't execute.

Post by llll »

Returning the string formats it, and does not execute the line.
Copying it into console shows its correct string.

How to execute the string after formatting? :?:

Code: Select all

name = "Untitled"
offset =  '3.427079'
obj = 'Extrude'

def changeY():
    return(f"App.getDocument('{name}').getObject('{obj}').setExpression('.Placement.Base.y', u'50 - {offset}')")
changeY()
App.activeDocument().recompute(None,True,True)
Last edited by llll on Thu Jul 14, 2022 1:01 am, edited 1 time in total.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Basics question. returning f-string doesn't execute.

Post by TheMarkster »

Try Gui.doCommand(string)
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: [solved] Basics question. returning f-string doesn't execute.

Post by onekk »

llll wrote: Wed Jul 13, 2022 1:50 pm Returning the string formats it, and does not execute the line.
Copying it into console shows its correct string.

How to execute the string after formatting?
Ehen call change() it will return the string.

You have to tell python interpreter that you wantbto execute things.

Probably there are other way than the Gui... but python is simply executing what you are telling it to do.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply