Python plugins not working / debugging fails

Python plugins not working / debugging fails

samykamkar
Collaborator Collaborator
1,858 Views
5 Replies
Message 1 of 6

Python plugins not working / debugging fails

samykamkar
Collaborator
Collaborator

Hi, I'm trying to write a plugin. I'm using Python as the docs state JS is not as fully featured and slower. Running Fusion 2.0.8156 on macOS 10.14.6 and VSCode 1.44.2

 

However, running a simple Python does nothing, and debug fails. I'm using a sample based off page 9 of the handout here: https://www.autodesk.com/autodesk-university/class/Customizing-Fusion-360-Using-Its-Programming-Inte...

 

Debugging errors with:

/Users/samy/miniconda3/bin/python: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
highlight: Could not read input file:
-
/Users/samy/miniconda3/bin/python: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
highlight: Could not read input file:
-
Traceback (most recent call last):
  File "/Users/samy/miniconda3/bin/conda", line 12, in <module>
    from conda.cli import main
ModuleNotFoundError: No module named 'conda'

 

According to https://forums.autodesk.com/t5/fusion-360-api-and-scripts/not-able-to-debug-scripts-add-ins-in-visua... I've gone ahead and downgraded (via MS VSCode) to the Python 2019.9.34911. I've also adjusted the Python path to use the one in Fusion's application path. Hitting the Play button in VSCode also errors in that scenario:

tigerblood:/Users/samy/Code/fusion/samyloop/Python$ "/Users/samy/Library/Application Support/Autodesk/webdeploy/production/9734d4c0ebc0481cf97bf881c8c462446cf2c899/Autodesk Fusion 360.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python" /Users/samy/Code/fusion/samyloop/Python/samyloop.py
Traceback (most recent call last):
  File "/Users/samy/Code/fusion/samyloop/Python/samyloop.py", line 28, in <module>
    app = adsk.core.Application.get()

 

Here's the code

app = adsk.core.Application.get()
design = app.activeProduct
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a new sketch on the xy plane.
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(xyPlane)
# Draw a circle.
circles = sketch.sketchCurves.sketchCircles
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
# Get the profile defined by the circle.
prof = sketch.profiles.item(0)
# Create an extrusion input to be able to define the input needed for an extrusion
# while specifying the profile and that a new component is to be created.
extrudes = rootComp.features.extrudeFeatures
extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
# Define that the extent is a distance extent of 5 cm.
extInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(5))
# Create the extrusion.
ext = extrudes.add(extInput)

 

Suggestions?

 

Thanks!

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

JeromeBriot
Mentor
Mentor

@samykamkar wrote:

Hitting the Play button in VSCode


Hello,

 

You can't run the script inside VS Code. You have to use the Run button  in the "Scripts And Add-ins" dialog in Fusion 360.

 

0 Likes
Message 3 of 6

samykamkar
Collaborator
Collaborator

Hi there, hitting "Run" in Fusion does nothing so I'm attempting to debug via VSCode. My understanding is that VSCode can connect to the Python debugger executed by Fusion, though seems Python also sometimes crashes when Run/Debugged from Fusion.

 

Trace:

Process:               Python [83349]
Path:                  /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.6.1 (3.6.1)
Code Type:             X86-64 (Native)
Parent Process:        Code Helper (Renderer) [83313]
Responsible:           Python [83349]
User ID:               501

Date/Time:             2020-04-18 12:45:52.792 -0700
OS Version:            Mac OS X 10.14.6 (18G2022)
Report Version:        12
Anonymous UUID:        ECD5F998-C1BE-EC0D-60A0-10CA7427E8CE


Time Awake Since Boot: 860000 seconds

System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
dyld2 mode
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x0000000101be32c2 __pthread_kill + 10
1   libsystem_pthread.dylib       	0x0000000101c36bf1 pthread_kill + 284
2   libsystem_c.dylib             	0x0000000101a2b6a6 abort + 127
3   org.python.python             	0x0000000100809551 Py_FatalError + 65
4   org.python.python             	0x000000010080b2a1 _Py_InitializeEx_Private + 1377
5   org.python.python             	0x00000001008280f0 Py_Main + 1376
6   org.python.python             	0x0000000100000dfe 0x100000000 + 3582
7   org.python.python             	0x0000000100000c34 0x100000000 + 3124

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x00007fff65ca95c0  rcx: 0x00007fff5bffd848  rdx: 0x0000000000000000
  rdi: 0x0000000000000307  rsi: 0x0000000000000006  rbp: 0x00007fff5bffd880  rsp: 0x00007fff5bffd848
   r8: 0x0000000000000000   r9: 0x0000000000000006  r10: 0x0000000000000000  r11: 0x0000000000000206
  r12: 0x0000000000000307  r13: 0x0000000000000002  r14: 0x0000000000000006  r15: 0x000000000000002d
  rip: 0x0000000101be32c2  rfl: 0x0000000000000206  cr2: 0x0000000101c362dc
  
