Google Sketchup Script IDE 讓你更方便測試你的程式

Sketchup 是一個非常好用直覺化的繪圖程式,台灣翻譯成 草圖大師,在被 Google 併購之後提供個人用免費版本,他簡單易用的程度可以這麼說,如果你會使用 AutoCAD 可以在一兩天內就可以學會 Sketchup ,AutoCAD 有提供LISP VBA C++ 作為第三方開發,也提供一個陽春的IDE方便作為撰寫測試程式,而Sketchup 並沒有提供類似的 IDE ,測試的時候要不斷重啟 Sketchup 主程式非常不方便,當然網路上也有很多關於Ruby的開發工具可用,現在有個好消息 這位大大 提供了一個簡易的 IDE ,不用橋接他是直接以Ruby 開發的。

作者網站 : http://www.alexschreyer.net/projects/sketchup-ruby-code-editor/

你下載 SketchUp Ruby Code Editor v.2.0 之後複製到Sketchup0 裝目錄下的 Plugin 資料夾就可以用了。


如上圖點選 Window\Ruby Code Editor\




測試的時候就不用重啟 Sketchup 主程式了,非常方便好用。




那Sketchup API 要在哪邊查詢?  可以到 http://code.google.com/intl/zh-TW/apis/sketchup/docs/index.html 這邊閱讀相關文件 。

這邊有一個從官網範例改寫很簡單的小程式,你可以存成 draw_stairs.rb 試試如何使用這個IDE... 非常方便好用

# First we pull in the standard API hooks.
require 'sketchup.rb'

# Show the Ruby Console at startup so we can
# see any programming errors we may make.
#Sketchup.send_action "showRubyPanel:"

# Add a menu item to launch our plugin.
#UI.menu("PlugIns").add_item("Draw stairs") {
#  draw_stairs 
#}

def draw_stairs

  # Create some variables.
  stairs = 10
  rise = 8
  run = 12
  width = 1800.mm
  thickness = 30.mm

  # Get handles to our model and the Entities collection it contains.
  model = Sketchup.active_model
  entities = model.entities

  # Loop across the same code several times
  for step in 1..stairs
    
    # Calculate our stair corners.
    x1 = 0
    x2 = width
    y1 = run * step
    y2 = run * (step + 1)
    z = rise * step
    
    # Create a series of "points", each a 3-item array containing x, y, and z.
    pt1 = [x1, y1, z]
    pt2 = [x2, y1, z]
    pt3 = [x2, y2, z]
    pt4 = [x1, y2, z]

    # Call methods on the Entities collection to draw stuff.
    new_face = entities.add_face pt1, pt2, pt3, pt4
    new_face.pushpull thickness
  end

end
draw_stairs 


留言

熱門文章