def open_template(file_path:str, target_component=None): """Opens an f3d file. This will use a file_path to open a Fusion Archive file. Parameters ---------- file_path : str A string that specifies where on the computer the f3d file lives. A relative path is considered relative to the archives folder within the repo. An absolute path is absolute to the root of the computer. target_component : Component, optional The component that the archive file will be inserted into. Defaults to a new Design Returns ------- Returns nothing if failed, Document of new file if target_component not selected, and Component of the new component if target_component is selected. """ fp_list = file_path.split("/") # location assumed based on relative path rules if not fp_list[0] == '': file_path = ut.abs_path("archives/"+file_path) app = adsk.core.Application.get() import_manager = app.importManager try: import_options = import_manager.createFusionArchiveImportOptions(file_path) except: raise UserWarning("Unable to find the .f3d archive at {}.".format(file_path)) if target_component: return import_manager.importToTarget(import_options, target_component) else: return import_manager.importToNewDocument(import_options)
def test_sync_folder_structure(): try: setup() json_path = "test_data/json/test_folder_creation.json" folder_dict = ut._load_json(ut.abs_path(json_path)) folder_name = ut.str_time() folder_dict_with_refs = \ aide_draw.sync_folder_structure(folder_dict, root_folder)#.dataFolders.add(folder_name)) ui.messageBox(str(folder_dict_with_refs)) print(str(folder_dict_with_refs)) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def start(hole_list, max_holes, feature_name_odd, feature_name_even, seed_name_odd, seed_name_even, fdoc): print('Beginning file download with urllib2...') url = 'http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg' urllib.request.urlretrieve(url, '/Users/ethankeller/Downloads/cat.jpg') a_ut.open_template(ut.abs_path("archives/constant_head_tank.f3z")) # split the list into odd and even cylindrical_pattern_feature.start(hole_list[::2], max_holes, feature_name_odd, seed_name_odd, fdoc) cylindrical_pattern_feature.start(hole_list[1::2], max_holes, feature_name_even, seed_name_even, fdoc)
def test_parametrize_fdoc_cube(): """ Import tests (import tests.tests) into the main aide.py module, put test_cube() within the run function, open the test_cube.f3d from the tests/templates folder, and run the aide add-in. The cube should be changed according to the parameters specified within test_cube.json in tests/json """ setup() json_path = "test_data/json/test_parametrize_fdoc_cube.json" param_dict = ut._load_json(ut.abs_path(json_path)) params_changed = aide_draw.parametrize_fdoc( param_dict, a_ut.open_template("tests/test_cube.f3d")) ui.messageBox( "The test passed if the opened cube is now sized to the parameters of: {}" .format(params_changed))
def test_abs_path_with_dot_dot(self): self.assertEqual(ut.abs_path("../tests/hi.hi"), ut.abs_path("hi.hi"))
################################ DRAW FUNCTIONS ############################### """ All the functions that change Fusion land based on JSON land! """ import adsk.core, adsk.fusion, adsk.cam, traceback import os, sys import warnings import json import aide_gui import importlib import utilities as ut import json_keys as keys try: fgen_registry = json.load(open(ut.abs_path("fgen_registry.json"))) except: print(__file__) raise FileNotFoundError( "The fgen_registry.json is missing from the root of aide_draw.") def draw_fdoc(fdoc, fdoc_dict): """Runs through the fgens defined in the fdoc_dict and passes given args to the relevant fgen """ for fgen_key in fdoc_dict: # Import the fgen that was called on. if fgen_key in fgen_registry: fgen_module = importlib.import_module(fgen_key) try:
**Note** Because this library involves the Fusion API, it is difficult to use a unit testing framework (the setup and teardown would be prohibitively extensive.) There must be some better way to test this, but not yet. """ import time import adsk.core, adsk.fusion, adsk.cam, traceback import warnings import os, sys import aide_draw, aide_gui, generate_json import utilities as ut import json import importlib sys.path.append(ut.abs_path("fgens")) import cylindrical_pattern_feature import lfom def setup(): """ responsible for doing the mundane job of setting up the module's global namespace with useful items for easy reference by the various tests. This function has the various assignments: app : the application ui : the ui fdoc : the active fusion document root_folder : the root folder of the project active_folder : the folder containing the active fdocs """
import json import utilities as ut GLOBAL_FGEN_LIST_KEY = "global_fgen_list" settings_dict = json.load(open(ut.abs_path("config.json"))) def get_global_fgen_list(): return settings_dict[GLOBAL_FGEN_LIST_KEY]
def test_aide_draw(): setup() json_path = "test_data/json/test_update_params.json" fdoc_dict = ut._load_json(ut.abs_path(json_path)) aide_draw.draw_fdoc(fdoc, fdoc_dict)
def test_parametrize_recursive_with_one_level_dict(): setup() json_path = "test_data/json/test_sync_dict_with_one_level_dict.json" folder_dict = ut._load_json(ut.abs_path(json_path)) d = generate_json.sync_dict(folder_dict, active_folder) aide_draw.parametrize_recursive(d)
def test_sync_dict_with_one_level_dict(): setup() json_path = "test_data/json/test_sync_dict_with_one_level_dict.json" folder_dict = ut._load_json(ut.abs_path(json_path)) d = generate_json.sync_dict(folder_dict, active_folder) ui.messageBox(str(d))