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

    Posts

    Recent Best Controversial
    • RE: What am I doing wrong?

      Sorry to dig up an old thread but It's kind of relevant to what I'm trying to do with inputbox.

      What I'd like to do is associate a word with a value... ie: inputbox prompts for 3 values to create a square, height, width and vertical line... height and width are pretty self explanatory. Vertical line is expressed as inches.. so a 24" x 24" square could be divided in half by typing in 12... what I'd like to add is being able to type in 'center' or 'middle' and getting the same result.

      I've tried making that field of the array a string and then converting the string to an integer or a float but I just can't get it to work... also tried associating the words to a value and samething no workie...

      Hope that makes sense...

      Thanks in advance.

      @tig said:

      Also you might not want the height as an integer by using .to_i, because 0.5.to_i will become 0 not 1 as you might have expected, as an integer simply ignores anything to the right of the decimal-separator !
      The inputbox dialog can have its 'type' set to be a 'float' etc by making the default e.g. 1.0 [rather than 1 which fixes it as an integer] - then the dialogs returned_value[0] is always as a float anyway - BUT if you really want it to be a string - so for example the user can type ' 1.5m' and they'll get 1.5m irrespective of the SKP's current unit settings - then use .to_l to convert that value into a 'length'...

      Rather than add your dialog into a lot of complex code to test it just make it in a one-liner in the Ruby Console...

      results=UI.inputbox(["Height: "],[1.0],[""],"My Title")
      for a float - shown with
      answer=results[0], and answer.class

      results=UI.inputbox(["Height: "],[1],[""],"My Title")
      for an integer - shown with
      answer=results[0], and answer.class

      results=UI.inputbox(["Height: "],["1.0"],[""],"My Title")
      for a 'string'- shown with
      answer=results[0], and answer.class and then
      answer.to_i answer.to_f answer.to_l

      [Try different answers to see the results...]

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      @tig said:

      Here's Jim's clever solution made into a method...

      def roundtofraction(num, frac)
      >   num = num.to_f
      >   frac = frac.to_f
      >   return (num * frac).round / frac
      > end
      

      Usage:

      my_num = 0.17578125
      my_frac = 16
      my_num=roundtofraction(my_num, my_frac)

      0.1875

      Thanks yet again TIG! πŸ˜„

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      @dan rathbun said:

      This is for measurements?

      One limitation within Sketchup, is that the precision is limited to 0.001", no matter what the model units are set to.

      So using a fractional float of 0.1875" may get rounded by Sketchup. Will it be 0.187" or 0.188" ??
      I would suggest that you decide what it will be in your 'rounding' method...

      Yes Dan, this is for measurements.

      I didn't know that limitation about Sketchup, interesting. But I'm not building a plane here just cabinets, vanties and that kind of thing, but I just don't like seeing that ~ and this script programming is addictive! You just keep adding on features and stuff you can do, I think I might have a problem. πŸ˜†

      Thanks for the info

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      @chris fullmer said:

      That can't be right, you didn't even have to make any special methods to do that 😳 πŸ˜†

      Chris don't feel bad even after doing this thing called 'programming' for the last few weeks I'm still getting the hang of methods, classes and all that jazz!! 😳 πŸ˜†

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      @jim said:

      my_num = 0.17578125 frac = 16.0 # 1/16th (radix, specifically) rounded_num = (my_num * frac).round / frac

      Dude you're a genius! That is awesome!

      Thank you!!

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      Wow! Thanks for taking the time to explain it in a Ruby's for Dummies term! πŸ˜„ No way I would of come up with a solution to that problem!

      That now makes total sense... now I'm off to try and implement this in my script... should fun πŸ˜„

      Thanks again!

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      Thanks Chris...

      I'm going to need to study that for awhile because at first glance I'm lost πŸ˜„ but on the other hand I'm glad it's not something simple because I was racking my brain trying to figure this out! 😳

      posted in Developers' Forum
      F
      Frankn
    • RE: Is there a ceiling function like in excel?

      Thank you Tig... that is helpful but it doesn't accomplish exactly what I'd like it to do... unless I'm not using it properly.

      Here's a more concrete example of what my problem is...

      A result I get after doing some funky math is 0.17578125 but I'd like to round that off to 0.1875. In Excel I'd this =CEILING(0.17578125, 1/64) and that works great.

      0,17578125 is actually more accurate but it's TOO accurate. πŸ˜„ Because I get a measurement inside Sketchup that has the ~ in front of it.

      Basically I'de likt to set the accuracy of my formulas to 1/64.

      I appologize if it's me not 'getting' your previous answer... I guess from my question you already guessed I'm still new to this whole programming deal. 😳

      posted in Developers' Forum
      F
      Frankn
    • Is there a ceiling function like in excel?

      Hi,
      Like the title says... I'm looking for a way to replicate the ceiling function in excel. I played around with ceil but either I'm not getting it or it doesn't do the same as excel.

      I basically want to round off numbers/measurments to the nearest 1/64.

      Any help would be greatly appreciated.

      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Inputbox with drop down list question

      Thank you guys that helped a ton in my understanding of how that works!

      I do have a few of questions...

      What is the the differnce in creating a list this way...

      list = ["item1"|"item2"|"item3"]

      and this...

      list = ["Wall", "Wall - Corner", "Base", "Base - Corner"]
      list_joined = list.join("|")
      drops = [list_joined, ""]

      any advantages disadvantages?

      Also in some examples that I found the don't use the UI in the inputbox command... again any advantage in doing either or?

      And lastly I'm having trouble understanding/implementing this last part...

      def dialog()...
      ###then in tour main code have
      return nil if not self.dialog()

      the def dialog() method contains these lines

      after the dialog has opened etc...

      ...
      return nil if not results
      ...
      if results[1] < 0
      UI.messagebox("The number must be >= 0 !")
      self.dialog()

      retry - user either then cancels >> nil or enter a number >= 0 >> true

      else ### number was OK
      @number=results[1] ### reset @number only now...
      return true
      end

      at the end

      Frank

      posted in Developers' Forum
      F
      Frankn
    • Inputbox with drop down list question

      Hi,

      I'm trying to get a drop down list to work. I'm able to creat an input box and even add a drop down list. But what I'm not able to figure out and can't seem to find the answer too is how to associate a value or have code run from the drop down list options.

      As you might have guessed I'm new at this whole programming thing. πŸ˜„ Any help would be appreciated.

      Thanks,
      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      I fixed a few things and realized I could call the instances I added to the global component by different names. πŸ˜„ 😳

      It does run slow but I still haven't looked into optimising scripts so hopefully I can speed it up some though I don't mind it though, it's faster then creating a cabinet from scratch. πŸ˜„

      Next on the to do/ to learn list is...

      • Creating door and drawer fronts, creating drawers... shouldn't be a problem.
      • Add a user defined number of shelves and insert them evenly spaced in the cabinet... I can do this manually/individually but the math involved in doing them automatically should be fun to figure out!
      • Same thing for door and drawer fronts.
      • And give a choice of creating an upper or lower cabinet since the building of these is different... I could use 2 different scripts like I did when moding the cab.rb script but I think it would be slick having it all-in-one.
      • Add grain direction
      • And eventually learning how to export the to a csv file so that I can populate an existing excel spreadsheet that I use... yes I know there are already some cut sheet/list scripts but this is more of a hobby/learning experience and I'd like to see what I can do. πŸ˜„

      That should be it but I'm already happy with the progress I've made in just 3 or 4 days or learning this stuff.

      Again thanks for all the help I really appreciate your teach how to fish approach. πŸ˜„

      Frank


      Test.rb

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      Hi Dan,

      Thanks for the explanation, I think that's what I did without realizing with just trial and error... many, many errors! πŸ˜„

      I thought you might like to see what I've been working on and by default bothering you with πŸ˜‰ so I included the script.

      Keep in mind this is a work in progress and my first attemp at at sort of programming so go easy on me. 😳 and please feel free to comment on what I'm doing wrong or that I could improve.

      Also the Drawers and Doors functions/inputs aren't implemented yet... still haven't figured that part out.

      Thanks again,
      Frank


      Test.rb

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      See API: ComponentDefinition.refresh_thumbnail

      cdefs = Sketchup.active_model.definitions
       cdefs.each {|comp| comp.refresh_thumbnail }
      

      [/quote]

      Thanks that worked perfect. πŸ˜„

      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      I had already tried that and it doesn't work, the only way to get them to show up is to edit the component then the preview shows up. Not a big deal but was just curious if I was doing something wrong with the script/code.

      Thanks again sir,
      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      Again thank you for the explaination Dan... it almost makes sense to me! πŸ˜„

      Something strange is happening with the way the components are being displayed in the Components window in Sketchup. They're all there but there is no preview picture to the components. But if I create a component manually it shows up... an idea why?

      I've also been looking into adding components to other components and all I found so far is some refernences to subcomponents and parent components but nowhere did I find how those work?

      This has been a greta learning experience and I find half the battle is actually using the correct search terms but I'm getting there!!

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      Hi just wanted to thank you both for taking the time to help me learn something new. I was able to get it to work but I couldn't get this line to work...

      model.active_entities.add_instance(new_def_component, Transformation.new) I keep getting this error not sure why.
      Error: #<NameError: uninitialized constant Transformation>

      But I am able to get it to work with this and it does what I need so far. πŸ˜„
      inst = ent.add_instance def_shelf, [0, 0, 0]

      I do have a question. I know how to create multiple instances of the same component and even make them unique if I need to... but how can I make the number of instances needed a variable?

      Example... user is prompted for the number of boxes he wants to add, he enters 3, the scripts creates 3 boxes in different locations.

      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      The more I read about how to create entities (I think I'm using the correct term) the more I realize that this script (cab.rb) probably isn't the best one to learn to script with.

      Using entries like entities.add_line([0, 0, 0], [10, 10, 10]) seem to be much more useful, also more powerful and maybe even simpler to use when you get how they work.

      Even if this script does hwta I want it to do, seems like building off of it to get the end result I want is more work then making something from scratch...

      Back to the reading!

      p.s. Mods if this is taking this thread off topic let me know and I'll stop posting here. πŸ˜„

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      Thanks for the link Dan, I'll give it a try and see how it compares to CutList 4.1

      So is it better to use... entities.add_line([0, 0, 0], [10, 10, 10]) ...which is something new I'll have to learn πŸ‘Š then what this script is using?

      @unknownuser said:

      Well don't feel bad.. because Components are in the second semester course.

      So what you're saying is I'm trying to run before I can walk... πŸ˜†

      If there's a simple tutorial on components somewhere please point me to it, I'd really like to understand this aspect of scripting because it seems like something I'd use a lot of.

      Well back to the books/web for me... wish me luck I need it so far what you and Jim have given me causes Sketchup to crash πŸ‘Š 🀣 and I know it isn't the code you've given me but I think it's where I'm placing it into the script...

      Serenity now!!!

      Thanks,
      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Creating Components in Cab.rb

      Thank you so much Jim for taking the time to answer such a seemingly simple thing to do. πŸ˜„

      I still get confused with this part...

      entities = new_component_definition.entities
      entities.add_line([0, 0, 0], [10, 10, 10])

      Is the second line equivelent to the following?

      ls=[] #left panel
      ls[0] = [0, depth, kick]
      ls[1] = [0, depth, height-thick]
      ls[2] = [0, thick, height-thick]
      ls[3] = [0, thick, kick]
      ls_base = entities.add_face ls
      ls_base.pushpull thick

      It's starting to make more sense. πŸ˜„

      Out of curiosity and in the name of learning how to do things why is this code different then what you gave before, which is what I've been trying to make work?

      Frank

      posted in Developers' Forum
      F
      Frankn
    • 1 / 1