<?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: What exactly is going on &amp;quot;under the hood&amp;quot; when running a script? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9601569#M11370</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should consider to read about Python and &lt;A href="https://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank" rel="noopener"&gt;OOP&lt;/A&gt; basics first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jun 2020 14:54:54 GMT</pubDate>
    <dc:creator>JeromeBriot</dc:creator>
    <dc:date>2020-06-25T14:54:54Z</dc:date>
    <item>
      <title>What exactly is going on "under the hood" when running a script?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9599869#M11369</link>
      <description>&lt;P&gt;I am a hobby user, and an absolute newbie with no formal programming background trying to learn API scripting to automate some common design tasks, such as classic joinery, for my woodworking hobby.&amp;nbsp; My only frame of reference for programming is with MS-DOS BASIC and .bat programming, which I used to be fairly good at before command-line interfaces were obsolete. I've gone through python tutorials and the API learning material from Autodesk, but I just can't wrap my head around the API-specific syntax.&amp;nbsp; With batch files, it was no different than automating a set list of commands into the DOS prompt and knowing how to carry forward a result from a previous line into the new one when needed, i.e. using variables and arguments.&amp;nbsp; &amp;nbsp; Is this a poor analogy?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What exactly is the API doing here?&amp;nbsp; It seems to me that most of the example scripts are just defining a string as a variable, then nesting that variable inside another and another until finally, an ".add function" is called and that is when something actually happens.&amp;nbsp; For instance, I get the same result with the following 2 blocks of code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;# 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)&lt;/LI-CODE&gt;&lt;P&gt;seems to be the same as:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;sketch = design.rootComponent.sketches.add(rootComp.xYConstructionPlane)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this just convention or is the API doing something else to "Get" an object ("Get the root component of the active design" in the example above)?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jun 2020 23:39:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9599869#M11369</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-24T23:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: What exactly is going on "under the hood" when running a script?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9601569#M11370</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should consider to read about Python and &lt;A href="https://en.wikipedia.org/wiki/Object-oriented_programming" target="_blank" rel="noopener"&gt;OOP&lt;/A&gt; basics first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 14:54:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9601569#M11370</guid>
      <dc:creator>JeromeBriot</dc:creator>
      <dc:date>2020-06-25T14:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: What exactly is going on "under the hood" when running a script?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9602542#M11371</link>
      <description>&lt;P&gt;I think I have at least a basic understanding of python and OOP (or at least the basic concepts), I guess I just can't seem to grasp how the code is controlling fusion when run since there isn't a way to control fusion manually through any sort of command line.&amp;nbsp; In the example above, for the line:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;rootComp = design.rootComponent&lt;/PRE&gt;&lt;P&gt;is Fusion also doing something else with this or is it just assigning the string 'design.rootComponent' to a variable called rootComp, so that later when&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;sketches = rootComp.sketches&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;is written it inserts the string into that line?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 22:41:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9602542#M11371</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-25T22:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: What exactly is going on "under the hood" when running a script?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9602619#M11372</link>
      <description>&lt;P&gt;Let's look at a basic script and dissect what's happening.&lt;/P&gt;&lt;P&gt;Line 4 is calling a static function on the Application object called "get".&amp;nbsp; You can think of the "adsk.core" part as specifying the library where the Application object is defined.&amp;nbsp; Objects support various functions (methods and properties) and one of these for the Application object is the get method.&amp;nbsp; It's a static function because you don't have to have an existing Application object to call it.&amp;nbsp; What's returned is a reference to the Application object and that's stored in the variable named "app".&amp;nbsp; The Application object is the top-level object in the API and represents the entire Fusion application. From the Application object you can access everything else.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Line 5 calls the userInterface property of the Application object.&amp;nbsp; This returns a UserInterface object, which is saved in the variable named "ui".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 6 calls a static method on the Design object called "cast" and passes in as an argument the object returned by calling the activeProduct property on the Application object.&amp;nbsp; The cast method will take the object provided and try to return a Design object.&amp;nbsp; It will only be successful if a Design object is passed in, so this line will only work if you currently have the Design workspace active.&amp;nbsp; If CAM is active, that line will fail because a CAM Product object will be returned.&amp;nbsp; The main reason I'm using the cast here is to tell the editor what type of variable des represents.&amp;nbsp; It's not necessary but if the development environment knows the variable type it can show me intellisense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 7 calls the rootComponent property of the Design object, which returns a Component object.&amp;nbsp; The term "Component" is used a lot in Inventor and unfortunately, not always correctly.&amp;nbsp; To learn more about the internals and what is a component you should read this:&amp;nbsp;&lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A" target="_blank"&gt;http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 9 calls the sketches property on the Component object.&amp;nbsp; This returns a Sketches object.&amp;nbsp; Then in the same line it calls the add method on the Sketches object.&amp;nbsp; Lines like that are actually combining several function calls into the single line.&amp;nbsp; It passes in a construction plane by calling the xYConstructionPlane property of the Component object (the root variable).&amp;nbsp; The result is the creation of a new sketch which is passed back and stored in the variable named "sk".&lt;BR /&gt;&lt;BR /&gt;The Sketch object supports a property called sketchCurves which returns all of the curves in the sketch and it also supports functions to let you get and create curves of various types.&amp;nbsp; This calls the sketchCircles property on the SketchCurves object which returns the SketchCircles object.&amp;nbsp; This object supports the addByCenterRadius method which takes a 3D point and radius as input and creates a new SketchCircle which it passes back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Line 11 gets the first profiles in the Sketch by calling the profiles property of the Sketch object and getting the first profile it contains and saves it in the variable "prof"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally on line 12, it calls the features property of the Component object, which returns a Features object and this object supports the extrudeFeatures property which returns an ExtrudeFeatures object and this object supports the addSimple method which creates an extrude feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can learn all about these objects in the reference manual of the API help.&amp;nbsp;&lt;A href="http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7B5A90C8-E94C-48DA-B16B-430729B734DC" target="_blank"&gt;http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7B5A90C8-E94C-48DA-B16B-430729B734DC&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully, this helps to get you started.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;01 def SimpleExtrude(context):
