• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

HTMLDialog - Change source on the fly? Possible?

Scheduled Pinned Locked Moved Developers' Forum
2 Posts 1 Posters 6.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    placidfury
    last edited by 15 May 2019, 19:51

    I'm just now digging into HTMLdialog usage, as my plugin has kind of outgrown the limited input boxes.
    I tried building a test function, which would build my HTML into a string then assign as the source of the dialog. And it works, for the initial page build and show, but after the user picks something from a dropdown and clicks a button to apply the choice, I want the page to re-load with the selected item in the dropdown changing - but after the button is clicked, the dialog seems to re-load with the initial HTML code, or if I try to rebuild the string and reassign the source, I get a blank window.
    Can the source of the dialog be re-assigned while the dialog is open?
    I've tried to find good examples of how to do this, but all the examples I find seem to be so simple as to not address this, or so over my head they're not much help...

    Thanks!

    Test code below, hope this makes sense... and not too ugly:

    module Htmlexample
      def self.show_dialog
    	model = Sketchup.active_model
    	attrdict = model.attribute_dictionary('BCEWP')
    	usage = 'BldgMod'
    	html = ''
    	html = '	<!DOCTYPE html>
    	<html>
    	<head>
    	<title>Cutlass Dialog</title>
    		<link rel="stylesheet" href="' + Sketchup.find_support_file('Plugins') + '/dialtest/layout.css" type="text/css" media="screen" charset="utf-8" />
    	</head>
    	<script>
    	function sendDataToSketchUp() {
    		var user_module = document.getElementById("id1");
    		sketchup.getUserInput(user_module.value)
    	}
    	</script>
    	<body>
    	<div class="content">
    	<form>
    		<select id="id1" name="modules">'
    	$lastmod = MDAT(0, 'LastUsedBldgMod')
    	attrdict.each { | key, value |
    		if key.to_s.include? "Last"
    		else
    			if key.to_s.include? usage
    				if value.to_s == $lastmod
    					html = html + '<option value="' + value.to_s + '" selected>' + value.to_s + '</option>'
    				else
    					html = html + '<option value="' + value.to_s + '">' + value.to_s + '</option>'
    				end
    			end
    		end
    	}
    	html = html + '</select>
    		<button onclick="sendDataToSketchUp()">Confirm</button>
    	</form>
    	</div>
    	</body>
    	</html>'
    		
    	  options = {
    	  dialog_title; 'Choose Module',
    	  preferences_key; 'cutlass.dynodial',
    	  scrollable; false,
              resizable; true,
              width; 300,
              height; 110,
    	  min_width; 250,
    	  min_height; 70,
    	  style; UI;;HtmlDialog;;STYLE_DIALOG
    	  }
    	dialog = UI;;HtmlDialog.new(options)
    	dialog.set_html(html)
    	if dialog.visible?
    	  dialog.bring_to_front
    	else
    		dialog.add_action_callback("getUserInput"){|action_context, user_module|
    		puts("JavaScript said user_module is #{user_module}.")
    		$lastmod = user_module.to_s
    		MDAT(1, 'LastUsedBldgMod', $lastmod)		
    		}
    		dialog.show
    	end #if
    	end
    end #module
    
    1 Reply Last reply Reply Quote 0
    • P Offline
      placidfury
      last edited by 16 May 2019, 18:04

      Did more searching, and found one spot that said the source couldn't be changed (at least not in the way I was meaning). I guess to do what I really want to do, I'd have to dive deep into this, and I just don't have the time since my development work is a "side" project at work.
      I DO however have time to use TT's SKUI, so that's what I'm going with, since I have already used it for a couple dialogs already in this project.

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      1 / 1
      • First post
        1/2
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement