Use area to get length from groups,don't use the edge

mod = Sketchup.active_model # 打开模型
ent = mod.entities # 模型中的所有实体
sel = mod.selection # 当前选择
def min(*args)
   args.min
end

def max(*args)
   args.max
end
dn=1
sel.each do | e |
 if e.is_a? Sketchup::Group
 e.name=dn.to_s
 dn=dn+1
 end
end

chosen_image = UI.savepanel("保存", mod.path, "csv|*.csv|txt|*.txt||")
puts chosen_image
 p=mod.path.gsub(/.skp$/,'_TMY.csv')
#f=File.open(p,'w')
sel.each do | e |
 if e.is_a? Sketchup::Group
    #puts e.length
    grp=e
    
    pt=grp.bounds.max
    pt1=grp.bounds.min
    w=grp.bounds.width
    h=grp.bounds.height
    d=grp.bounds.depth
    temp0=max(w,h,d)
    #最大数 temp0
    temp2=min(w,h,d)
    #最小数
    if w<temp0 then
      if w> temp2 then
      temp1=w
      end
    end
   if h<temp0 then
      if h> temp2 then
      temp1=h
      end
    end
    if d<temp0 then
      if d> temp2 then
      temp1=d
      end
    end  
    #temp1 中间数
     tn1=0
     tn2=0
    grp.entities.each do | e1 |
        if e1.is_a? Sketchup::Edge
           if e1.length == temp2 then
             if h> w
              x1, y1, z1 = e1.start.position.to_a
              #纵向
	          x2, y2, z2 = grp.bounds.corner(0).to_a
              if x1==x2 and y1 == y2 and z1 != z2
              Tn1=z1-z2
              UI.messagebox Tn1.to_mm
              end
	          
              x2, y2, z2 = grp.bounds.corner(6).to_a
              if x1==x2 and y1 == y2  and z1 != z2
              Tn2=z2-z1
              UI.messagebox Tn2.to_mm
              #puts Tn2.to_mm  
              end
              
             
             end
             if w > h then
              #水平
              x1, y1, z1 = e1.start.position.to_a
              x2, y2, z2 = grp.bounds.corner(4).to_a
              #puts x1
              #puts x2
              if y1==y2 and z1==z2 and x1!=x2
              #puts z1
              #puts z2
              
              Tn1=x1-x2
              UI.messagebox Tn1.to_mm
              end
	          
              x2, y2, z2 = grp.bounds.corner(7).to_a
              if y1==y2 and z1==z2 and x1!=x2
              
              Tn2=x2-x1
              UI.messagebox Tn2.to_mm
              #puts Tn2.to_mm  
             end
              
             end
              #puts Tn2.to_mm  
             
            end
         end
      end
      
      # ste=grp.name+",X:"+(pt[0]-pt1[0]).to_mm.round(2).to_s+"mm,"+"Y:"+(pt[1]-pt1[1]).to_mm.round(2).to_s+"mm," +"Z:"+(pt[2]-pt1[2]).to_mm.round(2).to_s+"mm"+",N1="+Tn1.to_s+",N2="+Tn2.to_s
      # f.puts ste
  end
end

will get the data of copper busbar bending
just get group (not move ) can
Tn1 and Tn2
if move the group ,the edges start point and end point no changes.
so …

I’m not entirely sure if I understand the question, but let me try;

1 You have a group with some edges.
2. You check the position of the edges
3. You move the group
4. You expect the position of the edges to update?

Entities in groups and components have coordinates local to that group/component. So if you move the group the local coordinates of the entities inside doesn’t change.

You would have to apply the transformation of the group to the local coordinates in order to get the global coordinates.

# Select a group with some edges:
model = Sketchup.active_model
group = model.selection.grep(Sketchup::Group).first
edge = group.entities.grep(Sketchup::Edge).first

puts "Before move:"

puts "Local coordinates:"
p edge.vertices.map(&:position)

puts "Global coordinates:"
p edge.vertices.map(&:position).map { |pt| pt.transform(group.transformation) }

tr = Geom::Transformation.new(Geom::Vector3d.new(10, 0, 0))
group.transform!(tr)

puts "After move:"

puts "Local coordinates:"
p edge.vertices.map(&:position)

puts "Global coordinates:"
p edge.vertices.map(&:position).map { |pt| pt.transform(group.transformation) }

nil

Output:

Before move:

Local coordinates:
[Point3d(0, 79.3307, 0), Point3d(0, 0, 0)]

Global coordinates:
[Point3d(7.25321, 167.974, 0), Point3d(7.25321, 88.6432, 0)]

After move:

Local coordinates:
[Point3d(0, 79.3307, 0), Point3d(0, 0, 0)]

Global coordinates:
[Point3d(17.2532, 167.974, 0), Point3d(17.2532, 88.6432, 0)]
2 Likes

Some ideas:


sel.each do | e |
  if e.is_a? Sketchup::Group
    grp = e
    # ...

Can be better done as:

sel.grep(Sketchup::Group) do | grp |
  # ...

(You save an indentation.)


    if w<temp0 then
      if w> temp2 then
        temp1=w
      end
    end

Can be done as:

    temp1 = w if w < temp0 && w > temp

    grp.entities.each do | e1 |
      if e1.is_a? Sketchup::Edge
        if e1.length == temp2 then
          # ...