Logical CPU:     0
Error Code:      0x02000148
Trap Number:     133


Binary Images:
       0x100000000 -        0x100000ff7 +org.python.python (3.6.1 - 3.6.1) <57997A9A-D861-6BD7-8E6E-E074D7987A38> /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
       0x100003000 -        0x100448fef  com.apple.CoreFoundation (6.9 - 1575.23) <596DBC2A-60E3-3A73-AA5F-7A1806CF3204> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x1006e3000 -        0x100908fef +org.python.python (3.6.1, [c] 2001-2017 Python Software Foundation. - 3.6.1) <9F36B3D4-C91B-D839-3D38-5B077717C316> /Library/Frameworks/Python.framework/Versions/3.6/Python
       0x100a50000 -        0x100a51ffb  libSystem.B.dylib (1252.250.1) <9AA73992-2087-34AF-803E-2D727104B989> /usr/lib/libSystem.B.dylib
       0x100a57000 -        0x1011dcfdf  libobjc.A.dylib (756.2) <7C312627-43CB-3234-9324-4DEA92D59F50> /usr/lib/libobjc.A.dylib
       0x101394000 -        0x101395ffb  libDiagnosticMessagesClient.dylib (107) <A14D0819-0970-34CD-8680-80E4D7FE8C2C> /usr/lib/libDiagnosticMessagesClient.dylib
       0x10139b000 -        0x1015fcffb  libicucore.A.dylib (62141.0.1) <A0D63918-76E9-3C1B-B255-46F4C1DA7FE8> /usr/lib/libicucore.A.dylib
       0x1016ea000 -        0x1016fcff7  libz.1.dylib (70.200.4) <B048FC1F-058F-3A08-A1FE-81D5308CB3E6> /usr/lib/libz.1.dylib
       0x101702000 -        0x101717ff7  libc++abi.dylib (400.17) <38C09CED-9090-3719-90F3-04A2749F5428> /usr/lib/libc++abi.dylib
       0x10172e000 -        0x101781ff7  libc++.1.dylib (400.9.4) <9A60A190-6C34-339F-BB3D-AACE942009A4> /usr/lib/libc++.1.dylib
       0x1017e1000 -        0x1017e5ff3  libcache.dylib (81) <1987D1E1-DB11-3291-B12A-EBD55848E02D> /usr/lib/system/libcache.dylib
       0x1017eb000 -        0x1017f5ff3  libcommonCrypto.dylib (60118.250.2) <1765BB6E-6784-3653-B16B-CB839721DC9A> /usr/lib/system/libcommonCrypto.dylib
       0x101803000 -        0x10180aff7  libcompiler_rt.dylib (63.4) <5212BA7B-B7EA-37B4-AF6E-AC4F507EDFB8> /usr/lib/system/libcompiler_rt.dylib
       0x101818000 -        0x101821ff7  libcopyfile.dylib (146.250.1) <98CD00CD-9B91-3B5C-A9DB-842638050FA8> /usr/lib/system/libcopyfile.dylib
       0x101828000 -        0x1018acfc3  libcorecrypto.dylib (602.260.2) <01464D24-570C-3B83-9D18-467769E0FCDD> /usr/lib/system/libcorecrypto.dylib
       0x1018c9000 -        0x101902ff7  libdispatch.dylib (1008.270.1) <97273678-E94C-3C8C-89F6-2E2020F4B43B> /usr/lib/system/libdispatch.dylib
       0x101933000 -        0x10195fff7  libdyld.dylib (655.1.1) <002418CC-AD11-3D10-865B-015591D24E6C> /usr/lib/system/libdyld.dylib
       0x10197e000 -        0x10197effb  libkeymgr.dylib (30) <0D0F9CA2-8D5A-3273-8723-59987B5827F2> /usr/lib/system/libkeymgr.dylib
       0x101983000 -        0x101983ff7  liblaunch.dylib (1336.261.2) <2B07E27E-D404-3E98-9D28-BCA641E5C479> /usr/lib/system/liblaunch.dylib
       0x10198a000 -        0x10198ffff  libmacho.dylib (927.0.3) <A377D608-77AB-3F6E-90F0-B4F251A5C12F> /usr/lib/system/libmacho.dylib
       0x101996000 -        0x101998ff7  libquarantine.dylib (86.270.1) <50A89DAB-7E34-3347-9AD5-68957B27EFD2> /usr/lib/system/libquarantine.dylib
       0x10199f000 -        0x1019a0ff7  libremovefile.dylib (45.200.2) <9FBEB2FF-EEBE-31BC-BCFC-C71F8D0E99B6> /usr/lib/system/libremovefile.dylib
       0x1019a6000 -        0x1019bdff3  libsystem_asl.dylib (356.200.4) <A62A7249-38B8-33FA-9875-F1852590796C> /usr/lib/system/libsystem_asl.dylib
       0x1019cb000 -        0x1019cbff7  libsystem_blocks.dylib (73) <A453E8EE-860D-3CED-B5DC-BE54E9DB4348> /usr/lib/system/libsystem_blocks.dylib
       0x1019d0000 -        0x101a57fff  libsystem_c.dylib (1272.250.1) <7EDACF78-2FA3-35B8-B051-D70475A35117> /usr/lib/system/libsystem_c.dylib
       0x101a80000 -        0x101a83ffb  libsystem_configuration.dylib (963.270.3) <2B4A836D-68A4-33E6-8D48-CD4486B03387> /usr/lib/system/libsystem_configuration.dylib
       0x101a8a000 -        0x101a8dff7  libsystem_coreservices.dylib (66) <719F75A4-74C5-3BA6-A09E-0C5A3E5889D7> /usr/lib/system/libsystem_coreservices.dylib
       0x101a93000 -        0x101a99fff  libsystem_darwin.dylib (1272.250.1) <EC9B39A5-9592-3577-8997-7DC721D20D8C> /usr/lib/system/libsystem_darwin.dylib
       0x101aa4000 -        0x101aaaffb  libsystem_dnssd.dylib (878.270.3) <97EEE658-D935-33C8-B56E-0F41EA7F6B43> /usr/lib/system/libsystem_dnssd.dylib
       0x101ab0000 -        0x101afbffb  libsystem_info.dylib (517.200.9) <D09D5AE0-2FDC-3A6D-93EC-729F931B1457> /usr/lib/system/libsystem_info.dylib
       0x101b12000 -        0x101b5dff7  libsystem_m.dylib (3158.200.7) <F19B6DB7-014F-3820-831F-389CCDA06EF6> /usr/lib/system/libsystem_m.dylib
       0x101b6c000 -        0x101b96fff  libsystem_malloc.dylib (166.270.1) <011F3AD0-8E6A-3A89-AE64-6E5F6840F30A> /usr/lib/system/libsystem_malloc.dylib
       0x101ba6000 -        0x101bb0ff7  libsystem_networkextension.dylib (767.250.2) <FF06F13A-AEFE-3A27-A073-910EF78AEA36> /usr/lib/system/libsystem_networkextension.dylib
       0x101bbc000 -        0x101bc3fff  libsystem_notify.dylib (172.200.21) <145B5CFC-CF73-33CE-BD3D-E8DDE268FFDE> /usr/lib/system/libsystem_notify.dylib
       0x101bca000 -        0x101bcdff7  libsystem_sandbox.dylib (851.270.1) <9494594B-5199-3186-82AB-5FF8BED6EE16> /usr/lib/system/libsystem_sandbox.dylib
       0x101bd4000 -        0x101bd6ff3  libsystem_secinit.dylib (30.260.2) <EF1EA47B-7B22-35E8-BD9B-F7003DCB96AE> /usr/lib/system/libsystem_secinit.dylib
       0x101bdc000 -        0x101c04ff7  libsystem_kernel.dylib (4903.278.19) <2C2536E7-EA3B-32B5-AFC6-B1139A5046FD> /usr/lib/system/libsystem_kernel.dylib
       0x101c1f000 -        0x101c28fef  libsystem_platform.dylib (177.270.1) <9D1FE5E4-EB7D-3B3F-A8D1-A96D9CF1348C> /usr/lib/system/libsystem_platform.dylib
       0x101c31000 -        0x101c3bff7  libsystem_pthread.dylib (330.250.2) <2D5C08FF-484F-3D59-9132-CE1DCB3F76D7> /usr/lib/system/libsystem_pthread.dylib
       0x101c46000 -        0x101c4dff3  libsystem_symptoms.dylib (820.267.1) <03F1C2DD-0F5A-3D9D-88F6-B26C0F94EB52> /usr/lib/system/libsystem_symptoms.dylib
       0x101c54000 -        0x101c69ff7  libsystem_trace.dylib (906.260.2) <EA74D04D-5ECA-3689-9084-48E4D32C859A> /usr/lib/system/libsystem_trace.dylib
       0x101c79000 -        0x101c7effb  libunwind.dylib (35.4) <24A97A67-F017-3CFC-B0D0-6BD0224B1336> /usr/lib/system/libunwind.dylib
       0x101c86000 -        0x101cb5fff  libxpc.dylib (1336.261.2) <7DEE2300-6D8E-3C00-9C63-E3E80D56B0C4> /usr/lib/system/libxpc.dylib
    0x7fff65c07000 -     0x7fff65c7170f  dyld (655.1.1) <B3D9DDCB-5AA7-3674-9608-16B5AA4AA494> /usr/lib/dyld

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 1202336
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=25.0M resident=0K(0%) swapped_out_or_unallocated=25.0M(100%)
Writable regions: Total=80.6M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=80.6M(100%)
 
                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                    8K        1 
