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: 

Change Text Script

2 REPLIES 2
Reply
Message 1 of 3
sdi1400294UX4P6
354 Views, 2 Replies

Change Text Script

Hello, 

i am new in scripting and i am facing a problem i am runnign this script that another member of the forum wrote but the thing is i am managing to change the text but it doesnt change the model unless i run compute all i tried adding adsk.doEvent() but still no change in the model... any idea why? the script i am running is: 

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = app.activeProduct
        rootComp = design.rootComponent
        
        # Get the sketch named "ChangeText"
        sk = rootComp.sketches.itemByName('ChangeText')
        
        # Get the first sketch text.
        skText = sk.sketchTexts.item(0)

        #Prompts the user for the new Text   
        (returnValue, cancelled) = ui.inputBox('What text?', 'New text:', )
        
        # Grab the sketch and first text entity 
        sk = rootComp.sketches.itemByName('ChangeText') 
        skText = sk.sketchTexts.item(0)

        # Change the text.
        skText.text = returnValue

        for i in range(100):
            time.sleep(0.01)
            adsk.doEvents()

        # Write in the path to the folder where you want to save STL‘s
        folder = 'C:\stl\zz'

        for i in range(100):
            time.sleep(0.01)
            adsk.doEvents()
        
        # Construct the output filename. Name will be the same as you‘ve changed    the text into.
        filename = folder + skText.text + '.stl'

        # Save the file as STL.
        exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
        stlOptions = exportMgr.createSTLExportOptions(rootComp)
        stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementMedium
        stlOptions.filename = filename
        exportMgr.execute(stlOptions)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
2 REPLIES 2
Message 2 of 3
kandennti
in reply to: sdi1400294UX4P6

Hi @sdi1400294UX4P6 .

 

Using the recently added Design.computeAll Method, the model changes were reflected and the STL file was exported correctly.

 

・・・
        # Change the text.
        skText.text = returnValue

        # for i in range(100):
        #     time.sleep(0.01)
        #     adsk.doEvents()

        # Write in the path to the folder where you want to save STL‘s
        folder = 'C:\stl\zz'

        # for i in range(100):
        #     time.sleep(0.01)
        #     adsk.doEvents()
        
        design.computeAll()
        
        # Construct the output filename. Name will be the same as you‘ve changed    the text into.
        filename = folder + skText.text + '.stl'

・・・
Message 3 of 3
sdi1400294UX4P6
in reply to: kandennti

omg! it works like a charm! 

Thank you you really saved me from a lot of frustration !!

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