02     ui = None
03     try:
04         app = adsk.core.Application.get()
05         ui = app.userInterface
06         des = adsk.fusion.Design.cast(app.activeProduct)
07         root = des.rootComponent
08
09         sk = root.sketches.add(root.xYConstructionPlane)
10         circle = sk.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)
11         prof = sk.profiles.item(0)
12
13         root.features.extrudeFeatures.addSimple(prof, adsk.core.ValueInput.createByString('2 in'), adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
14     except:
15         if ui:
16             ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 23:54:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9602619#M11372</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2020-06-25T23:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: What exactly is going on "under the hood" when running a script?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9608065#M11373</link>
      <description>&lt;P&gt;Thanks for the detailed reply.&amp;nbsp; My head is still spinning, but I will continue to dig through and figure it out.&amp;nbsp; I think I just need to study more code examples, but this gives me a great start.&amp;nbsp; So, if I understand correctly, lines such as 05 and 07 are storing strings to be referred to more easily later in the code, and lines 04 and 06 are where an action takes place in fusion, such as .get or .cast.&amp;nbsp; Is this a fair way to look at it?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 15:45:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9608065#M11373</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-29T15:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: What exactly is going on "under the hood" when running a script?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9608181#M11374</link>
      <description>&lt;P&gt;You seem to be stuck on the idea of storing strings.&amp;nbsp; In my sample there are not any strings being stored.&amp;nbsp; What's being saved to variables is references to Fusion programming objects.&amp;nbsp; Line 5, shown below, is using the variable named "app", which references the Fusion Application object and was gotten in line 4.&amp;nbsp; It's calling the "userInterface" property on the Application object.&amp;nbsp; The userInterface property returns a UserInterface object and that's being stored in the variable named "ui".&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ui = app.userInterface&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jun 2020 16:38:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-exactly-is-going-on-quot-under-the-hood-quot-when-running-a/m-p/9608181#M11374</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2020-06-29T16:38:29Z</dc:date>
    </item>
  </channel>
</rss>