MALLOC                            64.2M       12 
MALLOC guard page                   16K        4 
__DATA                            4232K       57 
__LINKEDIT                        4556K       44 
__TEXT                            20.5M       44 
__UNICODE                          564K        1 
__UNIXSTACK                       16.0M        2 
shared memory                        8K        2 
===========                     =======  ======= 
TOTAL                            109.9M      167 

Model: MacBookPro11,3, BootROM 156.0.0.0.0, 4 processors, Intel Core i7, 2.8 GHz, 16 GB, SMC 2.19f12
Graphics: kHW_IntelIrisProItem, Intel Iris Pro, spdisplays_builtin
Graphics: kHW_NVidiaGeForceGTX750MItem, NVIDIA GeForce GT 750M, spdisplays_pcie_device, 2 GB
Memory Module: BANK 0/DIMM0, 8 GB, DDR3, 1600 MHz, 0x802C, 0x31364B544631473634485A2D314736453120
Memory Module: BANK 1/DIMM0, 8 GB, DDR3, 1600 MHz, 0x802C, 0x31364B544631473634485A2D314736453120
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x134), Broadcom BCM43xx 1.0 (7.77.61.3 AirPortDriverBrcmNIC-1305.9)
Bluetooth: Version 6.0.14d3, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
Network Service: Belkin Dock (Broadcom NetXtreme Gigabit Ethernet Controller), Ethernet, en4
PCI Card: pci1b73,1100, USB eXtensible Host Controller, Thunderbolt@196,0,0
PCI Card: pci11c1,5901, IEEE 1394 Open HCI, Thunderbolt@195,0,0
PCI Card: Broadcom 57762-A1, Ethernet Controller, Thunderbolt@194,0,0
Serial ATA Device: APPLE SSD SM1024F, 1 TB
USB Device: USB 3.0 Bus
USB Device: Apple Internal Keyboard / Trackpad
USB Device: BRCM20702 Hub
USB Device: Bluetooth USB Host Controller
USB Device: USB 3.0 Bus
USB Device: USB3.0 Hub
USB Device: USB3.0 Hub
USB Device: USB3.0 Hub
USB Device: USB2.0 Hub
USB Device: USB2.0 Hub
USB Device: USB2.0 Hub
USB Device: RTL2838UHIDIR
USB Device: YARD Stick One
USB Device: USB PnP Sound Device
USB Device: Duet USB
USB Device: USB2.0 Hub
Thunderbolt Bus: MacBook Pro, Apple Inc., 17.1
Thunderbolt Device: Express Dock, Belkin International, Inc., 1, 26.1
0 Likes
Message 4 of 6

