<?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: Code for control of the camera in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7738140#M16801</link>
    <description>&lt;P&gt;Hi, Mr.Peter&amp;nbsp; and Mr.Tu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'&lt;SPAN&gt;adsk.core.Camera' is a type of gibberish most programmers commit&amp;nbsp;quite often.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just correct it a little bit to:&amp;nbsp; '&lt;/SPAN&gt;adsk.core.Application.get().activeViewport.camera' and you will be on a solid path for ... for the next one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;MichaelT_123&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 00:21:49 GMT</pubDate>
    <dc:creator>MichaelT_123</dc:creator>
    <dc:date>2018-01-31T00:21:49Z</dc:date>
    <item>
      <title>Code for control of the camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7724330#M16797</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below controls the camera in Fusion 360. The code works properly but there are some additional assignments that I have to do which to my knowledge should not be necessary and should be possible to replace them by just one assignment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the code I have to assign (part of the code below):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        cam.eye = adsk.core.Camera.eye
        cam.target = adsk.core.Camera.target
        cam.upVector = adsk.core.Camera.upVector
        cam.isSmoothTransition = adsk.core.Camera.isSmoothTransition&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to be necessary to make the assignment property by property in order to get the code working. It would be much easier if I could make the assignment for all properties att the same time by&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;cam = adsk.core.Camera&lt;/PRE&gt;&lt;P&gt;but if I try to execute the code with this assignment I get the error code: Is there anybody that can explain what I am doing wrong ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Error Code" style="width: 301px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/454877iFC8FED243A58BAB4/image-dimensions/301x322?v=v2" width="301" height="322" role="button" title="bild.png" alt="Error Code" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Error Code&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#Author-
#Description-


import adsk.core, adsk.fusion, traceback, math

app = adsk.core.Application.get()

def run(x):
    try:
        cam = app.activeViewport.camera        
        target = adsk.core.Point3D.create(0,0,100)
        up = adsk.core.Vector3D.create(0,0,1)
        eye = adsk.core.Point3D.create(500,500,100)

        steps = 500
        
        adsk.core.Camera.eye = eye
        adsk.core.Camera.target = target
        adsk.core.Camera.upVector = up
        adsk.core.Camera.isSmoothTransition = False     

        cam.eye = adsk.core.Camera.eye
        cam.target = adsk.core.Camera.target
        cam.upVector = adsk.core.Camera.upVector
        cam.isSmoothTransition = adsk.core.Camera.isSmoothTransition

        app.activeViewport.camera = cam
        ViewDist = adsk.core.Camera.target.distanceTo(adsk.core.Camera.eye)
        
        for i in range(0, 2*steps):
            eye = adsk.core.Point3D.create(2*ViewDist * math.cos((math.pi*2) * (i/steps)),\
            ViewDist * math.sin((math.pi*2) * (i/steps)), 100)            

            cam.eye = eye                             
            app.activeViewport.camera = cam

            adsk.doEvents()
            app.activeViewport.refresh()
            
    except:
        ui = app.userInterface
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;&lt;P&gt;Best Regards&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 19:19:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7724330#M16797</guid>
      <dc:creator>Peter__B</dc:creator>
      <dc:date>2018-01-25T19:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Code for control of the camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7725210#M16798</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I simplify your codes as below. "cam = app.activeViewport.camera" just gets a (temporary)copy of current camera. You can edit its parameters and set it back to active viewport to make the changes take effect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import adsk.core, adsk.fusion, adsk.cam, math, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        cam = app.activeViewport.camera        
        target = adsk.core.Point3D.create(0,0,100)
        up = adsk.core.Vector3D.create(0,0,1)
        eye = adsk.core.Point3D.create(500,500,100)

        steps = 500

        cam.eye = eye
        cam.target = target
        cam.upVector = up
        cam.isSmoothTransition = False

        ViewDist = target.distanceTo(eye)
        
        for i in range(0, 2*steps):
            eye = adsk.core.Point3D.create(2*ViewDist * math.cos((math.pi*2) * (i/steps)),\
            ViewDist * math.sin((math.pi*2) * (i/steps)), 100)            

            cam.eye = eye                             
            app.activeViewport.camera = cam

            adsk.doEvents()
            app.activeViewport.refresh()


    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 01:54:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7725210#M16798</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2018-01-26T01:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Code for control of the camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7725625#M16799</link>
      <description>&lt;P&gt;Thanks Marshal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also did that myself (copying a the current camera), but why do I get an error when I try to make the assignment ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;EM&gt;cam = adsk.core.Camera&lt;/EM&gt;&lt;/PRE&gt;&lt;P&gt;If I make the assignments it property by property i.e.&amp;nbsp; &lt;EM&gt;cam.eye = adska.core.Camera.eye&lt;/EM&gt;&amp;nbsp; etc. it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is the assignment, &lt;EM&gt;cam = adsk.core.Camera, &lt;/EM&gt;not allowed ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Peter&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 08:43:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7725625#M16799</guid>
      <dc:creator>Peter__B</dc:creator>
      <dc:date>2018-01-26T08:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Code for control of the camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7734832#M16800</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"adsk.core.Camera" is an API object. We didn't provide assignment operator for it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 03:07:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7734832#M16800</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2018-01-30T03:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Code for control of the camera</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7738140#M16801</link>
      <description>&lt;P&gt;Hi, Mr.Peter&amp;nbsp; and Mr.Tu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'&lt;SPAN&gt;adsk.core.Camera' is a type of gibberish most programmers commit&amp;nbsp;quite often.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just correct it a little bit to:&amp;nbsp; '&lt;/SPAN&gt;adsk.core.Application.get().activeViewport.camera' and you will be on a solid path for ... for the next one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;MichaelT_123&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 00:21:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/code-for-control-of-the-camera/m-p/7738140#M16801</guid>
      <dc:creator>MichaelT_123</dc:creator>
      <dc:date>2018-01-31T00:21:49Z</dc:date>
    </item>
  </channel>
</rss>

