วันอาทิตย์ที่ 20 พฤศจิกายน พ.ศ. 2559

โค้ดตัวอย่างการใช้ฟังก์ชั่น Follow Me [Ruby Sketchup]



โค้ดตัวอย่างการเขียนปลั้กอินสเกตอัพด้วยภาษา Ruby สร้างเส้นและหน้าตัดแล้วใช้คำสั่ง Follow Me เพื่อดึงหน้าตัดวิ่งไปตามแนวเส้นนำ


mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
model = Sketchup.active_model
entities = model.active_entities
# Add the group to the entities in the model
 group1 = entities.add_group
 # Get the entities within the group
 entities1 = group1.entities

  D = 0.012
  Re = (6*D*0.5+D*0.5)
  W = 1.00
  H = 0.50
  
  # C
  Wx = (W*0.5)
  Wy = (Wx-Re)
  
  # Points Line
  pt1 = [ -Wx.m, 0, -H.m]
  pt2 = [ -Wx.m, 0, -Re.m]
  pt3 = [ -Wy.m, 0, 0]
  pt4 = [ Wy.m, 0, 0]
  pt5 = [ Wx.m, 0, -Re.m]
  pt6 = [ Wx.m, 0, -H.m]
  
  # Follow Me profile 
  centerpoint = [ -Wx.m, 0, -H.m]
  vector = Geom::Vector3d.new 0,0,-1
  vector2 = vector.normalize!
  model = Sketchup.active_model
  entities = model.active_entities
  edges = entities1.add_circle centerpoint, vector2, D*0.5.m
  face = entities1.add_face edges
  
  path = []
  
  Ver1 = [1,0,0]
  Ver2 = [0,1,0]
  ptc1 = [ -Wy.m, 0, -Re.m]
  ptc2 = [ Wy.m, 0, -Re.m]
  # Follow Me Line
  group2 = entities.add_group
  entities2 = group2.entities
  Line1 = entities2.add_line pt1, pt2
  Line2 = entities2.add_arc ptc1, Ver1, Ver2, Re.m, 180.degrees, 270.degrees
  Line3 = entities2.add_line pt3, pt4
  Line4 = entities2.add_arc ptc2, Ver1, Ver2, Re.m, 270.degrees, 360.degrees
  Line5 = entities2.add_line pt5, pt6
  
  # Follow Me Run
  status = face.followme(Line1, Line2, Line3, Line4, Line5)
  entities.erase_entities group2
  
  group1.name = "A Line"

group1.set_attribute 'dynamic_attributes', 'Oname', '2'
group1.set_attribute 'dynamic_attributes', 'Onum', '145'
group1.set_attribute 'dynamic_attributes', 'Onum', '145'
group1.set_attribute 'dynamic_attributes', 'Otype', 'Footing'
group1.set_attribute 'dynamic_attributes', 'Ounit', 'kg.'

fsel = mod.selection.first # first selected object 
att = fsel.get_attribute("dynamic_attributes", "Otype")


       
 

Disqus Comments