JeromeBriot
Mentor
Mentor
Accepted solution

The script template is:

 

#Author-
#Description-

import adsk.core, adsk.fusion, adsk.cam, traceback

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

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

 

You have to place the code inside the run function:

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        
        app = adsk.core.Application.get()
        design = app.activeProduct
        # Get the root component of the active design.
        rootComp = design.rootComponent
        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)
        # Draw a circle.
        circles = sketch.sketchCurves.sketchCircles
        circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 2)
        # Get the profile defined by the circle.
        prof = sketch.profiles.item(0)
        # Create an extrusion input to be able to define the input needed for an extrusion
        # while specifying the profile and that a new component is to be created.
        extrudes = rootComp.features.extrudeFeatures
        extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)
        # Define that the extent is a distance extent of 5 cm.
        extInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(5))
        # Create the extrusion.
        ext = extrudes.add(extInput)

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

samykamkar
Collaborator
Collaborator

Ahh awesome, thanks @JeromeBriot!

0 Likes
Message 6 of 6

JeromeBriot
Mentor
Mentor

@samykamkar wrote:

I'm using Python as the docs state JS is not as fully featured and slower.


Writing scripts in Javascript is now deprecated in Fusion 360. You can only write codes in C++ or in Python.

 

fusion-360-python-cpp.png

 

Only Palettes objects can use Javascript with HTML and CSS.

 

A good place to start with the API: Fusion 360 API User's Manual

0 Likes