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

    davesexcel

    @davesexcel

    10
    Reputation
    1
    Profile views
    51
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    davesexcel Unfollow Follow
    registered-users

    Latest posts made by davesexcel

    • Two different colors to the same shape

      SidesGrey.jpgWith this code I am drawing a box and a box top, I am coloring the box gray and the top blue. I just require the top to be blue, the sides of the top need to be grey.

      l=96
      w=60
      h=60
      heel=8
      slope=4
      clr='Gray'
      rfClr='blue'
      ent = Sketchup.active_model.entities
      	
      		#---------Clear All
      Sketchup.active_model.entities.clear!		
      		#----------------
         model = Sketchup.active_model
      
          model.start_operation "Create Box"
      #-----------------------------------------------------------------------------      
      
          entities = model.active_entities
          group = entities.add_group
          entities = group.entities
             group.name="Box"
          @pt0 = [0, 0, 0]
          @pt1 = [0, l*12, 0]
          @pt2 = [w*12.0, l*12, 0]
          @pt3 = [w*12, 0, 0]
      
      newface = entities.add_face(@pt0, @pt1, @pt2, @pt3)
          newface.material=Sketchup;;Color.new clr
      newface.reverse!
          newface.pushpull h*12
      	    group = entities.add_group
          entities = group.entities
             group.name="Top"
      #-----------Top----------------
          @pt0 = [0, 0, h*12]
          @pt1 = [0, 0, h*12+heel]
          @pt2 = [w*12/2, 0, 12*h+heel+(w/2)*slope]
          @pt3 = [w*12, 0, 12*h+heel]
      	    @pt4 = [w*12, 0, 12*h]
      newface = entities.add_face(@pt0, @pt1, @pt2, @pt3, @pt4)
          newface.material=Sketchup;;Color.new rfClr
      
          newface.pushpull l*12
      
      posted in Developers' Forum
      D
      davesexcel
    • Round an angled edge

      I have not been able to figure out how to round an angled edge, and hope somebody has an idea.
      I use a half inch radius.Regular round noseAngled round nose
      For the straight angle, I draw a 1/2" line down the middle, then add a circle, then push the edge.

      I can draw the line for the angled board, but the circle gets all funky. The second image shows the way the curve should be for the angled board.

      Thanks.


      Sketchup File

      posted in Developers' Forum
      D
      davesexcel
    • RE: Round straight with round ends

      Ah...yes, I didn't think of selecting more than 1 edge, thanks!

      posted in Developers' Forum
      D
      davesexcel
    • Round straight with round ends

      [img]RoundTread3.jpg[/img]I cannot figure out how to round the edge on this , it always stops just before the turn. Follow me does not seem to work for this either.


      RoundTread.skp

      posted in Developers' Forum
      D
      davesexcel
    • RE: Open sketchup from Excel VBA and run ruby code

      Thanks,
      I think I understand the concept, from excel vba we are opening sketchup and passing on a variable that a plugin will recognize to run the plugin?

      posted in Developers' Forum
      D
      davesexcel
    • RE: Open sketchup from Excel VBA and run ruby code

      Thanks Jim,
      SendKeys does work for the interm, ENV variable looks promising, I will have to look into it.

      posted in Developers' Forum
      D
      davesexcel
    • Open sketchup from Excel VBA and run ruby code

      I found this code from google groups it opens sketchup from Excel.

      
      
      Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
      Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
      Sub fLaunchProgram(ByVal sProgram As String)
          Dim ProcessHandle As Long
          Dim ProcessId As Long
          On Error GoTo errExit
          ProcessId = Shell(sProgram, vbNormalFocus)
          ProcessHandle = OpenProcess(&H1F0000, 0, ProcessId)
          WaitForSingleObject ProcessHandle, INFINITE
          Exit Sub
      
      errExit;
          MsgBox "External program " & sProgram & " was not found", vbCritical, " fLaunchProgram"
      End Sub
      'To load SU
      Sub pTest()
          fLaunchProgram ("C;\Program Files\SketchUp\SketchUp 2015\SketchUp.exe")
      End Sub
      
      

      I have assigned the macro to a button, using sendkeys seems to take care of the splash screen when Sketchup opens.

      
      Sub Button1_Click()
          pTest
          SendKeys "~ (tilde)"
          
          'Shell ("C;\Users\dmorrison\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Plugins\GetFromExcel.rb")
      
      End Sub
      
      

      How can I run a plugin from sketchup with vba?

      posted in Developers' Forum
      D
      davesexcel
    • RE: Get data from already opened workbook

      Wow, I got it to work!!

      
      require 'win32ole'
      xl = WIN32OLE;;connect('Excel.Application')
      xl.visible=1
      worksheet = xl.Worksheets(1)
      
      
      
      
      posted in Developers' Forum
      D
      davesexcel
    • RE: Get data from already opened workbook

      Thanks Dan,
      I did find that, just can't get it to work< using all sorts of options, It seems to want to open up a new excel, and not use the existing excel. So it errors when finding the range.

      
        require 'win32ole'
      #WIN32OLE.connect('Excel.Application')
      xl = WIN32OLE;;connect('Excel.Application')
      xl.visible=1
      
      #wb = xl.Workbooks('TestAddImage.xlsm')
      puts "a"
      worksheet = xl.activesheet
      puts "b"
      #worksheet2 = xl.Worksheets('Sheet2')
      puts "c"
      worksheet.Range('a1').Value=1111
      worksheet.Range('a2').Value
      
      
      posted in Developers' Forum
      D
      davesexcel
    • Get data from already opened workbook

      Hi,
      I have a workbook, that I use to input the values for the sketchup to draw. I seems to be working fine but would like it to be able to get the info from the workbook that is already opened, not having to open the workbook to get the data. Is there a way to get the info from an active workbook?

      This way when I run the code, it will get the info and insert the picture onto the sheet.

      
        UI.menu("PlugIns").add_item("Get From Excel") { get_from_excel }
      require('win32ole')
      	 def get_from_excel
      ents=Sketchup.active_model.active_entities
      require 'win32ole'
      
      
      xl = WIN32OLE.new('Excel.Application')
      xl.visible=1
      
      wb = xl.Workbooks.Open('C;\TestFolder\Stair_Info_to_Sketchup.xlsm')
      
      worksheet = wb.Worksheets('Sheet1')
      worksheet2 = wb.Worksheets('Sheet2')
      
      ent = Sketchup.active_model.entities
      Sketchup.active_model.entities.clear!		
      rise=worksheet.range('a2').value
      run=worksheet.range('b2').value
      b=worksheet.range('i2').value
      d=worksheet.range('h2').value
      c=worksheet.range('c2').value
      dado=worksheet.range('d2').value
      ns=worksheet.range('e2').value
      e=worksheet.range('f2').value
      wdth=worksheet.range('g2').value
      tr=7
      g=1.25
      f=worksheet.range('j2').value
      h=0.5
      
      ent.add_line [0,(run+1)+0*run-1.5,rise-c], [0,(1.5+0*run)-1.5,rise-c]  
      ent.add_line [0,1.5+0*run-1.5,rise-c+dado], [0,1.5+0*run-1.5,rise-c]
      ent.add_line [0,1.5+0*run-1.5,rise-c+dado], [0,1+0*run-1.5,rise-c+dado]
      ent.add_line [0,1+0*run-1.5,rise-c+dado], [0,1+0*run-1.5,rise-c]
      edg = ent.add_line [0,1+0*run-(1+0.5),rise-c],[0,e+0*run-(ns+1),rise-c]
      edg = ent.add_line [0,e+0*run-(ns+1),rise-c],[0,e+0*run-(ns+1),rise]
      edg = ent.add_line [0,e+0*run-(ns+1),rise],[0,(run+1)+0*run-1.5,rise]
       edg=ent.add_line [0,1+run-1.5,rise],[0,1+run-1.5,rise-c]
              edg.find_faces; face=edg.faces[0]
                face.pushpull wdth
         group1 = ent.add_group face.all_connected ;group1.name="Tread"
      		  group1.description="Tread"         
      #loop through treads--------------------
      for i in 1..tr-2
        group2 = group1.copy
        tran = Geom;;Transformation.translation [0, run*i, rise*i]
      group2.transform! tran ;group2.name="Treads"
        end
        #---Good
         group = ent.add_group(); group.name="Bottom riser"
       
      ent2 = group.entities
       pts = []
       pts[0] = [0, 0, 0]
       pts[1] = [0,-e,0]
       pts[2] = [0, -e,rise-c+dado]
       pts[3] = [0, 0, rise-c+dado]
       # Add the face to the entities in the model
      face = ent2.add_face pts
       face.pushpull wdth
       group.description = "Bottom riser"
       #---good
       group = ent.add_group(); group.name="Riser"
      ent3 = group.entities
       pts = []
      pts[0] = [0, run, rise-c]
      pts[1] = [0,run-e,rise-c]
       pts[2] = [0, run-e,2*rise-c+dado]
       pts[3] = [0, run, 2*rise-c+dado]
       # Add the face to the entities in the model
      face = ent3.add_face pts
       face.pushpull wdth
      group.description = "Riser"
      
      for i in 1..tr-3
        group2 = group.copy
        tran = Geom;;Transformation.translation [0, run*i, rise*i]
        group2.transform! tran
        end
        #----good
        #<<<<<<Top Hanger
      
      
      
        group = ent.add_group(); group.name="Top riser"
       
         ent5 = group.entities
       ent5.add_line [0,b-2,d-c], [0,b-2,d-(rise+1)]
        ent5.add_line [0,b-2,d-(rise+1)], [0,b-2+h,d-(rise+1)]
        ent5.add_line [0,b-2+h,d-(rise+1)], [0,b-2+h,d]
          edg=ent5.add_line [0,b-2,d-c], [0,b-2-1,d-c]#<<<< edg
        ent5.add_line [0,b-2-1,d-c], [0,b-3,d]
        ent5.add_line [0,b-3,d] , [0,b-2+h,d]
        edg.find_faces; face=edg.faces[0]
        face.pushpull wdth
        
       #<<<<<<<<<<<<<<<Stringer
        
              # offset vectors for rise and run
      		group = ents.add_group(); group.name="Stringer"
      		ent1 = group.entities
      		
              risevect = Geom;;Vector3d.new([0,0,0], [0,0,rise])
              runvect = Geom;;Vector3d.new([0,0,0], [0,run,0])
      	#<<<<<<<<<<<<<<#last tread
              lstrun = Geom;;Vector3d.new([0,0,0], [0,(run-e),0])
      	#<<<<<<<<<<<<<<<<<<<<Move Stringer
      	ms= Geom;;Vector3d.new [(-wdth-g),0,0]
      	ms2= Geom;;Vector3d.new [-wdth/2+g/2,0,0]
      		#<<<routed stringer
        group = ent.add_group(); group.name="Routed Stringer"
       
         ent6 = group.entities
         pts = []
      
         pts[0] = [0,b-(1+e),d]
         pts[1] = [0,b-(4+e),d]
         pts[2] = [0,-3, rise]
         pts[3] = [0, -3, 0]
          #calculate pts 4 & 5
        vec = pts[2].vector_to(pts[1])
        v = vec.axes[1].reverse
        tpt = pts[2].offset(v,f)
        pts[4]=Geom.intersect_line_line [pts[3],[0,1,0]],[tpt,vec]
        #pts[4] = [0,(run+2.5)*0.4256, 0]
        pts[5] = Geom.intersect_line_line [pts[0],[0,0,1]],[tpt,vec]
        #pts[5] = [0, b-(1+e), (d-12 )]
        
             #add the face to the entities in the model
          face = ent6.add_face pts
          face.pushpull g
          group.description = "Routed Stringer"
      	#copy routed stringer
       group1 = group.copy
        tran = Geom;;Transformation.translation ms
      group1.transform! tran
      
      #-----Pictures Insert Code---------------
      
       #require 'win32ole'
       model = Sketchup.active_model
       entities = model.active_entities
       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
       #------------------------------------
      #-----Pictures Insert Code---------------
      pic = worksheet.Pictures.Insert('S;\Stairs\Stair Pics\write_image.jpeg')
      range = worksheet.Range('A5;F20')
      pic.ShapeRange.LockAspectRatio = false
      pic.Top = range.Top
      pic.Left = range.Left
      pic.Width = range.Width
      pic.Height = range.Height
      
      
      end
      
      

      Thanks

      posted in Developers' Forum
      D
      davesexcel