Import CAM from original when generating parametric models

Import CAM from original when generating parametric models

blue983
Enthusiast Enthusiast
371 Views
0 Replies
Message 1 of 1

Import CAM from original when generating parametric models

blue983
Enthusiast
Enthusiast

Hey there,

 

i wrote a script, that generates parametric models with the values coming from an csv-file. It uses a template-model, changes the parameters and saves it as a new model. This part is working fine.

 

Unfortunately the CAM-Setup from the template is not brought to the new model-file.

 

  1. Is there a possibility to bring the CAM-Setup from the template to the new saved file using the API?
  2. Is it possible, to activate/deactivate operations in the septup (assuming, question 1 is solved) using the API
  3. Is it possible, to change options of operations using the API?

The Script I use:

import adsk.core, adsk.fusion, traceback, os, sys

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

        importManager = app.importManager
        rootComp = app.activeProduct.rootComponent
        
        filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'X:\\ALLPARAMETRIC.f3d')
        
        importOptions = importManager.createFusionArchiveImportOptions(filename)
        importManager.importToTarget(importOptions, rootComp)
        
        pulleyOccurrance = rootComp.occurrences.item(rootComp.occurrences.count-1)
        
        parameters = pulleyOccurrance.component.parentDesign.allParameters
        doc = app.activeDocument


        # The project and folder is hard coded.
        projectName = 'alpha'
        folderName = 'Autogenerated'
        
        proj = None
        for project in app.data.dataProjects:
            if project.name == projectName:
                proj = project
                break

        targetFolder = None            
        if proj:
            if folderName == '':
                targetFolder = project.rootFolder
            else:
                for folder in project.rootFolder.dataFolders:
                    if folder.name == folderName:
                        targetFolder = folder
                        break

            if not targetFolder:
                return
        else:
            return

        # Read the csv file.
        file = open('X://construct.csv')
        for line in file:
            # Get the values from the csv file.
            pieces = line.split(',')
            inlfn = pieces[0]
            inoid = pieces[1]
            inrid = pieces[2]
            inlength = pieces[3]
            inhright = pieces[4]
            inhleft = pieces[5]
            ingradient = (180-int(pieces[6]))
            inedges = pieces[7]
            inpodest = pieces[8]
            
            # Set the parameters.

            lengthParam = parameters.itemByName('length')
            lengthParam.expression = str(inlength)
            
            hrightParam = parameters.itemByName('hright')
            hrightParam.expression = str(inhright)

            hleftParam = parameters.itemByName('hleft')
            hleftParam.expression = str(inhleft)

            gradientParam = parameters.itemByName('gradient')
            gradientParam.expression = str(ingradient)
            
            edgesParam = parameters.itemByName('edges')
            edgesParam.expression = str(inedges)

            podestParam = parameters.itemByName('podest')
            podestParam.expression = str(inpodest)

      
            
            adsk.doEvents()
            doc.saveAs(str(inlfn)+'_'+str(inoid)+'_'+str(inrid), targetFolder, '', '')
            adsk.doEvents()
        ui.messageBox('Finished')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
372 Views
0 Replies
Replies (0)