<?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: create bookmark from viewshed (python script) in ArcGIS CityEngine Questions</title>
    <link>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1528554#M11441</link>
    <description>&lt;P&gt;I have a hard time believing that this was ever an intended feature. What probably happened is someone finally saw this, went "That looks like a security problem", and patched it.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2024 10:39:39 GMT</pubDate>
    <dc:creator>shiunwo1</dc:creator>
    <dc:date>2024-08-28T10:39:39Z</dc:date>
    <item>
      <title>create bookmark from viewshed (python script)</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1528454#M11439</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I found it tedious to manually create bookmarks at the same location as the viewshed, so I tried using a Python script for the task.&lt;/P&gt;&lt;P&gt;Although I'm not very familiar with Python, I was able to confirm that the result is correct.(This work was assisted by ChatGPT. I would like to express my gratitude for the exceptional capabilities of ChatGPT. :))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from scripting import *

# Get a CityEngine instance
ce = CE()

# Function to add cameras and create bookmarks based on multiple Viewshed analyses
def addCamerasAndBookmarksForViewsheds():
    # Get all objects in the scene
    all_objects = ce.getObjectsFrom(ce.scene)
    # Filter out the viewshed objects
    viewsheds = [obj for obj in all_objects if ce.isViewshed(obj)]
    
    if not viewsheds:
        print("No viewshed analyses found in the scene.")
        return
    

    # Get the 3D view
    viewport = ce.get3DViews()
    
    # Iterate over each viewshed and create a camera and a bookmark
    for i, viewshed in enumerate(viewsheds):
        # Extract relevant viewshed information
        observer_position = ce.getObserverPoint(viewshed)
        angles = ce.getTiltAndHeadingAngles(viewshed)
        #The heading angle of the bookmark needs to be multiplied by -1         
        #relative to the heading angle of the viewshed. I'm not sure if this 
        #is due to an issue with the coordinate system.
        tilt, heading = angles[0], angles[1] * -1  
        
        
        # Set the camera details to match the viewshed direction and angle
        viewport.setCameraPosition(observer_position[0], observer_position[1], observer_position[2])
        viewport.setCameraRotation(tilt, heading, 0)  # Corrected: tilt, heading, roll
        # You can change the AOV
        viewport.setCameraAngleOfView(39.6)
        
        # Create a bookmark with the given name
        bookmark_name = "Bookmark_{}".format(ce.getName(viewshed))
        viewport.addBookmark(bookmark_name)
        print("Bookmark '{}' created for viewshed '{}'.".format(bookmark_name, ce.getName(viewshed)))

# Main script execution
if __name__ == '__main__':
    addCamerasAndBookmarksForViewsheds()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6361134431112w854h480r745" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6361134431112" data-account="6161463677001" 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/6161463677001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6361134431112w854h480r745');  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://community.esri.com/t5/video/gallerypage/video-id/6361134431112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not best, but I hope it helps in some way&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 06:23:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1528454#M11439</guid>
      <dc:creator>desert</dc:creator>
      <dc:date>2024-08-28T06:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: create bookmark from viewshed (python script)</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1528554#M11441</link>
      <description>&lt;P&gt;I have a hard time believing that this was ever an intended feature. What probably happened is someone finally saw this, went "That looks like a security problem", and patched it.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 10:39:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1528554#M11441</guid>
      <dc:creator>shiunwo1</dc:creator>
      <dc:date>2024-08-28T10:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: create bookmark from viewshed (python script)</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1529908#M11442</link>
      <description>&lt;P&gt;I wish there was a function to convert a viewshed into a bookmark.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Aug 2024 03:42:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1529908#M11442</guid>
      <dc:creator>desert</dc:creator>
      <dc:date>2024-08-30T03:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: create bookmark from viewshed (python script)</title>
      <link>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1537218#M11448</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363945"&gt;@desert&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Interesting script, thanks for sharing. To make it work in CityEngine I had to change a couple of lines at the start:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    # Filter out the viewshed objects
    viewsheds = ce.getObjectsFrom(ce.scene, ce.isViewshed)
    
    if not viewsheds:
        print("No viewshed analyses found in the scene.")
        return
    
    # Get the 3D view
    viewport = ce.get3DViews()[0]&lt;/LI-CODE&gt;&lt;P&gt;If I understand it correctly what you really would like to see is a way to create and edit bookmarks similar to how you can with Viewsheds. If this is the case I encourage you to express this as a new idea in the Ideas forum, this way it will get more traction &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;BR /&gt;Jonas&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2024 08:17:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-cityengine-questions/create-bookmark-from-viewshed-python-script/m-p/1537218#M11448</guid>
      <dc:creator>JonasObertuefer</dc:creator>
      <dc:date>2024-09-11T08:17:21Z</dc:date>
    </item>
  </channel>
</rss>

