Community
Fusion Design, Validate & Document
Stuck on a workflow? Have a tricky question about a Fusion (formerly Fusion 360) feature? Share your project, tips and tricks, ask questions, and get advice from the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to save hundreds of individual parts/bodies from an assembly in STEP?

29 REPLIES 29
SOLVED
Reply
Message 1 of 30
pabonyeray
8808 Views, 29 Replies

How to save hundreds of individual parts/bodies from an assembly in STEP?

As the title said, it's possible to save as a new part, hundred of individial parts/bodies from an assembly in STEP? I got in my hand a LEGO model that contains around 600+ and I would like to extract each piece it has just to have my own library of LEGO parts. Is this function possible? If not, is there any workaround instead of saving as a new part one by one? 

 

Thank you. 

Yeray Pabon

29 REPLIES 29
Message 2 of 30
paul.clauss
in reply to: pabonyeray

Hi @pabonyeray

 

Thanks for posting! To save a large assembly as a STEP file, you can export the assembly file in STEP format. To do so, select "Export" from the File menu in Fusion 360 and then change the type to "STEP files (*stp *step)". 

 

This technique will maintain the body and component definitions in your original Fusion design, but you will lose your sketches in the STEP format file.

 

Please let me know if you have any questions!

Paul Clauss

Product Support Specialist




Message 3 of 30
pabonyeray
in reply to: paul.clauss

Hello @paul.clauss,

Thanks for replying but I don't think that's the kind of answer I'm looking for. Say, for instance that this STEP assembly has 600 pieces. I want to have in my Project Folder, each individual part from the assembly saved as a single part. That way, when I go to project, I can see the hundreds parts available. I would also go to A360 and instead of seeing a file with the assembly, I should see all the 600 pieces each as an individual file.

I hope this clears my question. 

Please, let me know if you still have doubts.

 

Yeray Pabon

Message 4 of 30
paul.clauss
in reply to: pabonyeray

Hi @pabonyeray

 

Thanks for the clarification! While Fusion does not currently include an option for exporting individual files from an assembly, there may be an API that will do this. I had a look around and found this older forum thread asking for a similar function.

 

As I am unsure of if this issue has been addressed, I have reached out to a member of our API/Scripts team. I will let you know if this function is currently available in Fusion when I hear back! If it is not, I think that an export option that could automate the deconstruction of an assembly would be a great addition to the Ideastation

Paul Clauss

Product Support Specialist




Message 5 of 30
pabonyeray
in reply to: paul.clauss

Hello @paul.clauss,

 

Thank you for the reply and your help. I hope to hear good news from the API/Scripts team soon.

 

I'll definitely consider my idea for the ideastation if there's absolutely no way to do save the parts individually in batch. 

 

Please, have a good day. 

Yeray Pabon

Message 6 of 30
ekinsb
in reply to: pabonyeray

Below is some Python script code that I believe will accomplish what you want.  If you create a new Python script and replace the default code with the code below you'll be able to use it.  Have the assembly you want to export open and run the script.  It will create a new design for each unique body in the assembly and will write them back to the same folder that the assembly is in. It uses the name of the body for the name of the design, so you'll want to go through the assembly and make sure the bodies have meaningful names.

 

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

def run(context):
    ui = None
    progDialog = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)        

        file = app.activeDocument.dataFile
        folder = file.parentFolder
        
        progDialog = ui.createProgressDialog()
        progDialog.isBackgroundTranslucent = False
        progDialog.isCancelButtonShown = False

        # Get the total number of bodies to use in the progress bar.
        bodyTotal = 0
        comp = adsk.fusion.Component.cast(None)
        for comp in des.allComponents:
            for body in comp.bRepBodies:
                bodyTotal += 1

        progDialog.show('Body Export', 'Exporting body %v of %m...', 1, bodyTotal, 0)
        bodyCount = 0
        comp = adsk.fusion.Component.cast(None)
        for comp in des.allComponents:
            for body in comp.bRepBodies:
                bodyCount += 1
                progDialog.progressValue = bodyCount

                # Create a new direct modeling design.
                newDoc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType, True)
                des = adsk.fusion.Design.cast(newDoc.products.itemByProductType('DesignProductType'))                
                des.designType = adsk.fusion.DesignTypes.DirectDesignType
                
                # Copy the body in the new design.
                newRoot = des.rootComponent
                body.copyToComponent(newRoot)

                # Save the new design, using the body name as the name of the design.
                newDoc.saveAs(body.name, folder, '', '') 
                newDoc.close(False)
            
        progDialog.hide()
    except:
        if progDialog:
            progDialog.hide()
            
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

  


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 30
pabonyeray
in reply to: ekinsb

Hi @ekinsb,

 

The script is working wonderfully! My assembly contains 738 bodies so it will take a while (around 26mins; 2 sec per iteration). I tried it with a small assembly for testing and it worked flawlessly. Thank you very much you too, @ekinsb and @paul.clauss for all the help. Hope others can see this thread whenever they need this helpful function. Kudos.

 

UPDATE:

At body #348, it gave me an error and that Fusion 360 needed to close. Fortunately, there was no lost body after closing the program so when I opened Fusion back, it copied all the bodies up to body count 348. I noticed that after each iteration, the time it needs to finish the iteration increases gradually. Maybe there's some limit. I worked this around by deleting the bodies I already copied on the assembly, and restarted the script with the remaining bodies. So far, it's working. 

 

