def export_folder(root_folder, output_folder, file_types, write_version, name_option, folder_preserve): ao = AppObjects() for folder in root_folder.dataFolders: if folder_preserve: new_folder = os.path.join(output_folder, folder.name, "") if not os.path.exists(new_folder): os.makedirs(new_folder) else: new_folder = output_folder export_folder(folder, new_folder, file_types, write_version, name_option, folder_preserve) for file in root_folder.dataFiles: if file.fileExtension == "f3d": open_doc(file) try: output_name = get_name(write_version, name_option) export_active_doc(output_folder, file_types, output_name) # TODO add handling except ValueError as e: ao.ui.messageBox(str(e)) except AttributeError as e: ao.ui.messageBox(str(e)) break
def update_data(self): ao = AppObjects() self.hub = ao.app.data.activeHub self.data_file = ao.document.dataFile # Existing Properties self.hub_name = self.hub.name self.project_name = self.data_file.parentProject.name self.folder_name = self.data_file.parentFolder.name self.folder_id = self.data_file.parentFolder.id self.lineage_urn = self.data_file.id if LATEST_DEV: self.team_url = 'staging.autodesk360beta' self.version_urn = self.data_file.versionId # TODO Move after production self.hub_id = self.hub.id self.hub_id_decoded = b64_url_safe_decode(self.hub_id) self.project_id = self.data_file.parentProject.id self.project_id_decoded = b64_url_safe_decode(self.project_id) else: self.team_url = 'autodesk360' core_id = self.lineage_urn.split(':')[-1] self.version_urn = f"urn:adsk.wipprod:fs.file:vf.{core_id}?version={self.data_file.versionNumber}" self.b64_lineage_urn = b64_url_safe_encode(self.lineage_urn) self.b64_version_urn = b64_url_safe_encode(self.version_urn)
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() # Create a default value using a string default_value = adsk.core.ValueInput.createByString('1.0 in') # Get teh user's current units default_units = ao.units_manager.defaultLengthUnits # Create a value input. This will respect units and user defined equation input. inputs.addValueInput('value_input_id', '*Sample* Value Input', default_units, default_value) # Other Input types inputs.addBoolValueInput('bool_input_id', '*Sample* Check Box', True) inputs.addStringValueInput('string_input_id', '*Sample* String Value', 'Some Default Value') inputs.addSelectionInput('selection_input_id', '*Sample* Selection', 'Select Something') # Read Only Text Box inputs.addTextBoxCommandInput('text_box_input_id', 'Selection Type: ', 'Nothing Selected', 1, True) # Create a Drop Down drop_down_input = inputs.addDropDownCommandInput('drop_down_input_id', '*Sample* Drop Down', adsk.core.DropDownStyles.TextListDropDownStyle) drop_down_items = drop_down_input.listItems drop_down_items.add('List_Item_1', True, '') drop_down_items.add('List_Item_2', False, '')
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values): global SKIPPED_FILES ao = AppObjects() output_folder = input_values['output_folder'] folder_preserve = input_values['folder_preserve_id'] # TODO broken????? file_types = inputs.itemById('file_types_input').listItems write_version = input_values['write_version'] name_option = input_values['name_option_id'] root_folder = ao.app.data.activeProject.rootFolder # Make sure we have a folder not a file if not output_folder.endswith(os.path.sep): output_folder += os.path.sep # Create the base folder for this output if doesn't exist if not os.path.exists(output_folder): os.makedirs(output_folder) export_folder(root_folder, output_folder, file_types, write_version, name_option, folder_preserve) if len(SKIPPED_FILES) > 0: ao.ui.messageBox( "The following files contained external references and could not be exported as f3d's: {}" .format(SKIPPED_FILES)) close_command = ao.ui.commandDefinitions.itemById( self.fusion_app.command_id_from_name(config.close_cmd_id)) close_command.execute()
def close_doc(doc): try: doc.close(False) except: ao = AppObjects() ao.ui.messageBox('close_doc Failed:\n{}'.format( traceback.format_exc()))
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values): # Get the values from the user input the_value = input_values['value_input_id'] the_boolean = input_values['bool_input_id'] the_string = input_values['string_input_id'] all_selections = input_values['selection_input_id'] the_drop_down = input_values['drop_down_input_id'] # Selections are returned as a list so lets get the first one and its name the_first_selection = all_selections[0] the_selection_type = the_first_selection.objectType # Get a reference to all relevant application objects in a dictionary ao = AppObjects() converted_value = ao.units_manager.formatInternalValue(the_value, 'in', True) ao.ui.messageBox('The value, in internal units, you entered was: {} \n'.format(the_value) + 'The value, in inches, you entered was: {} \n'.format(converted_value) + 'The boolean value checked was: {} \n'.format(the_boolean) + 'The string you typed was: {} \n'.format(the_string) + 'The type of the first object you selected is: {} \n'.format(the_selection_type) + 'The drop down item you selected is: {}'.format(the_drop_down) )
def get_name2(data_file, write_version, option): ao = AppObjects() output_name = '' if option == 'Document Name': doc_name = data_file.name + " v" + str(data_file.versionNumber) #ao.ui.messageBox('get_name2:data_file\n{}'.format(doc_name) ) if (doc_name.find('/') != -1): ao.ui.messageBox( 'Error: Filename has an illegal "/". You must rename this model:\n{}' .format(doc_name)) # TODO: Exit AddIn gracefully. if not write_version: doc_name = doc_name[:doc_name.rfind(' v')] output_name = doc_name elif option == 'Description': output_name = ao.root_comp.description elif option == 'Part Number': output_name = ao.root_comp.partNumber else: raise ValueError('Something strange happened') return output_name
def on_execute(self, command, inputs, args, input_values): ao = AppObjects() document = ao.document if document.isSaved: document.close(False) close_command = ao.ui.commandDefinitions.itemById(self.cmd_id) close_command.execute()
def web_request_event_received(self, event_args, file, fusion_id, occurrence_or_document, private_info, properties): ao = AppObjects() # **********Do your stuff here************** ao.ui.messageBox("You just Opened: {} ".format(file)) # Could close the file here also self.conn.send(['finished opening', file])
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values): global FILES_WITH_EXTERNAL_REFS ao = AppObjects() project_folder = ao.app.data.activeProject.rootFolder output_folder = input_values['output_folder'] folder_preserve = input_values['folder_preserve_id'] file_types = inputs.itemById( 'file_types_input').listItems # TODO broken????? write_version = input_values['write_version'] export_all_versions = input_values['export_all_versions'] name_option = input_values['name_option_id'] skip_duplicates = input_values['skip_duplicates'] # Make sure we have a folder not a file if not output_folder.endswith(os.path.sep): output_folder += os.path.sep # Create the base folder for this output if doesn't exist if not os.path.exists(output_folder): os.makedirs(output_folder) export_folder(project_folder, output_folder, file_types, write_version, export_all_versions, skip_duplicates, name_option, folder_preserve) # Report Final Results log_file_name = output_folder + 'export_log.txt' f = open(log_file_name, "a") f.write("- - - - - - Exporting Log Session - - - - - - \n") if len(FAILED_FILES) > 0: f.write("The following files Failed Export:\n") for f_n in FAILED_FILES: f.write(" {}\n".format(f_n)) if len(FILES_WITH_EXTERNAL_REFS) > 0: f.write( "The following files contained external references, be careful with these files and their references:\n" ) for f_n in FILES_WITH_EXTERNAL_REFS: f.write(" {}\n".format(f_n)) if len(SKIPPED_DUP_FILES) > 0: f.write( "The following files were skipped because they were duplicates:\n" ) for f_n in SKIPPED_DUP_FILES: f.write(" {}\n".format(f_n)) f.close() ao.ui.messageBox( "Finished Exporting:\n Failed files:{fails}\n SkippeddDuplicate Files:{dups}\n Files with External References:{refs}\nSee export_log.txt" .format(fails=len(FAILED_FILES), dups=len(SKIPPED_DUP_FILES), refs=len(FILES_WITH_EXTERNAL_REFS)))
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() hub_id = ao.app.data.activeHub.id url = f"/project/v1/hubs/{hub_id}/projects" r_json = get_forge_data(url) if r_json: i = 0 for project in r_json['data']: project_name = project['attributes']['name'] tb = inputs.addTextBoxCommandInput(f'tb_input_{i}', project_name, project_name, 1, True) tb.isFullWidth = True
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): global FILES_WITH_EXTERNAL_REFS FILES_WITH_EXTERNAL_REFS.clear() FAILED_FILES.clear() SKIPPED_DUP_FILES.clear() ao = AppObjects() default_dir = apper.get_default_dir( config.app_name) + ao.app.data.activeProject.rootFolder.name inputs.addStringValueInput('output_folder', 'Output Folder:', default_dir) drop_input_list = inputs.addDropDownCommandInput( 'file_types_input', 'Export Types', adsk.core.DropDownStyles.CheckBoxDropDownStyle) drop_input_list = drop_input_list.listItems drop_input_list.add('IGES', False) drop_input_list.add('STEP', False) drop_input_list.add('SAT', False) drop_input_list.add('SMT', False) drop_input_list.add('F3D', True) drop_input_list.add('STL', False) name_option_group = inputs.addDropDownCommandInput( 'name_option_id', 'File Name Option', adsk.core.DropDownStyles.TextListDropDownStyle) name_option_group.listItems.add('Document Name', True) name_option_group.listItems.add('Description', False) name_option_group.listItems.add('Part Number', False) name_option_group.isVisible = True preserve_input = inputs.addBoolValueInput( 'folder_preserve_id', 'Preserve folder structure?', True, '', True) preserve_input.isVisible = True version_input = inputs.addBoolValueInput( 'write_version', 'Write versions to output file names?', True, '', True) version_input.isVisible = True all_versions_input = inputs.addBoolValueInput('export_all_versions', 'Export all versions?', True, '', True) all_versions_input.isVisible = True skip_duplicates_input = inputs.addBoolValueInput( 'skip_duplicates', 'Skip duplicates?', True, '', True) skip_duplicates_input.isVisible = True update_name_inputs(inputs, 'Document Name')
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() # Create a default value using a string default_value = adsk.core.ValueInput.createByString('1.0 in') # Get teh user's current units default_units = ao.units_manager.defaultLengthUnits selectionInput = inputs.addSelectionInput('selection_input_id', 'Select Parametric Part', 'Component to select') selectionInput.setSelectionLimits(1, 1) textBox = inputs.addTextBoxCommandInput('textBox', 'JSON String', '', 5, True)
def exportAppearancePropertiesToFile(): ao = AppObjects() filePath = '{0}{1}_{2}.{3}'.format('C:/temp/', "mats", int(time.time()), "csv") filePathExp = '{0}{1}_{2}.{3}'.format('C:/temp/', "exp", int(time.time()), "csv") # todo: report fusion crashes if request values for float property with one value only with open(filePath, "wt") as f: # for occur in ao.root_comp.occurrences: # recursion(f, occur) with open(filePathExp, "wt") as e: e.write("ID,NAME,METAL,COLOR,ROUGHNESS\n") for lib in ao.app.materialLibraries: for appear in lib.appearances: f.write("ID,NAME,HAS_TEXTURE\n") f.write(appear.id + ",") f.write(appear.name + ",") f.write(str(appear.hasTexture) + ",\n\n") f.write("ID,NAME,TYPE,VALUE\n") e.write(appear.id + ",") e.write(appear.name + ",") writeAppearanceProps(e, appear.appearanceProperties) for prop in appear.appearanceProperties: if prop.name == "URN" or prop.name == "IMAGE": continue f.write(prop.id + ",") f.write(prop.name + ",") f.write(prop.objectType.split("adsk::core::")[1] + ",") if prop.objectType == "adsk::core::ColorProperty": f.write(" ".join(["(" + str(value.red) + " " + str(value.green) + " " + str(value.blue) + " " + str(value.opacity) + ")" for value in prop.values]) + ",") elif prop.objectType == "adsk::core::BooleanProperty" or prop.objectType == "adsk::core::StringProperty": f.write(str(prop.value) + ",") elif prop.objectType == "adsk::core::FloatProperty" or prop.objectType == "adsk::core::IntegerProperty": if prop.hasMultipleValues: f.write(" ".join([value for value in prop.values]) + ",") else: f.write(str(prop.value) + ",") elif prop.objectType == "adsk::core::ChoiceProperty": (returnValue, names, choices) = prop.getChoices() f.write(prop.value+" ("+" ".join([name+":"+choice for (name, choice) in zip(names, choices)])+")") f.write("\n") f.write("\n\n") e.write("\n")
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() folder_id = ao.app.data.activeProject.rootFolder.id project_id = ao.app.data.activeProject.id url = f"/data/v1/projects/{project_id}/folders/{folder_id}/contents" r_json = get_forge_data(url) i = 0 for item in r_json['data']: name = item['attributes'].get('name', None) if name is None: name = item['attributes'].get('displayName', "No Name") tb = inputs.addTextBoxCommandInput(f'tb_input_{i}', "Name", name, 1, True)
def open_doc(data_file): # TODO: This often fails due to Runtime Error 3. Error Downloading. # However, when ran again, it works. This function should be updated to retry at least once. app = adsk.core.Application.get() try: document = app.documents.open(data_file, True) if document is not None: document.activate() return document except: FAILED_FILES.append(data_file.name) ao = AppObjects() ao.ui.messageBox('open_doc failed for file:{name}\n{tb}'.format( name=data_file.name, tb=traceback.format_exc()))
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values): try: ao = AppObjects() rootComponent = ao.design.rootComponent designName = rootComponent.name activeDocument = ao.app.activeDocument projectName = activeDocument.dataFile.parentProject.name saveChanges = False logger.info( "--------------------------------------------------------------------------------" ) logger.info("Starting processing of %s - %s", projectName, designName) logger.info( "--------------------------------------------------------------------------------" ) logger.info("Making Temp Directory") if not os.path.exists(exportDirectory): os.mkdir(exportDirectory) path = exportDirectory logger.info("Deleting files in the Temp Directory if any") folder = exportDirectory for filename in os.listdir(folder): file_path = os.path.join(folder, filename) try: if os.path.isfile(file_path) or os.path.islink(file_path): os.unlink(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path) except Exception as e: print('Failed to delete %s. Reason: %s' % (file_path, e)) # get list of bodies for the exports exportObjects = [] # get list of occurrences and bodies logger.debug("getting list of export objects") exportObjects = getExportObjects(rootComponent, 'bodies') exportStlAsOneFilePerBodyInOccurrence(exportObjects, projectName, designName, ao) except: logger.error(traceback.format_exc())
def update_urls(self, inputs): ao = AppObjects() view_url = f"https://{self.hub_id_name}.{self.team_url}.com/g/data/{self.b64_lineage_urn}" thumbnail_url = f"https://developer.api.autodesk.com/modelderivative/v2/designdata/" \ f"{self.b64_lineage_urn}/thumbnail" open_url = f"fusion360://userEmail={ao.app.currentUser.email}&" \ f"lineageUrn={self.lineage_urn}&" \ f"hubUrl=https://{self.hub_id_name}.{self.team_url}.com&" \ f"documentName={self.data_file.name}" inputs.itemById('view_url').formattedText = url_of(view_url) inputs.itemById('thumbnail_url').formattedText = url_of(thumbnail_url) inputs.itemById('open_url').formattedText = url_of(open_url)
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() if not ao.document.isSaved: ao.ui.messageBox("You must save teh active document first") command.doExecute(True) version_id = ao.document.dataFile.versionId project_id = ao.app.data.activeProject.id url = f"/data/v1/projects/{project_id}/versions/{version_id}" r_json = get_forge_data(url) name = r_json['data']['attributes'].get('displayName', "No Name") tb1 = inputs.addTextBoxCommandInput(f'tb_input_{i}', "Name", name, 1, True) name = r_json['data'].get('type', "No Type") tb2 = inputs.addTextBoxCommandInput(f'tb_input_{i}', "Type", name, 1, True)
def export_active_doc(folder, file_types, output_name, skip_dups): global FILES_WITH_EXTERNAL_REFS ao = AppObjects() export_mgr = ao.export_manager export_functions = [ export_mgr.createIGESExportOptions, export_mgr.createSTEPExportOptions, export_mgr.createSATExportOptions, export_mgr.createSMTExportOptions, export_mgr.createFusionArchiveExportOptions, export_mgr.createSTLExportOptions ] export_extensions = ['.igs', '.step', '.sat', '.smt', '.f3d', '.stl'] for i in range(file_types.count - 2): if file_types.item(i).isSelected: export_name = folder + output_name + export_extensions[i] export_name, dup = dup_check(export_name) if not (dup and skip_dups): export_options = export_functions[i](export_name) export_mgr.execute(export_options) if file_types.item(file_types.count - 2).isSelected: if ao.document.allDocumentReferences.count > 0: FILES_WITH_EXTERNAL_REFS.append(ao.document.name) # Why? export_name = folder + output_name + '.f3d' export_name, dup = dup_check(export_name) if not (dup and skip_dups): export_options = export_mgr.createFusionArchiveExportOptions( export_name) export_mgr.execute(export_options) if file_types.item(file_types.count - 1).isSelected: stl_export_name = folder + output_name + '.stl' stl_export_name, dup = dup_check(stl_export_name) if not (dup and skip_dups): stl_options = export_mgr.createSTLExportOptions( ao.design.rootComponent, stl_export_name) export_mgr.execute(stl_options)
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() designName = "" projectName = "" try: designName = ao.design.rootComponent.name projectName = ao.app.activeDocument.dataFile.parentProject.name logger.info( "--------------------------------------------------------------------------------" ) logger.info("Initializing processing of %s - %s", projectName, designName) logger.info( "--------------------------------------------------------------------------------" ) except AttributeError as err: logger.error( "--------------------------------------------------------------------------------" ) logger.error("Error: No active document found.") logger.error( "--------------------------------------------------------------------------------" ) if ao.ui: ao.ui.messageBox("Error: No active document found.") except: logger.error( "--------------------------------------------------------------------------------" ) logger.error("Error:") logger.error( "--------------------------------------------------------------------------------" ) logger.error(traceback.format_exc())
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values): # Get a reference to all relevant application objects in a dictionary ao = AppObjects() # selectionInput = input_values['selection_input_id'] inputString = input_values['textBox'] selectionInput = inputs.itemById('selection_input_id') if inputString == '': if selectionInput.selection( 0).entity.objectType == 'adsk::fusion::Occurrence': entity = selectionInput.selection(0).entity.component else: entity = selectionInput.selection(0).entity if entity.attributes.itemByName("vex_cad", "part_data") is not None: inputString = entity.attributes.itemByName( "vex_cad", "part_data").value attributesDict = {"uuid": ''} try: attributesDict.update(json.loads(inputString)) except: ao.ui.messageBox(inputString + '\n\nis not a valid JSON string.', 'Invalid entry', adsk.core.MessageBoxButtonTypes.OKButtonType, adsk.core.MessageBoxIconTypes.CriticalIconType) return attributesDict["uuid"] = str(uuid.uuid4()) attributesJson = json.dumps(attributesDict) entity = vex_cad.getCompIfOccurrence( selectionInput.selection(0).entity) for index in range(entity.attributes.count): entity.attributes.item(index).deleteMe entity.attributes.add("vex_cad", "part_data", attributesJson) appliedAttributes = entity.attributes.itemByName( "vex_cad", "part_data").value ao.ui.messageBox(appliedAttributes + '\n\nWas applied successfully.')
def on_execute(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, args, input_values): global SKIPPED_FILES ao = AppObjects() output_folder = input_values['output_folder'] folder_preserve = input_values['folder_preserve_id'] # TODO broken????? file_types = inputs.itemById('file_types_input').listItems write_version = input_values['write_version'] name_option = input_values['name_option_id'] root_folder = ao.app.data.activeProject.rootFolder export_folder(root_folder, output_folder, file_types, write_version, name_option, folder_preserve) if len(SKIPPED_FILES) > 0: ao.ui.messageBox( "The following files contained external references and could not be exported as f3d's: {}".format( SKIPPED_FILES ) )
def writeAppearanceProps(e, props): type = props.itemById("interior_model").value if type == 0: e.write("False,") writeColor(e, props.itemById("opaque_albedo")) writeNum(e, props.itemById("surface_roughness")) # writeNum(e, appear.itemById("opaque_f0")) if props.itemById("opaque_emission"): writeNum(e, props.itemById("opaque_luminance")) writeColor(e, props.itemById("opaque_luminance_modifier")) #todo opaque translucency?? elif type == 1: e.write("True,") writeColor(e, props.itemById("metal_f0")) writeNum(e, props.itemById("surface_roughness")) elif type == 2: e.write("False,") writeColor(e, props.itemById("layered_diffuse")) writeNum(e, props.itemById("surface_roughness")) # writeColor(e, appear.itemById("layered_f0")) elif type == 3: e.write("False,") writeColor(e, props.itemById("transparent_color")) writeNum(e, props.itemById("surface_roughness")) writeNum(e, props.itemById("transparent_distance")) # translate to alpha? # writeNum(e, appear.itemById("transparent_ior")) elif type == 4: pass #todo ?? elif type == 5: e.write("False,") writeColor(e, props.itemById("glazing_transmission_color")) writeNum(e, props.itemById("surface_roughness")) elif type is None: return else: AppObjects().ui.messageBox(str(type)) return
def get_name(write_version, option): ao = AppObjects() output_name = '' if option == 'Document Name': doc_name = ao.app.activeDocument.name if not write_version: doc_name = doc_name[:doc_name.rfind(' v')] output_name = doc_name elif option == 'Description': output_name = ao.root_comp.description elif option == 'Part Number': output_name = ao.root_comp.partNumber else: raise ValueError('Something strange happened') return output_name
def on_create(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs): ao = AppObjects() if not ao.document.isSaved: ao.ui.messageBox("You must save teh active document first") command.doExecute(True) command.setDialogInitialSize(800, 800) inputs.addTextBoxCommandInput('hub_id_name', 'Your Hub ID: ', self.hub_id_name, 1, False) info_box = inputs.addTextBoxCommandInput('hub_id_info_id', 'Hub Info', 'Note: this is the first part of the url you see in Fusion team\n' 'Like: https://YOUR_HUB_ID.autodesk360.com/g/projects/.../', 3, True) info_box.isFullWidth = True inputs.addTextBoxCommandInput('hub_name', 'Hub Name: ', self.hub_name, 1, True) inputs.addTextBoxCommandInput('hub_id', 'Hub ID: ', self.hub_id, 1, True) inputs.addTextBoxCommandInput('hub_id_decoded', 'Hub ID Decoded: ', self.hub_id_decoded, 1, True) inputs.addTextBoxCommandInput('project_name', 'Project Name: ', self.project_name, 1, True) inputs.addTextBoxCommandInput('project_id', 'Project ID: ', self.project_id, 1, True) inputs.addTextBoxCommandInput('project_id_decoded', 'Project ID Decoded: ', self.project_id_decoded, 1, True) inputs.addTextBoxCommandInput('folder_name', 'Folder Name: ', self.folder_name, 1, True) inputs.addTextBoxCommandInput('folder_id', 'Folder ID: ', self.folder_name, 1, True) inputs.addTextBoxCommandInput('lineage_urn', 'Lineage URN: ', self.lineage_urn, 1, True) inputs.addTextBoxCommandInput('b64_lineage_urn', 'base64 Lineage URN: ', self.b64_lineage_urn, 1, True) inputs.addTextBoxCommandInput('version_urn', 'Version URN: ', self.version_urn, 1, True) inputs.addTextBoxCommandInput('b64_version_urn', 'base64 Version URN: ', self.b64_version_urn, 1, True) inputs.addTextBoxCommandInput('view_url', 'View Url: ', '', 3, True) inputs.addTextBoxCommandInput('thumbnail_url', 'Thumbnail Url: ', '', 3, True) inputs.addTextBoxCommandInput('open_url', 'Open Url: ', '', 3, True) self.update_data() self.update_data_inputs(inputs) self.update_urls(inputs)
def on_input_changed(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, changed_input, input_values): ao = AppObjects() SelectionInput = input_values['selection_input_id'] angle = inputs.itemById('angle_id') if len(SelectionInput) == 2: point = SelectionInput[1] # ao.ui.messageBox(str(point)) # ao.ui.messageBox(str(point.assemblyContext.name)) xDirection = point.parentSketch.xDirection yDirection = point.parentSketch.yDirection angle.setManipulator(point.worldGeometry, xDirection, yDirection) angle.isVisible = True if changed_input == angle: for multiplier in range(8, -1, -1): if angle.value > math.pi * multiplier / 4 - math.pi / 8: angle.value = math.pi * multiplier / 4 break else: angle.isVisible = False pass
def get_forge_data(url): ao = AppObjects() access_token = config.access_token headers = { 'Authorization': f"Bearer {access_token}", 'Content-Type': 'application/vnd.api+json' } r = requests.get(FORGE_BASE + url, headers=headers) r_json = r.json() if r.status_code == 200: return r_json # TODO deal with expired token # elif r.status_code == EXPIRED: # refresh and recall method else: ao.ui.messageBox(str(r.status_code)) ao.ui.messageBox(str(r_json)) return False
def on_destroy(self, command: adsk.core.Command, inputs: adsk.core.CommandInputs, reason, input_values): try: ao = AppObjects() designName = ao.design.rootComponent.name projectName = ao.app.activeDocument.dataFile.parentProject.name logger.info( "--------------------------------------------------------------------------------" ) logger.info("Finished processing of %s - %s", projectName, designName) logger.info( "--------------------------------------------------------------------------------" ) except: logger.info( "--------------------------------------------------------------------------------" ) logger.info("Finished") logger.info( "--------------------------------------------------------------------------------" )
def __init__(self, name: str, options: dict): super().__init__(name, options) ao = AppObjects() self.hub = ao.app.data.activeHub self.data_file = ao.document.dataFile self.lineage_urn = '' self.version_urn = '' self.b64_lineage_urn = '' self.b64_version_urn = '' self.hub_id_name = "YOUR_HUB_ID" self.hub_id = "Not Implemented" self.hub_id_decoded = "Not Implemented" self.hub_name = '' self.project_id = "Not Implemented" self.project_id_decoded = "Not Implemented" self.project_name = '' self.folder_id = '' self.folder_name = '' self.team_url = ''