sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Select Style for drawing

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 2 Posters 7.2k Views 2 Watching
    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.
    • U Offline
      UncleString
      last edited by

      Construction Documentation Style.jpgIs there a way to select a style for my drawing?

      I would like it to use "Construction Documentation Style"

      Here is the code I am using to save the image.

      ` model = Sketchup.active_model
      entities = model.active_entities
      Sketchup.send_action("viewIso:")
      view = model.active_view

      Puts in SketchUp install directory by default

      status = view.write_image "test.jpeg"
      keys = {
      :filename => "S:/Stairs/Stair Pics/write_image.jpeg",
      :width => 500,
      :height => 400,
      :antialias => false,
      :compression => 0.5,
      :transparent => false
      }
      model = Sketchup.active_model
      view = model.active_view

      new_view = view.zoom_extents
      view.write_image keys`

      Thanks

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Your code seems to be saving an image of the model.
        And I expect that's not what you want ?

        The API includes several distinct methods for affecting a model's 'Styles'...

        http://ruby.sketchup.com/Sketchup/Styles.html
        http://ruby.sketchup.com/Sketchup/Style.html
        http://ruby.sketchup.com/Sketchup/Page.html#style-instance_method
        http://ruby.sketchup.com/Sketchup/Page.html#use_style%3F-instance_method
        etc

        To 'load' a particular Style you need to get the path to its .style file...
        There are ways to find this in Ruby...
        But on a PC I think it's easy to get through:
        desired_style_file_path = 'C:\ProgramData\SketchUp\SketchUp 2018\SketchUp\Styles\Default Styles\08Construction Documentation Style.style'

        Then use that to set the Style ??

        TIG

        1 Reply Last reply Reply Quote 0
        • U Offline
          UncleString
          last edited by

          Thanks,
          I could not find the actual file location, I was able to right click on the style and save it to a different location, and use that address to for the code.
          While this code does change the style.

          ` model = Sketchup.active_model
          entities = model.active_entities
          Sketchup.send_action("viewIso:")
          view = model.active_view

          #---------------Change Style----------
          filename = File.expand_path('C:\Users\dmorrison\Downloads\08Construction Documentation Style.style')
          styles = Sketchup.active_model.styles
          status = styles.add_style(filename, true)
          #-----------------------------

          Puts in SketchUp install directory by default

          status = view.write_image "test.jpeg"
          keys = {
          :filename => "S:/Stairs/Stair Pics/write_image.jpeg",
          :width => 500,
          :height => 400,
          :antialias => false,
          :compression => 0.5,
          :transparent => false
          }
          model = Sketchup.active_model
          view = model.active_view

          new_view = view.zoom_extents
          view.write_image keys`

          It does not change in my actual plugin.

          The last lines of the plugin to insert the image into excel
          ` #-----Pictures Insert Code---------------

          #require 'win32ole'
          model = Sketchup.active_model
          entities = model.active_entities
          Sketchup.send_action("viewIso:")
          view = model.active_view
          #---------------Change Style----------
          filename = File.expand_path('C:\ProgramData\SketchUp\SketchUp 2015\SketchUp\Styles\Default Styles\08Construction Documentation Style.style')
          styles = Sketchup.active_model.styles
          status = styles.add_style(filename, true)
          #-----------------------------

          Puts in SketchUp install directory by default

          status = view.write_image "test.jpeg"
          keys = {
          :filename => "S:/Stairs/Stair Pics/write_image.jpeg",
          :width => 500,
          :height => 400,
          :antialias => false,
          :compression => 0.5,
          :transparent => false
          }
          model = Sketchup.active_model
          view = model.active_view

          new_view = view.zoom_extents
          view.write_image keys
          #------------------------------------
          worksheet.pictures.delete
          #-----Pictures Insert Code---------------
          pic = worksheet.Pictures.Insert('S:\Stairs\Stair Pics\write_image.jpeg')
          range = worksheet.Range('a14:e32')
          pic.ShapeRange.LockAspectRatio = false
          pic.Top = range.Top
          pic.Left = range.Left
          pic.Width = range.Width
          pic.Height = range.Height`

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            So you have the Style changing as you hope.
            Does your middle code write the images you expect.
            You seemingly pointless " test.jpeg" will go in the current working directory.
            To find that use p Dir.pwd in the Ruby Console...
            It might NOT be the main SketchUp folder...
            Running the code with the Console open might help spot errors etc...

            :filename => "S:/Stairs/Stair Pics/write_image.jpeg",
            will only work if the folder "S:/Stairs/Stair Pics" exists - does it ?

            So is this image getting saved ?

            I suddenly realized that you briefly mention v2015 in your code.
            So the default Styles are [probably] in another location - I only have >=v2017 on this PC so I can't confirm...

            I think that the write_image method using a key only works for PNG files in older SketchUp versions - try that PNG file-type and see if it helps...
            Saving images as a JPG with a key etc are only supported in newer SketchUp versions - in older SketchUp versions you need to pass overloads as arguments listed after the file path...
            See here...
            http://ruby.sketchup.com/Sketchup/View.html#write_image-instance_method

            Also the [#]require 'win32ole' might not work with older SketchUp versions !
            It's only been shipped since the Ruby set up changed...
            In that case you might need to include an equivalent .so in your own subfolder and load that manually ??

            TIG

            1 Reply Last reply Reply Quote 0
            • U Offline
              UncleString
              last edited by

              Thanks Tig,

              The image does end up in excel, but not with the correct style

              Pic in excel

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                What version of SketchUp are you using ?

                Let's break this down into individual steps.

                1. Add and activate Style
                  pause
                2. Export Image
                  pause
                3. Add Image to Excel

                For 1. - does it add and activate the Style as you hope ?

                For 2. - does it export an Image using the expected Style [and view, zoom etc] ? Is the actual JPG file what you want ?

                For 3. - is there a preexisting Image in the Excel file ? Is the Image imported the one seen in 2. ?

                At the moment your "reporting" is clear to you but unclear to the rest of us !

                TIG

                1 Reply Last reply Reply Quote 0
                • U Offline
                  UncleString
                  last edited by

                  Okay, there is something very strange. I spent a lot of time trying to figure out why it would not pause or even show a msgbox as it was going through the code. I commented out the entire code and got nothing, I un-commented just the 1st line and the code produced a drawing, I don't know what code it used as I had all the code commented out.
                  For example
                  ` UI.menu("PlugIns").add_item("Get From Excel") { get_from_excel }

                   # def get_from_excel
                  

                  ents=Sketchup.active_model.active_entities

                  require 'win32ole'

                  xl = WIN32OLE::connect('Excel.Application')

                  workbook = excel.Workbooks('Stair_Info_to_Sketchup')

                  worksheet = workbook.Worksheets(1)

                  ................`

                  How is this possible? I am going to assume it was is obviously running a code from somewhere else, but I can't locate it.

                  1 Reply Last reply Reply Quote 0
                  • U Offline
                    UncleString
                    last edited by

                    I found it, it was a test .rb file, not a plugin but it did have
                    def get_from_excel

                    That is where the plugin was getting the code from.

                    Thank you,
                    The style does change now that I am in the correct code.

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

                    Advertisement