UPDATE 2:

Managed to use the script for the remaining bodies and now I have every single body on my folder. Thank you both again for all the help. Please, have a great day. 🙂

 

Yeray Pabon

Message 8 of 30
jonquilmusic
in reply to: ekinsb

So much GRATITUDE, ekinsb!  This issue has been my bane!  Elegant work-around!

Message 9 of 30
TrippyLighting
in reply to: ekinsb

This is the second time in recent weeks that you posted one of these incredible little helpers.

 

Did you write this just now for the purpose of helping in this thread ?

 

If not and assuming there are other helpful scripts, would you have a repository of others that might be interesting ?

 

@jonquilmusic This is not a workaround. This is exactly what scripts and scripting languages are made for 😉

Peter Doering
Message 10 of 30
ekinsb
in reply to: TrippyLighting

Believe me that I don't have a hidden lair with a stash of secret utilities.  Once in a while an ongoing issue is pointed out to me or I happen to hear about it and I see that something could be done with the API so I put together a quick proof-of-concept to demonstrate the capability.  That kind of work is fun for me and it's even better if it is actually a benefit to others.  The two little utilities I  recently wrote are both for things that I wouldn't have thought of so I'm happy to hear about other issues to see if there might be something we could do with the API.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 11 of 30
schneik-adsk
in reply to: ekinsb

...could you post one more version? Instead of exporting bodies, just export components with their current name?

Kevin Schneider
Message 12 of 30

Ohh...and while you're at it, maybe rigid group the just created Components on an assembly/subassembly basis, so I don't have to answer questions about strange behavior of assemblies one the forum ;*)

Peter Doering
Message 13 of 30
ekinsb
in reply to: schneik-adsk

I just tried creating a version that would provide the option of choosing to export bodies or components and unfortunately am running into problems with the component version. I've tried to few different approaches to try and work around each problem without success.  I need to log a few bugs.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 14 of 30
finnmacmanus
in reply to: ekinsb

Hello Brian,

 

Just want to say firstly, thanks so so much for your time in writing this script. Could be incredibly helpful!

Unfortunately I am a bit new to Python, and I was wondering if anyone here could help out with a quick question - when I run the script in cmd : "Python Fusion.py" where Fusion.py is the exact script above - I get this error:

ModuleNotFoundError: No module named 'adsk'

 

If there's any way I could get your advice on that would really appreciate it. This script would be really helpful in a current project! Thanks again for your time.

Message 15 of 30
ekinsb
in reply to: finnmacmanus

Good question.  I thought there was an existing article somewhere that explained how to do this that I could point you to but I'm not finding it so I need to write one and add it to the help for an upcoming update.

 

Here's what I suggest on how to use the samples posted on the forum and the samples in the API help. This relies on whoever posted the code to post the complete program and not just a portion of it.  I typically post the entire program, which is the case here.  The samples in the online help are also complete programs.  Here's the easiest way to use them.

 

  1. Create a new Python script using the "Create" button on the "Scripts and Add-Ins" dialog.
  2. In the "Create New Script or Add-In" dialog choose "Script", "Python", and enter a name for the new script, as shown below.  Click the "Create" button to create the script.

    CreateScript.png
  3.  Select the script you just created from the list of the scripts in the dialog and click the "Edit" button.  This will open the script in the editor.  If this is the first time you've edited a script it will first download the editor.

  4.  In the editor you'll see a small amount of code for the new script that will look like the code below.  Delete all of it and replace it with the provided code.

    #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()))
  5. Now you can run the script by running the "Scripts and Add-Ins" command, choosing the script from the list, and clicking the "Run" button.

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 16 of 30
finnmacmanus
in reply to: ekinsb

Hey Brian!! Thank you SO much! I did not expect a reply so quickly, especially one as detailed... Worked like a charm man. Thank you!!

Message 17 of 30
a.ibrahim27598
in reply to: ekinsb

I was just wondering if there is a code that is similar to this but runs in Autocad, that would be very helpful.

Thanks in advance

Message 18 of 30

It works for me! I need only two small upgrades (I guess they are simple but I'm not a developer...)

 

  1. Save steps in a sub folder  named "export" (not in the same folder of the source design)
  2. Overwrite pre-existing exported steps, if they are present (now they are duplicated)

Can you address me to the right commands/syntax?

 

Thanks

Message 19 of 30
2018csb1080
in reply to: ekinsb

Hi @ekinsb,

Thank you for this script. I am facing an issue with this script.

When I load a model from my local system and run the script the below line gives the value of the file as None

file = app.activeDocument.dataFile

and when I first save this locally loaded file on the cloud and then run this script, it works fine.

 

I have to save the component files on my local system, how can I do that?

Thanks!

Message 20 of 30
2018csb1080
in reply to: ekinsb

Hi @ekinsb,

Thanks for the script. I am facing one issue while running this script.

When I load a file from my local system, the value of file below is none,

file = app.activeDocument.dataFile

But when I load the same file saved in fusion 360 cloud, the script runs successfully.

 

I want to load the file from my local machine and save the components in the same directory. How can I do that?

 

Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report