2010年8月14日 星期六

API

開始學習 SketchUp 的 ruby api

1. 文檔存於
c:\Program Files\Google\Google SketchUp [n]\Plugins


2. 畫3d
new_face = Sketchup.active_model.entities.add_face [0, 0, 0], [0, 4, 0], [2, 4, 0], [2, 0, 0]
new_face.pushpull 3

3. 設定模型的位置

Sketchup.active_model.shadow_info["Latitude"]=25.038958406398 Sketchup.active_model.shadow_info["Longitude "]=121.517620663266
3. 由 Latitude / Longitude 轉為 point

point = Sketchup.active_model.latlong_to_point  [-105.28300, 40.01700]

4. to build up use negative number
5. the number is in the unit of cm, not m, so x 100
6. Use () to group stuff


Sketchup.active_model.shadow_info["Longitude"]=121.51689405991
Sketchup.active_model.shadow_info["Latitude"]=25.041991523604


 (Sketchup.active_model.entities.add_face (Sketchup.active_model.latlong_to_point [121.51689405991,25.041991523604]),(Sketchup.active_model.latlong_to_point [121.516845753752,25.041817588114]) , (Sketchup.active_model.latlong_to_point [121.516887788275,25.041807954783]) , (Sketchup.active_model.latlong_to_point [121.516936094488,25.041981890259] )).pushpull -300

Convert from

121.51689405991,25.041991523604,3 121.516845753752,25.041817588114,3 121.516887788275,25.041807954783,3 121.516936094488,25.041981890259,3 121.51689405991,25.041991523604,3


to that

remember to discard the last point.

7. String split

a = "121.51689405991,25.041991523604,3 121.516845753752,25.041817588114,3 121.516887788275,25.041807954783,3 121.516936094488,25.041981890259,3 121.51689405991,25.041991523604,3".split(/ /)

["121.51689405991,25.041991523604,3", "121.516845753752,25.041817588114,3", "121.516887788275,25.041807954783,3", "121.516936094488,25.041981890259,3", "121.51689405991,25.041991523604,3"]

8. Iterate array

a.each {|i| k = i.split(/,/); puts k }


9. l to position model, d to draw a model


def l(s)
   # put the first log lat as the model log/lat
   a = s.split(/ /)
   b = a[0].split(/,/)
  Sketchup.active_model.shadow_info["Longitude"]=b[0].to_f
  Sketchup.active_model.shadow_info["Latitude"]=b[1].to_f
end
def d(s)
   a = s.split(/ /)
   pts =[]
  height = 0
  (a.length-1).times do |i|
      b = a[i].split(/,/)
      height = b[2].to_f * -100
     pts[i] = Sketchup.active_model.latlong_to_point [b[0].to_f, b[1].to_f]
  end
  (Sketchup.active_model.entities.add_face pts).pushpull height
end

def version()
  puts "1.7"
end

沒有留言:

張貼留言