Scripts Not working after Update

se23umec034
Observer
Observer

Scripts Not working after Update

se23umec034
Observer
Observer

I have recently updated my Fusion 360 and I am not able to use my Scripts to export the CAD file into a URDF file. Please suggest me a way to fix it or please provide me the version Fusion 360 before the update.


Thank you

0 Likes
Reply
139 Views
4 Replies
Replies (4)

BrianEkins
Mentor
Mentor

I'm unaware of any intentional changes in this release that would have broken scripts, but sometimes changes are made to the Fusion core that the API team is unaware of and API testing didn't find. Can you post the script you're using to export to URDF?

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

Yeah sure.

#################

#Author-syuntoku14
#Description-Generate URDF file from Fusion 360

import adsk, adsk.core, adsk.fusion, traceback
import os
import sys
from .utils import utils
from .core import Link, Joint, Write

"""
# length unit is 'cm' and inertial unit is 'kg/cm^2'
# If there is no 'body' in the root component, maybe the corrdinates are wrong.
"""

# joint effort: 100
# joint velocity: 100
# supports "Revolute", "Rigid" and "Slider" joint types

# I'm not sure how prismatic joint acts if there is no limit in fusion model

def run(context😞
    ui = None
    success_msg = 'Successfully create URDF file'
    msg = success_msg

    try:
        # --------------------
        # initialize
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        title = 'Fusion2URDF'
        if not design:
            ui.messageBox('No active Fusion design', title)
            return

        root = design.rootComponent  # root component
        components = design.allComponents

        # set the names
        robot_name = root.name.split()[0]
        package_name = robot_name + '_description'
        save_dir = utils.file_dialog(ui)
        if save_dir == False:
            ui.messageBox('Fusion2URDF was canceled', title)
            return 0

        save_dir = save_dir + '/' + package_name
        try: os.mkdir(save_dir)
        except: pass

        package_dir = os.path.abspath(os.path.dirname(__file__)) + '/package/'

        # --------------------
        # set dictionaries

        # Generate joints_dict. All joints are related to root.
        joints_dict, msg = Joint.make_joints_dict(root, msg)
        if msg != success_msg:
            ui.messageBox(msg, title)
            return 0

        # Generate inertial_dict
        inertial_dict, msg = Link.make_inertial_dict(root, msg)
        if msg != success_msg:
            ui.messageBox(msg, title)
            return 0
        elif not 'base_link' in inertial_dict:
            msg = 'There is no base_link. Please set base_link and run again.'
            ui.messageBox(msg, title)
            return 0

        links_xyz_dict = {}

        # --------------------
        # Generate URDF
        Write.write_urdf(joints_dict, links_xyz_dict, inertial_dict, package_name, robot_name, save_dir)
        Write.write_materials_xacro(joints_dict, links_xyz_dict, inertial_dict, package_name, robot_name, save_dir)
        Write.write_transmissions_xacro(joints_dict, links_xyz_dict, inertial_dict, package_name, robot_name, save_dir)
        Write.write_gazebo_xacro(joints_dict, links_xyz_dict, inertial_dict, package_name, robot_name, save_dir)
        Write.write_display_launch(package_name, robot_name, save_dir)
        Write.write_gazebo_launch(package_name, robot_name, save_dir)

        # copy over package files
        utils.create_package(package_name, save_dir, package_dir)
        utils.update_setup_py(save_dir, package_name)
        utils.update_setup_cfg(save_dir, package_name)
        utils.update_package_xml(save_dir, package_name)

        # Generate STl files
        utils.copy_occs(root)
        utils.export_stl(design, save_dir, components)

        ui.messageBox(msg, title)

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


####################

 
I have also uploaded the zip which I had in the scripts folder under Fusion 360. 
Thank you for your time 
0 Likes

I thought you meant it quit working with the new release earlier this week, but this would have quit working with the September update of Fusion when the Python version was updated to Version 3.12. You're script uses a library called distutils which Python stopped delivering with 3.12. You can read the official Python documentation here. It uses a function called from distutils called copy_tree to copy files. It will need to be rewritten to use something else.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

se23umec034
Observer
Observer

Ok I will look for that
Thank you very much 😊

0 Likes