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
    • Retrieving bounding box corners Point3d

      I'm working on a placement tool and trying to determine which corner is which of the bounding box using the cursor... here's the code I came up with to try and do that...

      Iterate selection...

      		
      @bbox_points_array=[]
      @coord=[]
      @selection.each{|entity|
       if entity.parent==@model
        parent=entity
        old_comp_origin=parent.transformation.origin
        trans=entity.transformation.to_a
        vector=Geom;;Vector3d.new(trans[0], trans[4], trans[8])
      			
        if trans[1]<0
         multiplier=-1
        else
         multiplier=1
        end 
      
        old_comp_angle=((X_AXIS.angle_between(vector)).radians)*multiplier
        @coord << old_comp_origin << old_comp_angle << parent
      			
        parent_bounding_box=parent.bounds
        for i in 0..7
         point=parent_bounding_box.corner(i)
         @bbox_points_array << point.to_a
        end
      end
      
      

      ... then use I use the cursor input point and compare it to the array I created above to see if there's a match... I round the decimals just to make them more legible...

      			
      cursor_input_point=@ip.position.to_a
      corner=0
      @bb_corner=[]
      @main_module.bbox_point3d.each{|bbox_corner|
       bbox_input_point_array=[bbox_corner[0].round(6), bbox_corner[1].round(6), bbox_corner[2].round(6)]
      
       cursor_input_point_array=[cursor_input_point[0].round(6), cursor_input_point[1].round(6), cursor_input_point[2].round(6)]
      
       if bbox_input_point_array==cursor_input_point_array
        @bb_corner << corner
       end
        corner+=1
      }
      
      

      This works as long as the component is aligned with one of the axes if it's rotated ie: 45deg, the array point3ds are all off. I suspect this is due to the transformation that is applied to the component but I have no idea how to fix it.

      Here's an example of an array with the compoent aligned on the x axis at origin [0, 0, 0]...

      [[0.0, 0.0, 0.0], [22.000000000000007, 0.0, 0.0], [0.0, 22.000000000000007, 0.0], [22.000000000000007, 22.000000000000007, 0.0], [0.0, 0.0, 22.0], [22.000000000000007, 0.0, 22.0], [0.0, 22.000000000000007, 22.0], [22.000000000000007, 22.000000000000007, 22.0]]
      

      and the same component rotated 45deg...

      [[-15.55634918610406, -5.024295867788081e-15, 0.0], [15.556349186104041, -5.024295867788081e-15, 0.0], [-15.55634918610406, 31.112698372208097, 0.0], [15.556349186104041, 31.112698372208097, 0.0], [-15.55634918610406, -5.024295867788081e-15, 22.0], [15.556349186104041, -5.024295867788081e-15, 22.0], [-15.55634918610406, 31.112698372208097, 22.0], [15.556349186104041, 31.112698372208097, 22.0]]
      

      Any ideas or suggestions?

      posted in Developers' Forum
      F
      Frankn
    • RE: Escaping out of editing a component

      UUgghhh never thought of searching for something with 'close' in it kept thinking 'escape'!

      Thanks Tig! You da man... well tiger!

      This is the code I'm using... anything more efficient?

      while @model.active_entities!=@model.entities
             @model.close_active
      end
      
      posted in Developers' Forum
      F
      Frankn
    • Escaping out of editing a component

      Sorry if this has been asked before but I searched and can't find an answer... though admittedly I'm not sure what to search for so I'll explain it best as I can...

      When editing a group or component we can use the escape key to exit 'edit mode'... is there a way to do this with ruby? I tried

      @model.selection.clear 
      

      but that doesn't work. I included a picture to help explain what I mean.
      selection.jpg

      posted in Developers' Forum
      F
      Frankn
    • RE: Iterate selection

      Thanks Anton_s!
      Even though I'm still trying to figure out what and how your code works it does work perfectly! πŸ˜„

      posted in Developers' Forum
      F
      Frankn
    • Iterate selection

      As the title implies I'm trying to iterate a selected component to retrieve the subcomponents. I use this code to iterate the whole model but can't figure out how to do it for only selected components.

      @component_list=definitions.find_all() {|e| e.entities.find()}.map() {|e| e.instances }.flatten

      posted in Developers' Forum
      F
      Frankn
    • RE: Sketchup2014 - undefined method `GetString'

      @dan rathbun said:

      FILES. One file for each language:

      %(#004000)["Plugins/FN_CabinetBuilder/Resources/en-US/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/fr/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/zh-CN/cabBuilder.str" "Plugins/FN_CabinetBuilder/Resources/zh-TW/cabBuilder.str"]

      @frankn said:

      ... and use .GetString to retrieve the proper language?

      Yes, or [] for SketchUp 2014+.

      Ok gotcha for the files, thanks Dan.

      As far as using .GetString or [], does .GetString still work in 2014 so that it's compatible with older versions of Sketchup?

      Later on when I'm done with my plugin(yeah right!) this might be something cool to add as a feature.

      Thanks again for the info!

      posted in Developers' Forum
      F
      Frankn
    • RE: Sketchup2014 - undefined method `GetString'

      Thanks for the replies and help guys!

      So I read up on LanguageHandler and looked at LangHandler.rb, utilities.rb and utilities.string. From my understanding what LanguageHandler is used for is if you want the plugin to be multilingual?

      So if someone wanted there plugin to be readable in English, French and Chinese he would create the appropriate .string file to translate between languages and use .GetString to retrieve the proper language?

      I haven't had time to test this so I might be way off track here... 😳

      But all this made me realize that I don't need LanguageHandler to get what I want done, for now anyways. Everytime I think I'm done with my plugin I think of other things to add to complicate my life. πŸ’š

      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Sketchup2014 - undefined method `GetString'

      @dan rathbun said:

      $uStrings is only defined IF the user has installed the Utilities plugin.
      Since SU2013, it no longer distros with SketchUp. Users must explicitly install it from the Extension Warehouse.

      ALSO... it is bad programming etiquette to create global vars for use by a single plugin.
      We have been bitchin' at the Trimble team to move their myraid of global vars into their plugin namespaces as class/module vars.
      SO.. you should not rely upon global vars created by other plugins (even SketchUp team plugins.)

      If you need to access any of the Resources strings files, you can do so temporarily, and store the strings your plugin uses, in a hash inside your plugin's namespace.

      @say = Hash.new {|hash, key| key }
      > 
      > lf = LanguageHandler.new("utilities.strings")
      > @say["Name;"]= lf.GetString("Name;")
      > 
      > lf = LanguageHandler.new("Components.strings")
      > @say["Components"]= lf.GetString("Components")
      > 
      > lf = LanguageHandler.new("examples.strings")
      > @say["Width"]= lf.GetString("Width")
      > @say["Height"]= lf.GetString("Height")
      > @say["Depth"]= lf.GetString("Depth")
      > 
      > lf = nil # release the last LanguageHandler object for GC
      > 
      > # use them later in your code;
      > 
      > msg << "#{@say["Name;"]} #{(selected_comp_name)}"
      > 
      > 
      

      HOWEVER.. I just noticed that the "utilities.strings" file (and therefore the $uStrings object, does NOT have an entry "Name:" !!!

      Did you think that a LanguageHandler hash-wrapper object would just magically contain the strings you need ?

      It does not work like that. You have to create the translations for all the strings files that your plugin will need.

      Thanks for the reply Dan,

      This part of the code is from the querytool plugin and other then changing a few things to play around with and try and learn ,like adding "Name:", I never got around to doing much with it and like I said this worked in other versions of sketchup including 2013 ,so yeah magically everything worked till now without me having to do much at all. πŸ’š πŸ˜‰

      From your reply, which honestly for a non programmer half hack like me is more confusing then my original question, ha!, if I check out the utilities plugin it's a good example of how LanguageHandler works?

      Looks like I'll be learning something new once again!

      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Sketchup2014 - undefined method `GetString'

      @chris fullmer said:

      That means it is calling "GetString" on a nil object. It would have been a little more helpful if you posted the full error message. But essentially it gave you a line number in there. On that line, you are calling GetString. At that moment, what ever you are calling getstring on, is nil. And getstring is not a method for the nil object. Does that help?

      If you post the full error message, I could help determine what line is actually the problem line.

      Chris

      Hi Chris,
      My bad, here's the full error message...
      Error: #<NoMethodError: undefined method GetString' for nil:NilClass> C:/Users/Frank/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/FN/CabinetBuilder/cabBuilder.rb:4245:in onMouseMove'

      And here's the actual line of code...

      msg << $uStrings.GetString("Name;") + " #{(selected_comp_name)}"
      

      Weird thing is in all the other versions of Sketchup I don't get the error message and everything works fine.

      posted in Developers' Forum
      F
      Frankn
    • Sketchup2014 - undefined method `GetString'

      I've downloaded Sketchup2014 and tried running the plugin I'm working on but, as the title suggests, I get Error: #<NoMethodError: undefined method `GetString' for nil:NilClass>.

      I searched for a solution and the only thing I could find was in this thread but no solution was given...
      http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=9460%26amp;p=464586%26amp;hilit=getstring#p464586

      posted in Developers' Forum
      F
      Frankn
    • RE: [code] ComponentDefinition-delete (another version!)

      @tig said:

      It's ' commit_operation' NOT ' confirm_operation' - my typo 😳 - it's now corrected in my earlier code...
      You can manually select objects including instances, and just the instances' definitions will be processed.
      You can only add 'entities' to a Selection [like geometry or instances] in code.
      NOT a 'definition' - which is NOT an 'entity'... πŸ˜•

      Thanks you sir! That works perfectly! I should of caught that but I just figured it was a command I didn't know of yet! 😳 πŸ˜„

      posted in Developers' Forum
      F
      Frankn
    • RE: [code] ComponentDefinition-delete (another version!)

      Here's something interesting/weird that's happening...

      After I delete the definition I iterate through model.definitions just to make sure everything was getting deleted but I found that the parent instance isn't getting deleted and the names of the subcomponents aren't getting deleted either... which causes the new component being created to be renamed with #1 at the end...

      Any idea why?

      posted in Developers' Forum
      F
      Frankn
    • RE: [code] ComponentDefinition-delete (another version!)

      Ok so after a beer break I figured out why I couldn't select the instance... I was trying to select the definition! 😳

      When I comment out m.confirm_operation everything seems to work but obviously there's something wrong with the code or I wouldn't need to comment it out.

      posted in Developers' Forum
      F
      Frankn
    • RE: [code] ComponentDefinition-delete (another version!)

      Thanks TIG,

      The second code is what I'm looking to do but I'm getting this error...
      Error: #<NoMethodError: undefined method `confirm_operation' for #Sketchup::Model:0x8e9a4b4>

      Also I tried selecting the definition I want to delete with this but it doesn't seem to work

      @model.selection.add(#<Sketchup;;ComponentDefinition;0xbcd77a0>)
      

      I forgot to mention that if I manually select the instance it does delete it and the parent from the components viewer but leaves the subcomponents.

      I'm still trying to figure out what your code does, this is a little over my pay grade! πŸ˜•

      posted in Developers' Forum
      F
      Frankn
    • RE: [code] ComponentDefinition-delete (another version!)

      @tig said:

      it has been discovered how to do what we want anyway without a new method at all...

      Sorry to bring back a very old post/topic but I'm trying to delete definitions and I tried using the code AlexMozg wrote but I'm having problems with it and to be honest I don't really understand how the code works so I'm not sure what's going wrong.

      The error I get is... Error: #<TypeError: reference to deleted ComponentDefinition>

      Is there another way to do this if not what should I be looking for in regards to the problem I'm having?

      Thanks.

      posted in Developers' Forum
      F
      Frankn
    • RE: Using each_slice possible?

      @dan rathbun said:

      @frankn said:

      Now I'm having the same problem with "delete_if!"

      That is because the method's name is delete_if.

      There is no exclamation point name.

      I was actually using the ! as punctuation not in my code.

      BUT reading your post made me realize I had made typo somewhere else in my code causing the error.

      Thanks again for your help sir.

      posted in Developers' Forum
      F
      Frankn
    • RE: Using each_slice possible?

      Thanks Dan that works awesome!

      Now I'm having the same problem with delete_if! Isn't there an addon or file we can download to get the missing methods? If not how do you know figure out how to make new ones as you did? I don't want to have to bother anyone the next time I get a similar error if I can fix it myself.

      posted in Developers' Forum
      F
      Frankn
    • RE: Using each_slice possible?

      Thanks Dan!
      But I get this error now...
      Error: #<NoMethodError: undefined method `abs' for Math:Module>

      posted in Developers' Forum
      F
      Frankn
    • Using each_slice possible?

      I have a feeling this is a stupid question but I can't find the answer!

      I need to use each_slice in a plugin I'm working on but can't get it to work... I keep getting Error: #<NoMethodError: undefined method `each_slice' for #Array:0xc6c8c14>.

      Thanks in advance!

      Frank

      posted in Developers' Forum
      F
      Frankn
    • RE: Pushpull/move a component instance's face

      @unknownuser said:

      ](http://www.sketchup.com/intl/en/developer/docs/ourdoc/face#reverse!)

      I had seen that but I never tried it thinking it was like the Skethup function 'reverse faces' which turns the face from purple to white. 😳

      No I guess not... that will change the faces for ALL instances. (Remember that it is the Definition that owns the component entities, not the instances. ALL instances share the same entities collection from their parent definition.)

      Actually that works in my situation because I make all my instances unique... but I'm just starting to play around with this and might run into problems later. πŸ˜‰

      edit: just took a closer look at my model and yes it does turn the face from white to purple doing exactly like the Sketchup function. So yes it works but not the ideal solution.

      posted in Developers' Forum
      F
      Frankn
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 2 / 6