- UID
- 256
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-11
- 最后登录
- 1970-1-1
|
发表于 2005-4-16 15:49:55
|
显示全部楼层
我把这个插件汉化一下并把原来的英寸单位改面毫米,安装后在“绘图”菜单最下面增加一个“参数开窗”。
上传不了附件!!下面是源文件 :
#=========================================
require 'sketchup.rb'
def find_face(face1,face2,discard)
# UI.messagebox("Got this far")
face1edges=face1.edges
face2edges=face2.edges
0.upto(3) do |a|
0.upto(3) do |b|
if ((face1edges[a] != face2edges) and (face1edges[a].common_face(face2edges) != discard ))
if ((face1edges[a].common_face(face2edges) != face1) and (face1edges[a].common_face(face2edges) != face2))
if (face1edges[a].common_face(face2edges))
@face = face1edges[a].common_face(face2edges)
end
end
end
end
end
end
def find_lowPoints(face)
fVerts=face.vertices
low1=fVerts[0]
low2=low1
0.upto(3) do |a|
fVertsZ1=fVerts[a].position[2]
if (fVertsZ1 <= low2.position[2])
low2=fVerts[a]
end
if (fVertsZ1 <= low1.position[2])
low2=low1
low1=fVerts[a]
end
end
0.upto(3) do |a|
edge=face.edges[a]
if ((edge.used_by?(low1)) && (edge.used_by?(low2)))
@lowE=a
end
end
end
def insetPaint(face)
faceEdges = face.edges #Select edges so we know where we've been
face.pushpull (-@glassinset) #Inset the glass
discard=faceEdges[0].faces[0] #These lines find the new inset face
face1=faceEdges[0].faces[1] # |
face2=faceEdges[1].faces[1] # |
face=nil # |
find_face(face1,face2,discard) #_V____
@face.material=@glasscolor #Paint the new inset face
end
def do_window
# CHECK THE SELECTIONS!
model = Sketchup.active_model
@item = model.selection
entities = model.active_entities
materials=model.materials
# ALLOW ONLY ONE SELECTED FACE
if (((@item.length != 1) || (@item.first.class != Sketchup::Face)) || (@item.first.edges.length != 4))
@item.clear
UI.messagebox("请选择一个独立的4边面!")
end
return if @item.empty?
# ALLOW ONLY FACE-IN-A-FACE
if ((model.selection.first.edges[0].faces != model.selection.first.edges[1].faces) && (model.selection.first.edges[1].faces != model.selection.first.edges[2].faces) && (model.selection.first.edges[2].faces != model.selection.first.edges[3].faces) && (model.selection.first.edges[3].faces != model.selection.first.edges[0].faces))
@item.clear
UI.messagebox("请选择一个未与其它面关联的独立4边面!")
end
return if @item.empty?
if (@framecolor == nil)
@vPanes = 2
@hPanes = 2
@framewidth = 50.mm
@frameheight = 50.mm
@frameinset = 80.mm
@glassinset = 20.mm
@framecolor = "DimGray"
@glasscolor = "abu_Glass"
end
# Prompt the user for the Windowizer settings
prompts = ["行数 ", "列数 ", "窗框宽度 ", "窗框高度 ", "窗框深度 ", "玻璃深度 ", "窗框颜色 ", "玻璃颜色 "]
values = [@vPanes, @hPanes, @framewidth, @frameheight, @frameinset, @glassinset, @framecolor, @glasscolor]
results = inputbox prompts, values, "参数 "
return if not results
@vPanes = results[0]
@hPanes = results[1]
@framewidth = results[2]
@frameheight = results[3]
@frameinset = results[4]
@glassinset = results[5]
@framecolor = results[6]
@glasscolor = results[7]
@vPanes = 1 if @vPanes < 1
@hPanes = 1 if @hPanes < 1
@frameinset = 1 if @frameinset == 0
@glassinset = 1 if @glassinset == 0
model.start_operation "Windowizer"
# ADD THE GLASS PAINT
if (materials["abu_Glass"] == nil)
glass=materials.add("abu_Glass")
glass.color=[176,224,230]
glass.alpha=0.75
end
face = @item.first
@faceEdges = face.edges #Select edges so we know where we've been
face.pushpull (-@frameinset) #Inset the frame
faceEdges = []
0.upto(3) do |a|
faceEdges[faceEdges.length]=@faceEdges[a] if (@faceEdges[a].valid?) #Pass valid edges to new handler
end
if (faceEdges.length < 2) #Not enough edges to determine where we need to go
UI.messagebox("Sorry, cannot continue - need 2 old edges left from push-pull")
# model.commit_operation
return
end
discard=faceEdges[0].faces[0] #These lines find the new inset face
face1=faceEdges[0].faces[1] # |
face2=faceEdges[1].faces[1] # |
find_face(face1,face2,discard) #_V____
@face.material=@framecolor #Paint the new inset face
discard = nil
discard = @face #the inset face is now the discard for the window panes
find_lowPoints(@face)
@edge1=@face.edges[@lowE] #Put the face edges in a usable order
@edge2=@face.edges[@lowE-3]
@edge3=@face.edges[@lowE-2]
@edge4=@face.edges[@lowE-1]
@hLength1=((@edge1.length-@framewidth)/@hPanes)-@framewidth #Glass length, bottom edge
@hLength2=((@edge3.length-@framewidth)/@hPanes)-@framewidth #Glass length, top edge
@vLength1=((@edge4.length-@frameheight)/@vPanes)-@frameheight #Glass length, left edge
@vLength2=((@edge2.length-@frameheight)/@vPanes)-@frameheight #Glass length, right edge
if (@edge4.used_by?(@edge1.start))
@hpt1=Geom::Point3d.new(@edge1.start.position)
else
@hpt1=Geom::Point3d.new(@edge1.end.position)
end
0.upto(3) do |a|
if (@face.vertices[a].position == @hpt1)
@hpt2=Geom::Point3d.new(@face.vertices[a-3].position)
@hpt3=Geom::Point3d.new(@face.vertices[a-1].position)
@hpt4=Geom::Point3d.new(@face.vertices[a-2].position)
end
end
if (@edge1.start.position == @hpt1)
@hVec1=@edge1.line[1]
else
@hVec1=@edge1.line[1].reverse
end
if (@edge3.start.position == @hpt4)
@hVec2=@edge3.line[1].reverse
else
@hVec2=@edge3.line[1]
end
if (@edge4.start.position == @hpt3)
@vVec1=@edge4.line[1].reverse
else
@vVec1=@edge4.line[1]
end
if (@edge2.start.position == @hpt2)
@vVec2=@edge2.line[1]
else
@vVec2=@edge2.line[1].reverse
end
1.upto(@vPanes) do |n|
1.upto(@hPanes) do |m|
@hpt1x=@hpt1.offset(@hVec1, ((@framewidth*m)+(@hLength1 * (m-1))))
@hpt2x=@hpt1.offset(@hVec1, ((@framewidth*m)+(@hLength1 * m)))
@hpt3x=@hpt3.offset(@hVec2, ((@framewidth*m)+(@hLength2 * (m-1))))
@hpt4x=@hpt3.offset(@hVec2, ((@framewidth*m)+(@hLength2 * m)))
@vpt1x=@hpt1.offset(@vVec1, ((@frameheight*n)+(@vLength1 * (n-1))))
@vpt2x=@hpt1.offset(@vVec1, ((@frameheight*n)+(@vLength1 * n)))
@vpt3x=@hpt2.offset(@vVec2, ((@frameheight*n)+(@vLength2 * (n-1))))
@vpt4x=@hpt2.offset(@vVec2, ((@frameheight*n)+(@vLength2 * n)))
@line1=[Geom::Point3d.new(@hpt1x), Geom::Point3d.new(@hpt3x)]
@line2=[Geom::Point3d.new(@hpt2x), Geom::Point3d.new(@hpt4x)]
@line3=[Geom::Point3d.new(@vpt1x), Geom::Point3d.new(@vpt3x)]
@line4=[Geom::Point3d.new(@vpt2x), Geom::Point3d.new(@vpt4x)]
@pt0=Geom.intersect_line_line(@line1, @line3)
@pt1=Geom.intersect_line_line(@line2, @line3)
@pt2=Geom.intersect_line_line(@line2, @line4)
@pt3=Geom.intersect_line_line(@line1, @line4)
pts = []
pts[0] = @pt0
pts[1] = @pt1
pts[2] = @pt2
pts[3] = @pt3
face = entities.add_face pts
insetPaint(face)
end
end
model.commit_operation
end
if( not file_loaded?("cwindowizer.rb") )
# This will add a separator to the menu, but only once
add_separator_to_menu("Draw")
# To add an item to a menu, you identify the menu, and then
# provide a title to display and a block to execute. In this case,
# the block just calls the create_box function
UI.menu("Draw").add_item("参数开窗 ") { do_window }
end
#-----------------------------------------------------------------------------
file_loaded("cwindowizer.rb")
#----------------------------------------------------------------- |
|