… can be better done as:

    grp.entities.grep(Sketchup::Edge) do |e1|
      next unless e1.length == temp2
      # ...

(You save 2 indents.)

1 Like

I am will use REgroup .think it .
TKS DanRathbun and tt_su
This demo will get copper busbar bending data and qickly to get cut length bend length
will for Electric Engineering Corporation use

test group explode,and the edge.vertices no change.
image
this is test code
Sketchup.active_model.entities.add_line grp.bounds.corner(6),e1.start

# 这段是默认代码,您可以选择使用或删除。。。
mod = Sketchup.active_model # 打开模型
ent = mod.entities # 模型中的所有实体
sel = mod.selection # 当前选择
def min(*args)
   args.min
end

def max(*args)
   args.max
end
dn=1
sel.grep(Sketchup::Group) do | e |
 
 e.name=dn.to_s
 dn=dn+1
 
end

chosen_image = UI.savepanel("保存", mod.path, "csv|*.csv|txt|*.txt||")
puts chosen_image
 #p=mod.path.gsub(/.skp$/,'_TMY.csv')
#f=File.open(p,'w')
sel.grep(Sketchup::Group) do | grp |
    
    pt=grp.bounds.max
    pt1=grp.bounds.min
    w=grp.bounds.width
    h=grp.bounds.height
    d=grp.bounds.depth
    temp0=max(w,h,d)
    #最大数 temp0
    temp2=min(w,h,d)
    #最小数
    temp1 = w if w < temp0 && w > temp2
    temp1 = h if h < temp0 && h > temp2
    temp1 = d if d < temp0 && d > temp2
   
    #temp1 中间数
     tn1=0
     tn2=0
    grp.entities.grep(Sketchup::Edge) do |e1|
          next unless e1.length == temp2
             if h> w
              x1, y1, z1 = e1.start.position.to_a
              #纵向
	          x2, y2, z2 = grp.bounds.corner(0).to_a
              if y1==y2 and z1 != z2
              Tn1=z1-z2
              UI.messagebox Tn1.to_mm
              end
	          
              x2, y2, z2 = grp.bounds.corner(6).to_a
              if y1==y2 and  z1 != z2
              Tn2=z2-z1
              UI.messagebox Tn2.to_mm
              #puts Tn2.to_mm  
              end
              Sketchup.active_model.entities.add_line grp.bounds.corner(0),e1.start
             
             end
             if w > h then
              #水平
              x1, y1, z1 = e1.start.position.to_a
              x2, y2, z2 = grp.bounds.corner(4).to_a
              #puts x1
              #puts x2
              if y1==y2 and z1==z2 and x1!=x2
              #puts z1
              #puts z2
              
              Tn1=x1-x2
              UI.messagebox Tn1.to_mm
              end
	          
              x2, y2, z2 = grp.bounds.corner(7).to_a
              if y1==y2 and z1==z2 and x1!=x2
              
              Tn2=x2-x1
              UI.messagebox Tn2.to_mm
              #puts Tn2.to_mm  
             end
              Sketchup.active_model.entities.add_line grp.bounds.corner(6),e1.start
             end
              #puts Tn2.to_mm  
             
            end
         end
      
      
      # ste=grp.name+",X:"+(pt[0]-pt1[0]).to_mm.round(2).to_s+"mm,"+"Y:"+(pt[1]-pt1[1]).to_mm.round(2).to_s+"mm," +"Z:"+(pt[2]-pt1[2]).to_mm.round(2).to_s+"mm"+",N1="+Tn1.to_s+",N2="+Tn2.to_s
      # f.puts ste
 



#f.close
result = UI.messagebox '导出完成,导出内容在当前文件所在目录下', MB_OK

use face area to get length.
so 方法总比困难多。
TKS
现将代码奉上,总是有wv

# 这段是默认代码,您可以选择使用或删除。。。
mod = Sketchup.active_model # 打开模型
ent = mod.entities # 模型中的所有实体
sel = mod.selection # 当前选择
def min(*args)
   args.min
end

def max(*args)
   args.max
end

 #p=mod.path.gsub(/.skp$/,'_TMY.csv')
#f=File.open(p,'w')
sel.grep(Sketchup::Group) do | grp |
    
    pt=grp.bounds.max
    pt1=grp.bounds.min
    w=grp.bounds.width
    h=grp.bounds.height
    d=grp.bounds.depth
    temp0=max(w,h,d)
    #最大数 temp0
    temp2=min(w,h,d)
    #最小数
    temp1 = w if w < temp0 && w > temp2
    temp1 = h if h < temp0 && h > temp2
    temp1 = d if d < temp0 && d > temp2
 
    #temp1 中间数
     grp.entities.grep(Sketchup::Edge) do |e1|
           next unless e1.length == temp2 #当边长等于排宽时
             
              #result = e1.faces[0].classify_point(pt1)
              #if result == Sketchup::Face::PointNotOnPlane
                  if e1.faces[0].area > e1.faces[1].area
                    bc1=e1.faces[0].area / e1.length
                    p bc1.to_mm  
                  else
                    bc2=e1.faces[1].area / e1.length
                    p bc2.to_mm 
                  end
                #end #end result
     end #end temp2
          

end             

TKS!