<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Clear current design in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/8437139#M18070</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/116141"&gt;@ekinsb&lt;/a&gt;&amp;nbsp;That's a fabulous script, I added it as a class to my libraries so that I can call it whenever I want whilst debugging!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        class CloseAllDocuments:
            
            def __init__(self, save):
                self.ui = None 
                try:
                    self.save = save
                    self.app = adsk.core.Application.get()
                    self.ui = app.userInterface
                    if self.save:
                        self.ui.messageBox('Saving and Closing all existing documents ...')
                    else:
                        self.ui.messageBox('Closing all existing documents without saving ...')
                    self.docs = []
                    for doc in self.app.documents:
                        self.docs.append(doc)
                    # Close all open documents, without saving them.
                    for doc in self.docs:
                        doc.close(self.save)
                except:
                    if ui:
                        self.ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))   &lt;/PRE&gt;
&lt;P&gt;So when debugging I just start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CloseAllDocuments(False)&lt;/PRE&gt;
&lt;P&gt;and then follow up with what I'm working on!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Nov 2018 19:09:38 GMT</pubDate>
    <dc:creator>CaptainXamtastic</dc:creator>
    <dc:date>2018-11-30T19:09:38Z</dc:date>
    <item>
      <title>Clear current design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/7113511#M18067</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;during programming, you have to run the script multiple times for debugging.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to run the script in a clean design, I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)&lt;/PRE&gt;&lt;P&gt;But this leads to the fact that during debugging creates a lot of new designs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to clear current design (delete all existing components etc)? This would help to solve this problem.&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2017 14:14:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/7113511#M18067</guid>
      <dc:creator>copypastestd</dc:creator>
      <dc:date>2017-05-28T14:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Clear current design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/7115044#M18068</link>
      <description>&lt;P&gt;Personally, I prefer to keep this code out of my program and I just manually close the previous design, create a new design and start debugging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you could add code that will close all open documents. &amp;nbsp;The function below will do this and because Fusion requires that there is always at least one open document it will automatically create a new one. It closes the documents without saving any changes so you have to be careful using it because you will lose any modeling work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def closeAll():
    ui = None 
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        # Build a list of the open documents.
        docs = []
        for doc in app.documents:
            docs.append(doc)
        
        # Close all open documents, without saving them.
        for doc in docs:
            doc.close(False)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 15:18:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/7115044#M18068</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2017-05-29T15:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Clear current design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/7132627#M18069</link>
      <description>&lt;P&gt;Brain, tnx for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 17:52:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/7132627#M18069</guid>
      <dc:creator>copypastestd</dc:creator>
      <dc:date>2017-06-06T17:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Clear current design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/8437139#M18070</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/116141"&gt;@ekinsb&lt;/a&gt;&amp;nbsp;That's a fabulous script, I added it as a class to my libraries so that I can call it whenever I want whilst debugging!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        class CloseAllDocuments:
            
            def __init__(self, save):
                self.ui = None 
                try:
                    self.save = save
                    self.app = adsk.core.Application.get()
                    self.ui = app.userInterface
                    if self.save:
                        self.ui.messageBox('Saving and Closing all existing documents ...')
                    else:
                        self.ui.messageBox('Closing all existing documents without saving ...')
                    self.docs = []
                    for doc in self.app.documents:
                        self.docs.append(doc)
                    # Close all open documents, without saving them.
                    for doc in self.docs:
                        doc.close(self.save)
                except:
                    if ui:
                        self.ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))   &lt;/PRE&gt;
&lt;P&gt;So when debugging I just start with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CloseAllDocuments(False)&lt;/PRE&gt;
&lt;P&gt;and then follow up with what I'm working on!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 19:09:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/8437139#M18070</guid>
      <dc:creator>CaptainXamtastic</dc:creator>
      <dc:date>2018-11-30T19:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Clear current design</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/8438847#M18072</link>
      <description>&lt;P&gt;I have this little helper function I use at the beginning of a script. It closes the document with the&amp;nbsp;given name, creates and actives a new document with the same name, and then sets the viewport in the new document to match that of the document that was just closed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I find the viewport thing in particular to be useful when doing iterative design via the API. Otherwise, I find that I'm always having to move the viewport back to whatever I was just looking at, after making a tweak in the script and re-running it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def setup_document(document_name="ScriptDocument"):
    app = adsk.core.Application.get()

    preview_doc = None  # type: adsk.fusion.FusionDocument
    saved_camera = None
    for document in app.documents:
        if document.name == document_name:
            preview_doc = document
            break
    if preview_doc is not None:
        preview_doc.activate()
        saved_camera = app.activeViewport.camera
        preview_doc.close(False)

    preview_doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
    preview_doc.name = document_name
    preview_doc.activate()
    if saved_camera is not None:
        is_smooth_transition_bak = saved_camera.isSmoothTransition
        saved_camera.isSmoothTransition = False
        app.activeViewport.camera = saved_camera
        saved_camera.isSmoothTransition = is_smooth_transition_bak
        app.activeViewport.camera = saved_camera&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Dec 2018 01:06:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/clear-current-design/m-p/8438847#M18072</guid>
      <dc:creator>JesusFreke</dc:creator>
      <dc:date>2018-12-02T01:06:21Z</dc:date>
    </item>
  </channel>
</rss>

