<?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: Is there a better way to detect when user picks a named view? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13079122#M683</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;-San,&lt;BR /&gt;Thank you! How do I know which of named views was clicked though? I've looked through&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ApplicationCommandEventArgs and all it's tree and I can't seem to understand how do I get to which view was selected.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 11 Oct 2024 14:48:16 GMT</pubDate>
    <dc:creator>soswow</dc:creator>
    <dc:date>2024-10-11T14:48:16Z</dc:date>
    <item>
      <title>Is there a better way to detect when user picks a named view?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13078146#M681</link>
      <description>&lt;P&gt;my current solution is to hook up to camera changed event and then on each event go through all named views and compare their camera parameters (eye, target, up_Vector) with the current view camera. It is very hacky and generates multiple events. All doable, but I thought maybe there was a more elegant way.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 06:27:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13078146#M681</guid>
      <dc:creator>soswow</dc:creator>
      <dc:date>2024-10-11T06:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better way to detect when user picks a named view?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13078538#M682</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3100753"&gt;@soswow&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fusion360 executes commands for many operations.&lt;/P&gt;
&lt;P&gt;The UserInterface.commandStarting event is fired when a command is executed.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-EBB6C82A-A256-4AB7-9A86-0F7A9653A7E9" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-EBB6C82A-A256-4AB7-9A86-0F7A9653A7E9&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By using the UserInterface.activeCommand property, the ID of the command being executed can be known.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-635C6C94-BA41-44D6-A97D-61BFA56C6688" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-635C6C94-BA41-44D6-A97D-61BFA56C6688&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you click here, “RestoreCameraCommand” is executing.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 283px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1420411iC3C0DF3775C592DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 10:06:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13078538#M682</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2024-10-11T10:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better way to detect when user picks a named view?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13079122#M683</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;-San,&lt;BR /&gt;Thank you! How do I know which of named views was clicked though? I've looked through&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;ApplicationCommandEventArgs and all it's tree and I can't seem to understand how do I get to which view was selected.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Oct 2024 14:48:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13079122#M683</guid>
      <dc:creator>soswow</dc:creator>
      <dc:date>2024-10-11T14:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better way to detect when user picks a named view?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13080028#M684</link>
      <description>&lt;P&gt;It's ok. I've seen some of your other answers for similar question and it sounds like there is no way to get input information for command this way. I guess that just means I can't use named views as an input for my purposes.&lt;/P&gt;&lt;P&gt;I'd find another way.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2024 00:36:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13080028#M684</guid>
      <dc:creator>soswow</dc:creator>
      <dc:date>2024-10-12T00:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better way to detect when user picks a named view?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13080797#M685</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3100753"&gt;@soswow&lt;/a&gt;&amp;nbsp;-San.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the command occurs, we created a sample that compares the current Camera with the Camera in the NamedView and determines that the one that matches is the one that was clicked.&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#FusionAPI_python addin
import traceback
import adsk.core as core
import adsk.fusion as fusion

_app = core.Application.cast(None)
_ui  = core.UserInterface.cast(None)
_handlers = []

_cmdInfo = {
    "id": "kantoku_DumpPickNamedViewTest",
    "name": "DumpPickNamedViewTest",
    "tooltip": "DumpPickNamedViewTest",
    "workSpace": "FusionSolidEnvironment",
    "panelId": "SolidScriptsAddinsPanel",
}


def run(context):
    ui = None
    try:
        global _app, _ui
        _app = core.Application.get()
        _ui = _app.userInterface

        cmdDefs: core.CommandDefinitions = _ui.commandDefinitions

        global _cmdInfo
        cmdDef: core.CommandDefinition = cmdDefs.itemById(_cmdInfo["id"])
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(
            _cmdInfo["id"],
            _cmdInfo["name"],
            _cmdInfo["tooltip"])

        global _handlers
        onCommandCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCommandCreated)
        _handlers.append(onCommandCreated)

        workSpace: core.Workspace = _ui.workspaces.itemById(_cmdInfo["workSpace"])
        targetpanel :core.ToolbarPanel = workSpace.toolbarPanels.itemById(_cmdInfo["panelId"])

        controls :core.ToolbarControls = targetpanel.controls
        cmdControl :core.ToolbarPanel = controls.addCommand(cmdDef)

        cmdControl.isVisible = True

    except:
        if _ui:
            _ui.messageBox("Failed:\n{}".format(traceback.format_exc()))


class CommandCreatedHandler(core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            global _app, _ui, _handlers
            cmd = core.Command.cast(args.command)
            des :fusion.Design = _app.activeDocument

            core.Camera.isEqual = isEqual

            # event
            onCommandTerminated = MyCommandTerminatedHandler()
            _ui.commandTerminated.add(onCommandTerminated)
            _handlers.append(onCommandTerminated)

        except:
            if _ui:
                _ui.messageBox("Failed:\n{}".format(traceback.format_exc()))


class MyCommandTerminatedHandler(core.ApplicationCommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args: core.ApplicationCommandEventArgs):
        if not _ui.activeCommand == "RestoreCameraCommand": return

        stateCam: core.Camera = _app.activeViewport.camera

        des: fusion.Design = _app.activeProduct
        views: core.NamedViews = des.namedViews
        view: core.NamedView = None
        for view in views:
            if stateCam.isEqual(view.camera):
                _app.log(f"Pick NamedView {view.name}!!")
                return


def isEqual(self: core.Camera, cam: core.Camera) -&amp;gt; bool:
    if not self.cameraType == cam.cameraType:
        return False
    if not self.eye.isEqualTo(cam.eye):
        return False
    if not self.target.isEqualTo(cam.target):
        return False
    if not self.upVector.isEqualTo(cam.upVector):
        return False
    if abs(self.perspectiveAngle - cam.perspectiveAngle) &amp;gt; 0.001:
        return False

    return True


def stop(context):
    try:
        global _cmdInfo
        workSpace: core.Workspace = _ui.workspaces.itemById(_cmdInfo["workSpace"])
        panel: core.ToolbarPanel = workSpace.toolbarPanels.itemById(_cmdInfo["panelId"])

        if panel:
            panel.controls.itemById(_cmdInfo["id"]).deleteMe()

        cmdDefs: core.CommandDefinitions = _ui.commandDefinitions
        cmdDef: core.CommandDefinition = cmdDefs.itemById(_cmdInfo["id"])
        if cmdDef:
            cmdDef.deleteMe()

    except:
        print("Failed:\n{}".format(traceback.format_exc()))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 261px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1420841iCB366CE30DE5D06C/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since Design.namedViews contains only the NamedViews that you have created yourself, if you need to detect the use of the default one, you should check the Camera data in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Oct 2024 15:41:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13080797#M685</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2024-10-12T15:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a better way to detect when user picks a named view?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13083115#M686</link>
      <description>&lt;P&gt;oh yes! Smart people think alike I suppose &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; I've come up with the same thing. Actually, I found even nicer solution for my case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6363236005112w1026h540r355" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6363236005112" data-account="6057940548001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6057940548001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6363236005112w1026h540r355');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://forums.autodesk.com/t5/video/gallerypage/video-id/6363236005112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I decided not to worry about named views entirely. Through naming convention and way to detect when canvas is turned on and off, I can move the camera to the required frame, since I have all cameras information when user selects specific convas. And also I hide canvas when camera is moved away.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2024 12:08:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/is-there-a-better-way-to-detect-when-user-picks-a-named-view/m-p/13083115#M686</guid>
      <dc:creator>soswow</dc:creator>
      <dc:date>2024-10-14T12:08:10Z</dc:date>
    </item>
  </channel>
</rss>

