Invalidated Extrusions after copy

Invalidated Extrusions after copy

chip.cox
Participant Participant
496 Views
5 Replies
Message 1 of 6

Invalidated Extrusions after copy

chip.cox
Participant
Participant

I am probably going about this the hard way.  That seems to be the story of my life.  But here it goes.  

I have a design complete with text which extruded on the face.  I tried embossing it first, but had the same problem.  The first thing I do after gathering some information is use addNewComponentCopy to copy a template component containing the script I want to another sub-component off the root.  I do all my updates against this occurrence.  However after the component copy, the three extrusions of text are all invalid.  I have a loop for each character I want to change and they change on the sketch properly but are never reflected in the body.  I am assuming that is because the extrusion events in the timeline are invalid.  If I right click on each invalid timeline event and select edit feature, all I have to do is click OK and the sketch is shown in the body correctly. 

 

How can I make the extrusion or better the emboss events auto update as the sketch changes?

Or how do I determine invalid events and force them to re-execute.

 

Thank you

0 Likes
Accepted solutions (1)
497 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

Can you post your model? I would like to test it to see if the same thing happens when you go through the same steps using the user interface or if this problem is specific to using the API.

 

If you run the "Compute All" command at the bottom of the MODIFY menu, does that fix the extrusions?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 6

chip.cox
Participant
Participant

Here is my code.  It is my first attempt at a script.  It's even still named Hello World.  Please be gentle and don't hurt yourself laughing too hard.

#Author- Chip Cox
#Description- My first script

import adsk.core, adsk.fusion, adsk.cam, traceback, string,os
from itertools import chain

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface

        #Replace this section with a drop down font selection later
        [ans,canc]=ui.inputBox('Font Family','Font')
        if canc==True :
          ui.messageBox('cancled')
          return
        else:
          font=ans
        [ans,canc]=ui.inputBox('Font Size','Font')
        if canc==True :
          ui.messageBox('Cancled')
          return
        else:
          fontsize=int(ans)/10

        # we have our font now - it may not be valid but it's a string
        #ui.messageBox('Font ' + font + ' - ' + str(int(fontsize*10)))

        # Lets get the design mode and get started
        design=adsk.fusion.Design.cast(app.activeProduct)
        if not design:
            ui.messageBox('No active Fusion 360 Design', 'No Design')
            return
        else:
            rc=design.rootComponent   # rc = Root Component
            #ui.messageBox('root component name = ' + rc.name)

            trans=None
            for tc in rc.occurrences:
              if tc.name=='Template:1':
                trans=tc.transform
                break
            if trans==None:
              ui.messageBox('Template component not found')
              return

            # create new occurance of component and name it after the font we are creating.
            nc=rc.occurrences.addNewComponentCopy(tc.component,trans)
            nc.component.name=font + str(int(fontsize*10))
            
            nc.activate()
            nc.isLightBulbOn=True
            tc.isLightBulbOn=False

            #find the sketch named template in the component occurance we are working with
            tempsk=nc.component.sketches.itemByName('Template')

            # get the text box on the sketch
            tempsktextitem=tempsk.sketchTexts.item(0)
            # set its font to the new font entered above
            tempsktextitem.fontName=font
            #set the user parameter for font size to the new font size.  This effects ALL components.
            design.userParameters.itemByName('FontSize').value=fontsize


            # Write in the path to the folder where you want to save STL‘s
            fdir=ui.createFolderDialog()
            fdir.title = 'Folder to save STL file in'
            fdirResults=fdir.showDialog()
            # Check fdirResults for ok/cancel/etc
            folder = fdir.folder + '/'

            #ui.messageBox(folder)
            ext=rc.features.extrudeFeatures
          
            #for c in chain(numbers,letters,upperletters,numbers):
            for c in string.printable:
              tempsktextitem.text=c
              print(c)
              tempsk.redefine(rc.xZConstructionPlane)
        
              # Construct the output filename. Name will be the same as you‘ve changed    the text into.
              filename = ''.join([folder,font, '-', str(int(fontsize)), '-ch-',c if c!='/' else 'slash'])
              #ui.messageBox(filename)
              # Save the file as STL.
              exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
              stlOptions = exportMgr.createSTLExportOptions(nc.bRepBodies.item(0),filename)
              if stlOptions == None:
                ui.messageBox('stlOptions is null')
                return
              stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementMedium
              #stlOptions.filename = filename
              stlOptions.isIncludingInvisibleBodies=True
              stlOptions.isIncludingInvisibleComponents=True
              if not exportMgr.execute(stlOptions):
                ui.messageBox('error executing export')
            ui.messageBox('Done')

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

   

0 Likes
Message 4 of 6

chip.cox
Participant
Participant
Oh, and I forgot to add I got it to work by re-assigning the plane. Which is what I guess happens when I edit the extrude features in the time line. I'm just not sure if that's normal.
0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor
Accepted solution

This seems to be a general Fusion problem and isn't specific to the API. You can easily see it if you select the "Template:1" occurrence in the timeline and choose "Copy" from the context menu. Now select the top node in the browser, and choose the "Paste New" command from the timeline. You'll see a new occurrence in the browser and also several new features in the timeline. The last three extrusions will be yellow. Running the "Compute All" command fixed those three but an earlier extrude changes to yellow. To fix it I had to open the edit dialog for the feature and click OK.

 

It will be good if you can report this on the Support forum. I wouldn't mention the API in your report since it doesn't have anything to do with the problem.

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 6 of 6

chip.cox
Participant
Participant

Will do.  It mostly works for now.  For some reason, when it exports the body to an stl file, it converts everything except the first letter to lowercase, which is a problem.  But I haven't played with it enough to know if it's my problem ( probably), a python problem on an API problem.

 

Anyway thanks for all your help.

Chip

0 Likes