sketchucation logo sketchucation
    • Login
    1. Home
    2. jolran
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 37
    • Posts 1,027
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: [Tutorial] PickHelper - Visual Guide

      I had a quick look. Good stylished job! Appears very easy too follow.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Thanks, you are most kind.

      I will have another look at your libraries.
      Although I got it working now with a different solution, it would be good to know what went wrong before.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Yeah, ok. I did not manage to make it work with nested hashes.
      Got some backslashes "/" and wierd results.
      Your method most likely works, but I might have scre#Β€ewd things up making the nested hashes in ruby. Also got somewhat lost in the code during the process.

      So I took one step back to get some control over the situation and decided not to use nested JSON. In spite of yours and Dans efforts 😳 Sorry.

      Instead I make 4 separate JSONlists using your 1st converter.
      Send them in the execute_script function(). Rewrote some JS so I could reuse your loops.
      It might be safer doing it that way anyway?
      Don't have to eval or parse the JSON, just use the sort_by_value(json) function you provided, Thomthom.

      It works, but might need some optimizing.
      Can post some code later..

      Happy new year BTW!

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Ahh! Very nice.
      2 methods I can try before corking up πŸ˜„

      Dan, havent seen that one before. Started doing standard hash, but this looks interesting indeed. Learning lots here.

      Thomthom, so the code is basically just repeating until it doesent find a hash? I was trying to do something similar but it did not work for me. Some ":" came out as "=>". Will try and let you know how it works.
      BTW it says # Very simplified method just for this example's purpose.
      I suppose you have more convoluted for this purpose?

      Thanks to both of you!

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      @unknownuser said:

      My library is built around populating the webdialog with Ruby classes - letting me develop UIs using just Ruby.
      I see, must be convenient doing like that in the long run.
      For me just now I only need to send in some lists and values to my dialog and hit an OK buttons and start Ruby.

      So the strategy right now is to nest a hash=>json object with list of material, layers, components and default values for inputboxes. And send through a function like you do in materials.rb.

      @unknownuser said:

      But along with that blog entry I might see if I can decouple my bridge framework.

      Do you mean a bridge light? Sounds interrseting.
      It seems there is no easy way to get around that webdialogs have to be complicated. Looks like there are many things that can go wrong. And the step from SU's inputbox is quite large.

      http://sketchucation.com/forums/viewtopic.php?f=180&t=35969#p316774
      This topic covers alot about JSON in Sketchup, BTW. Might mention it if someone enters here looking for info bout the subject.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Thomthom, thanks.

      I have been poking around in TTlib. But sometimes the picture is so big I can't see the details πŸ˜„

      Also I totally forgot to check out your thomthom.net docs. Bunch of info there.

      With your explanations here I might understand the code better.
      Will give it a try.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      OK! a lot of new stuff to digest. This forum is great.

      It seems like I do a lot of things in almost the right way, or the wrong way. πŸ˜„

      I wasent sure in wich direction there was a message size limit. So to defend against that I interpreted from some topic that you could insert arrays or such in hidden inputfields.
      Sending layers, materials and component names it can easily become over 2000 characters. But in reality I won't reach that large amounts like during some tests here from Thomthom.

      Dan.
      JSON.parse( string ) sound like a better solution then. As long as I accept the user has IE8 +. For Mac that will not be an issue?
      I believe that the user is probably working with SU on his or her major workstation which should be up do date.
      Still have to figure out how to nest JSON or rather "hashes ready" for JSON in ruby first. Maybe use the method Thomthom already provided if it will work for that purpose.
      There is bunch of info regarding " require 'json' ". But that module is not avilable in Sketchup I suppose..

      Regarding "code cleanup after script" I saw that thread, and put Thomthoms JQ body-detach script in the "$doc.ready" function. Don't know if theres the right place to put it, but I sure did πŸ˜„
      Maybe it should be done in a callback πŸ˜•

      So just to make clear, I can forget about hidden inputfields and just send the data from SU exect.script to a global array in JS then? Like Thomthoms in this topic provided" materials.rb" do.

      JD Hill. Thanks.

      Sounds a bit like the issue I had before, I was also conserned about the end user going heywild on the keybord with names and such.
      I suppose you havent had a look at Thomthoms script? Or maybe you are already doing something similar.
      Well anyway, it's cleverly using 1 string stored as .text for display in webdialog and keeping the original SUmaterial.name stored as value. So one send the value to SU from JS.
      In case of materials in SU, display.name is used, but I dont think there is nothing stopping you from doing some escaping on that string either, cause it wont affect the value. If one can put anything one like as value or not I havent got a clue..

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Hi again!

      ThomThoms code seems to be working very well. I've expanded the code to include lists of layers.name and components.name(from file) as well.
      Also I'm sending the JSON.hashes to hidden inputfields in the HTML.

      Took like forever to figure out one has to convert the JSON when extracting it from an inputfield or such. With something like:

      var containr = eval('(' + $('#container').val() + ')') ;
      

      Code is just for some other "freshy" who's also in distress.

      Now comes the question concerning strategy.

      I already got it working well but with sending data to multiple inputfields during several "execute_scripts". I suppose it's better/or cleaner to store all data in 1 JSON obj. And the send it to 1 inputfield?
      Ideally I would include some other default values in the JSON as well.
      However I can't get the syntax right. I've tried with something like:

      @vals2JS= {
      		"matlist" => self.hash_to_json( self.materials_hash ),
      		"layrlist" => self.hash_to_json( self.layers_hash ),
      		"complist" => self.hash_to_json( self.comps_hash )
      	}
      

      And then try converting the @vals2JS hash to JSON, but to no avail. 😞
      Also I'm worried about the maximum message limit. Maybe it's better to send data in chunks like I am? Or does it hurt something?

      Update: Ok, i read someone suggesting serialize arrays or hashes with "join" and "split" to be able to put multiple values in hidden inputfields. πŸ˜•
      Also if I understood it correctly there is only maximum message limit FROM webdialog to Ruby?? For me that won't be a problem if thats true...

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      @unknownuser said:

      FIY: I added a [Code] tag to the title

      Thats great! Hope the topic can help others as well.

      @unknownuser said:

      That could be a correct assumption, IF jQuery was without bugs. It is not.

      Yeah, thats always I possibility. Like you said Thomthom code seams to work, so I will try to do it his way in my way.
      Always interesting to read about your deep explorations, Dan. Although I'm not grasping everything.

      edited: OT

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      [
      @unknownuser said:

      Go ahead!

      That is very kind of you! I've never used a for loop before so I'll might rewrite some stuff to the codingstyle I'm used to. Otherwise I'll have a hard time to follow.

      @unknownuser said:

      Not sure what you mean by this though. Custom interface?

      costum UI, [like "jquery-ui-1.8.16.custom.min.js". Download whats needed.

      @unknownuser said:

      I might just use it as an example for a new blog entry as it deals with a few common issues in communication with webdialogs.

      I think you should πŸ‘ It's a good example I think. Not too long not too short.
      Trying to learn from someone elses script with 500 + lines of ruby + HTML, JS etc can be very time consuming and difficult. And Googles examples leave you in need for more.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      BTW do you always use Jquery source with ajax.googleapis.com etc..?
      Or was it just for this example.
      It's only works if you not in the need for costum interface right?

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Thank you very much Thomthom β˜€ . I havent tried it, but I trust it works.

      May I add parts of it and mimic some into my script?
      Will have to rewrite lots of my stuff but this looks very well structured, and I like my code to be that as well πŸ˜„ .

      Edit. Just tested and it works nicely πŸ‘

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      ThomThom, thanks and good point! I will definately investigate text vs HTML content.

      Dan. Interresting read. Not quite following it all, but if JQ is using innerText(my MS) may that cause problems with MAC?
      Although I thought JQUERY took care of platform incompabilities?

      EDIT: something dropped down the mailbox. Will have a look at that Thomthom!

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Plugin] VisTools v1.3.4

      "Look Mom! No code outside the author's namespaces." πŸ˜„

      Looks like very tidy code. And well documented. Will study this.

      posted in Plugins
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Thomthom, thanks for your help.
      I am using Jquery as well. I'm using it noway near its potential, though. But I think the JQ selectors themself is worth the try learning it.
      Don't have a programmer background so all this is quite new to me.

      @unknownuser said:

      static HTML
      ?

      Do you mean running the HTML straight from Notepad? I do that often, but not with theese
      variables though. I thought theese problems came from ruby-side so..

      @unknownuser said:

      Make sure you make the data valid for HTML. & is a special characters used to denote character entities

      Well, I am sending strings, yes. I'm always aware of that.

      But the material names can be made by a user. Sketchup.active_model.materials. So I thought (besides having tidy names in the dialog) the convention was to trap for cases where the user enters some invalid characters in the material name.

      Its difficult to post snippets from a larger piece of code but I can try.

      In the JS I have an body onload function like which call a function to SU for default options:

      $(document).ready(function(){
      getSU_opts('populate_UI');
      }
      

      This function then make a callback to SU for default values.

      function getSU_opts(vals) { // populates the Webdialog from SKP. 
      		window.location.href = 'skp;get_data@' + vals;
      }
      

      Back in SU after creating the webdialog I have this callback to send default values.

      @hatchUI.add_action_callback("get_data") do |@hatchUI, vals|
      		if vals=="populate_UI"
      			@hatchUI.execute_script(%(document.getElementById("mat_list").value   ="#{getmats()}";))
        end
      end
      

      "mat_list" is a hidden inputfield. In case the list gets long.

      So to populate the Html dropdownlist I'll use this michmach Jquery-JS code.

      function populate_List(i,j){ //i=id of "hidden storage-element"(array). j=id for selectionbox where to create new option from i
      		
      		var Listitem = $(i).val().split('|');
      		
      		$.each(Listitem, function(val, text) {             
      			$(j).append( $('<option></option>').val(val).html(text) )             
      		}); 
      }
      

      The code is working somewhat.
      I do get a dropdownlist with the material names, except for thoose extreme names.
      They get blank, but are selectable.
      And if I dont use string.gsub(/[^_0-9A-Za-z/, '')]
      I get an JS error. If it not standard to trap for extreme non english name I think I'm ok?

      Note I'm just showing the relevant code parts to this topic.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      Ahh, now I see what you mean by Properly escaping the execute_string argument.

      Yes I think I'm doing that properly cause I'm populating the dialog with materialnames already. Some come out as blank though. But they are extreme names like ÄÅÀâp()&&Β€# etc, just for testing.
      I do get an JS error if NOT escaping some characters like I do in the method.
      even if they are strings. Maybe my meta-tag is incorrect?

      <meta http-equiv="X-UA-Compatible" content="IE=8"/>
      <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
      

      material.display_name is interesting though. Cause I also wanted to display more user-friendly names in the dialog.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Code] Material.names to Webdialog.

      @unknownuser said:

      UTF-8 encoded?

      I think so, will doublecheck. Some materials came out as blank until I escaped some characters.

      @unknownuser said:

      Properly escaping the execute_string argument?

      Not sure what you mean.

      I'm currently populating the dialog with excecute script and passing in each values. Some are methods like the one posted #{method}. Could and probably will be turned into hash later on. I will pay more attention to your homepage, some good reading on materials there.

      So you are saying that all SU characters are legitimate? No need to escape as long as UTF-8?
      I am sending user material names if that has anything to do with it.
      Testing with some wierd names like "%&%/((%)%)=?&(&". Actually I just thought this was something one had to do before sending strings to html/js. Just proves how little I know πŸ˜„

      posted in Developers' Forum
      jolranJ
      jolran
    • [Code] Material.names to Webdialog.

      [mod=Solution:2yiho50t]Sample code posted here: http://sketchucation.com/forums/viewtopic.php?f=180&t=49704#p447346[/mod:2yiho50t]

      Hi.
      I'm passing in material names to webdialog, and sometimes they may include illegal characters.
      So using some string.gsub to make them more acceptable for the html works.
      But then again it is difficult(impossible?) to rebuild that string when coming back to SU-Ruby.
      So I'm searching for info about the subject and meanwhile have a solution thats working for my case, but I am a bit worried the method can fail at some point.

      The main idea is to get model material names to array1.
      Then make a "clone" of array1 with same strings, in same order, but illegal characters removed .
      Pass clone-array to Webdialog. Then back to SU I'll catch the "index" value from the selection. And use strings from array1[index] to assign the material.

      Here some code, not optimized but works when sending the array "web_mats" to a hidden inputfield in HTML and listing the items as options in dropdownlist.

      def getmats()
      	@mat_names=[]; web_mats=[] 
      	Sketchup.active_model.materials.each {|e| @mat_names << e.name if e.valid? } #
      	@mat_names.sort! #Not very precise since there could be numbers. But decent enough.
      	@mat_names.each{|e| web_mats << e.gsub(/[^_0-9A-Za-z]/, '')  } 
      	return web_mats.join('|')
      end
      

      So as I said the index number of the selection option, should match array 1 material name that has the correct stringconvention for SU.
      Not posting any JS here to shorten the topic.

      Now!
      I see that IF the gsub routine fails and the string to HTML is "illegal", there is a blank in the dropdownlist. BUT, the index numbers still seems to be correct. So the 2 arrays still contains same number of items in the right order. But some nils. I can live with that..
      But again if somehow the index would return wrong number, all materials would get mixed up, and thats not a good thing to say at least.

      Is this a bad way of doing things? Some pitfall I havent thought of? I'm sure there is a smarter way even though I like the simplicity in this solution.

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: Two identical faces, but show just one

      Thomthom's links tells you how it works. Sometimes the API can be hard to understand. Also we don't know where exact you are in your code.
      But you can group the face and then turn the group into an component.
      I think its easier to work with groups at first and then at some point turn it into an instance-component when ready to glue to a face. Just a personal preference.
      Dont know how you want to group your face but be careful not to group Sketchup entities directly(add_group(entities). It can BUGsplat.
      And then use the behavior to glue. Lets say you have made your component and it's called inst.

      You get the behavior with: be = inst.defintion.behavior
      You have all the behavior methods in the API. But for gluing you will need to add:
      be.is2d = true
      be.cuts_opening = true
      be.snapto = 0

      So lets say your second face you want to glue onto is called face2.

      Then you just add inst.glued_to = face2

      Don't have time to give you more code just now. Maybe Thomthom get back to you after he have packed all his presents πŸ˜„

      posted in Developers' Forum
      jolranJ
      jolran
    • RE: [Plugin] TIG-Smart_offset

      Thank you TIG and Merry Christmas!

      This one is a difficult task.

      posted in Plugins
      jolranJ
      jolran
    • 1 / 1