Please Click on QR code to register for the class MIDTERM Examination
Week 10
Week 7
- Material
Link Textures
- File csv format
Link csv wiki
- Ruby Hashes
Link Ruby
- CSI Masterformat and BIM
Link CSI
*******************************
Midterm Examination
Download 2 files
week51.rb
offset.rb
--------------------------------------
and save into folder C:\QTOOLS\API
Run Sketchup
in Ruby console
load "C:\\QTOOLS\\API\\week51.rb"
*******************************
Midterm Question
From menu choose Create building use parameters of yours from above table
Show/Hide Layer for my_column and beam
Delete guides after create building
BOQ mmenu
Please Click on QR code to register for the class MIDTERM Examination
Notepad++ v.5.5
- Create folder C:\QTOOLS\API\ to store all learning materials
- Link download API
- Unnzip into folder above
-
Goto folder C:\QTOOLS\API\SketchupAPI\npp55\
Run file C:\QTOOLS\API\SketchupAPI\npp55\npp.5.5.Installer.exe
Copy file C:\QTOOLS\API\SketchupAPI\ruby.xml
into folder C:\Program Files (x86)\Notepad++\plugins\APIs\
Ruby Language References
Link to web siteWeek 4
# load "C:\\QTOOLS\\API\\week4.rb" #load others rb files load "C:\\QTOOLS\\API\\week2.rb" load "C:\\QTOOLS\\API\\week3.rb" def test p "week4" end def add_point pt = Geom::Point3d.new(10.m,0,0) #create new point model = Sketchup.active_model model.entities.add_cpoint(pt) #add into model end def add_line pt1 = Geom::Point3d.new(0,0,0) pt2 = Geom::Point3d.new(10.m,20.m,4.m) model = Sketchup.active_model model.entities.add_line pt1,pt2 end def add_face pt1 = Geom::Point3d.new(0,0,0) pt2 = Geom::Point3d.new(10.m,20.m,0) pt3 = Geom::Point3d.new(0,20.m,0) model = Sketchup.active_model model.entities.add_face(pt1, pt2, pt3) end def add_room pt1 = Geom::Point3d.new(0,0,0) pt2 = Geom::Point3d.new(4.m,0,0) pt3 = Geom::Point3d.new(4.m,5.m,0) pt4 = Geom::Point3d.new(0,5.m,0) model = Sketchup.active_model face = model.entities.add_face(pt1, pt2, pt3, pt4) face.pushpull 10.cm end def group_add_room pt1 = Geom::Point3d.new(0,0,0) pt2 = Geom::Point3d.new(4.m,0,0) pt3 = Geom::Point3d.new(4.m,5.m,0) pt4 = Geom::Point3d.new(0,5.m,0) model = Sketchup.active_model group = model.entities.add_group face = group.entities.add_face(pt1, pt2, pt3, pt4) face.pushpull 10.cm end def rotate1 model = Sketchup.active_model; selection = model.selection; entity = selection[0]; angle = 45.degrees #radians vector = Geom::Vector3d.new(0,0,1) #Z axis point = Geom::Point3d.new(0,0,0) #origin tr_rotate = Geom::Transformation.rotation point, vector, angle entity.transform!(tr_rotate) end def move1 model = Sketchup.active_model; selection = model.selection; entity = selection[0]; #tr_vector = Geom::Vector3d.new(10.m,2.m,0) tr_vector = Geom::Point3d.new(4.m,0,0) - Geom::Point3d.new(0,0,0) tr_move = Geom::Transformation.translation tr_vector entity.transform!(tr_move) end def scale1 model = Sketchup.active_model; selection = model.selection; entity = selection[0]; xscale = 2 yscale = 2 zscale = 1 point = Geom::Point3d.new(1.m,0,0) #change ref. point tr_scale = Geom::Transformation.scaling point, xscale, yscale, zscale entity.transform!(tr_scale) end def grid1 arr_x = [3,4,5] arr_y = [6,7] point = Geom::Point3d.new(0,0,0) ix = 0 iy = 0 arr_x.each{|dx| puts dx; p "======" }#arr_x end def grid11 arr_x = [3,4,5] arr_y = [6,7] point = Geom::Point3d.new(0,0,0) ix = 0 iy = 0 arr_x.each{|dx| puts dx; p "======" arr_y.each{|dy| puts dy; p "*****" }#arr_y }#arr_x end def grid12 arr_x = [3,4,5] arr_y = [6,7] point = Geom::Point3d.new(0,0,0) ix = 0 iy = 0 point_row = point #ref. point model = Sketchup.active_model arr_x.each{|dx| puts dx; p "======" pt2 = point_row.offset Geom::Vector3d.new(dx.m,0,0) model.entities.add_cpoint(pt2) #add cpoint point_row = pt2 #change ref. point to pt2 } #arr_x end def grid13 arr_x = [0,3,4,5] arr_y = [0,6,7] point_ver = Geom::Point3d.new(10.m,20.m,0) ix = 0 iy = 0 point_row = point_ver #ref. point model = Sketchup.active_model arr_y.each{|dy| point_ver = point_ver.offset Geom::Vector3d.new(0,-dy.m,0) point_row = point_ver #ref. point arr_x.each{|dx| puts dx; p "======" pt2 = point_row.offset Geom::Vector3d.new(dx.m,0,0) model.entities.add_cpoint(pt2) #add cpoint point_row = pt2 #change ref. point to pt2 }#arr_x } #arr_y end def grid14 arr_x = [0,3,4,5] arr_y = [0,6,7] point_ver = Geom::Point3d.new(10.m,20.m,0) ix = 0 iy = 0 point_row = point_ver #ref. point model = Sketchup.active_model #model.start_operation( "Make Grid" , true) arr_y.each{|dy| point_ver = point_ver.offset Geom::Vector3d.new(0,-dy.m,0) point_row = point_ver #ref. point arr_x.each{|dx| puts dx; p "======" pt2 = point_row.offset Geom::Vector3d.new(dx.m,0,0) make_column1(pt2) #add column model.entities.add_cpoint(pt2) #add cpoint point_row = pt2 #change ref. point to pt2 }#arr_x } #arr_y #model.commit_operation end def make_column1(pt) #parameters #dimension of Column dx = 0.4.m dy = 0.3.m dz = 3.m #create points #pt1 = pt pt1 = pt.offset Geom::Vector3d.new((dx * -0.5) ,(dy * -0.5),0) #adjust center point of column pt2 = pt1.offset Geom::Vector3d.new(dx,0,0) pt3 = pt2.offset Geom::Vector3d.new(0,dy,0) pt4 = pt1.offset Geom::Vector3d.new(0,dy,0) #create object column model = Sketchup.active_model group = model.entities.add_group face = group.entities.add_face(pt1, pt2, pt3, pt4) face.pushpull -dz #add layer layer = model.layers.add "my_column" #change layer of group group.layer = layer end def count_group model = Sketchup.active_model; selection = model.selection; arr = []; selection.each{|entity| arr.push entity } count = 0 arr.each{|entity| if (entity.class == Sketchup::Group); group = entity; count = count + 1 end } p "group count =" + count.to_s p "" end
Week 3
%Steel in building partsSteel in Column
# load "C:\\QTOOLS\\API\\week3.rb" def test p "week3" end def make_column #dimension of Column dx = 0.4.m dy = 0.3.m dz = 3.m #create points pt1 = Geom::Point3d.new(0,0,0) pt2 = pt1.offset Geom::Vector3d.new(dx,0,0) pt3 = pt2.offset Geom::Vector3d.new(0,dy,0) pt4 = pt1.offset Geom::Vector3d.new(0,dy,0) #create object column model = Sketchup.active_model group = model.entities.add_group face = group.entities.add_face(pt1, pt2, pt3, pt4) face.pushpull -dz #add layer layer = model.layers.add "my_column" #change layer of group group.layer = layer end def make_beam #dimension of Column dx = 4.m dy = 0.2.m dz = 0.4.m angle = 0.degrees #rotation angle #create points pt1 = Geom::Point3d.new(0,0,0) pt2 = pt1.offset Geom::Vector3d.new(dx,0,0) pt3 = pt2.offset Geom::Vector3d.new(0,dy,0) pt4 = pt1.offset Geom::Vector3d.new(0,dy,0) #create object column model = Sketchup.active_model group = model.entities.add_group face = group.entities.add_face(pt1, pt2, pt3, pt4) face.pushpull dz tr_rotate = Geom::Transformation.rotation pt1, Geom::Vector3d.new(0,0,1), angle group.transform!(tr_rotate) #add layer layer = model.layers.add "my_beam" #change layer of group group.layer = layer end def move_object #parameters from user prompts = ["dx [m.]" , "dy [m.]" , "dz [m.]"]; defaults = ["1" , "1" , "1"]; input = UI.inputbox prompts, defaults, "Enter dx,dy,dz." #return as array #distance of be move dx = input[0].to_f.m dy = input[1].to_f.m dz = input[2].to_f.m model = Sketchup.active_model; selection = model.selection; entity = selection[0]; tr_vector = Geom::Vector3d.new(dx,dy,dz) tr_move = Geom::Transformation.translation tr_vector entity.transform!(tr_move) end
Week 2
Download file boq1.skp and save in folder C:\QTOOLS\API\Week 1:Basic Sketchup And Ruby API
Objectives:1.Understand Sketchup's basic model concept edge , face, group, component
2.Understand relation between Sketchup model and Ruby API
3.How to count objects ,edges , faces, groups, components, in model with its properties such as length , area
# load "C:\\QTOOLS\\API\\week1.rb" def count_object model = Sketchup.active_model; selection = model.selection; entity = selection[0]; if (entity.class == Sketchup::Edge); edge = entity; p edge end if (entity.class == Sketchup::Face); face = entity; p face end if (entity.class == Sketchup::Group); group = entity; p group end if (entity.class == Sketchup::ComponentInstance); component = entity; p component end endEnd of Week 1