But it seems no way to calculate the area...
Posts
-
RE: How to see the results of this method?
-
How to see the results of this method?
def sum_area( material, entities, tr = Geom;;Transformation.new ) area = 0.0 for entity in entities if entity.is_a?( Sketchup;;Group ) area += sum_area( material, entity.entities, tr * entity.transformation ) elsif entity.is_a?( Sketchup;;ComponentInstance ) area += sum_area( material, entity.definition.entities, tr * entity.transformation ) elsif entity.is_a?( Sketchup;;Face ) && entity.material == material # (!) The area returned is the unscaled area of the definition. # Use the combined transformation to calculate the correct area. # (Sorry, I don't remember from the top of my head how one does that.) # # (!) Also not that this only takes into account materials on the front # of faces. You must decide if you want to take into account the back # size as well. area += entity.area end end area end
Thank you for your help!
-
How do I change this code?(deduct the overlapping area)
I want to deduct the overlapping area between componentinstance and componentinstance in model.
How do I change this code?
Thank you for your help!mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selectionas = mod.definitions["column"].instances
bs = mod.definitions["beam"].instanceshits = {} ### empty hash
as.each{|a|
es = a.parent.entities
hits[a]=[]
bs.each{|b|
next unless es = b.parent.entities ### same context
bb = a.bounds.intersect(b.bounds)
hits[a] << b if bb && bb.valid?
}
}
hits.each{|hit| puts "column #{hit[0]} intersects beam #{hit[1]}" }
-
RE: How do I change the code?
TO TIG:
Thank you for your reply!
If I want to get the component's dynamic attributes(lenx, leny...) by multiple components collision detection?
and I will deduction of the overlapping area(multiple components) after...
(1)multiple components collision detection
(2)get the component's dynamic attributes(lenx, leny...)Thank you for your help!
-
How do I change the code?
mod = Sketchup.active_model
ent = mod.entitiesq = Sketchup.active_model.selection.add(
Sketchup.active_model.definitions["aaa"].instances )a = Sketchup.active_model.selection.add(
Sketchup.active_model.definitions["bbb"].instances )bb = Geom::BoundingBox.new.add(q.bounds.intersect(a.bounds))
if bb.valid?
puts "a"
else
puts "b"
endIt can't run...
How do I change the code? -
Collision Detection
Hello everyone
The following figure...
a and b intersect
b and c intersect
a and c not intersectI get Leny, Lenz from dynamic attributes(inch)
How not to let the detected twice?(a&b and b&a)
Thank you for your help!
mod = Sketchup.active_model
ent = mod.entities
grp = ent.grep(Sketchup::ComponentInstance)
for i in 0...grp.length - 1
grp.each{ |g| next if g == grp[i] # skip comparing to self
bb = Geom::BoundingBox.new.add(g.bounds.intersect(grp[i].bounds))
if bb.valid?#gg = g.get_attribute("dynamic_attributes","lenx","")
gg1 = g.get_attribute("dynamic_attributes","leny","")
gg2 = g.get_attribute("dynamic_attributes","lenz","")
#puts gg#.to_cm
puts gg1#.to_cm
puts gg2#.to_cm#gg3 = grp[i].get_attribute("dynamic_attributes","lenx","")
gg4 = grp[i].get_attribute("dynamic_attributes","leny","")
gg5 = grp[i].get_attribute("dynamic_attributes","lenz","")
#puts gg3#.to_cm
puts gg4#.to_cm
puts gg5#.to_cmq = gg1.to_i * gg2.to_i - gg4.to_i * gg5.to_i
puts q
#puts "#{g.name} and #{grp[i].name} intersect"
else
puts "#{g.name} and #{grp[i].name} do not intersect"
end
bb.clear
}
end
-
How to detect collisions between ComponentInstance?
Hello everyone
How to detect collisions between ComponentInstance?
e.g:
if name = "column" all component collision name = "beam" all component
do something...
else
do something...
endThank you for your answer!
-
How to detect collisions between ComponentInstance?
Hello everyone
How to detect collisions between ComponentInstance?
e.g:
if name = "column" all component collision name = "beam" all component
do something...
else
do something...
endThank you for your answer!
-
Automatically Calculate the Component's Area and Volume
Hello everyone:
I want to know how to automatically calculate the component's area and volume in the dynamic attributes.
p.s:Non-use formula input.
Such as following example.
Thank you for your answer.
-
Detect object intersect
Hello everyone
mod = Sketchup.active_model
ent = mod.entities
grp = ent.grep(Sketchup::ComponentInstance)
for i in 0...grp.length - 1
grp.each{ |g| next if g == grp[i]
bb = Geom::BoundingBox.new.add(g.bounds.intersect(grp[i].bounds))
if bb.valid?
puts "#{g.name.to_s} and #{grp[i].name.to_s} intersect"
else
puts "#{g.name.to_s} and #{grp[i].name.to_s} do not intersect"
end
bb.clear
}
endI want to know how to calculate the model of dynamic properties of all objects (such as "Lenx", "Leny" ,"Lenz"...etc) after the object intersected the other object.
The case description like this:
First, detect all objects intersect situations like the above code
Second, if name = "column" objects intersect name = "beam" objects(just a simple example)
then, "column" objects dynamic properties("Lenx") deduction "beam" objects dynamic properties("Leny")Thank you for your advice and help
-
Detect object intersect
Hello everyone
mod = Sketchup.active_model
ent = mod.entities
grp = ent.grep(Sketchup::ComponentInstance)
for i in 0...grp.length - 1
grp.each{ |g| next if g == grp[i]
bb = Geom::BoundingBox.new.add(g.bounds.intersect(grp[i].bounds))
if bb.valid?
puts "#{g.name.to_s} and #{grp[i].name.to_s} intersect"
else
puts "#{g.name.to_s} and #{grp[i].name.to_s} do not intersect"
end
bb.clear
}
endI want to know how to calculate the model of dynamic properties of all objects (such as "Lenx", "Leny" ,"Lenz"...etc) after the object intersected the other object.
The case description like this:
First, detect all objects intersect situations like the above code
Second, if name = "column" objects intersect name = "beam" objects(just a simple example)
then, "column" objects dynamic properties("Lenx") deduction "beam" objects dynamic properties("Leny")Thank you for your advice and help
-
RE: Detect whether all elements of the model intersect
Hello everyone
I reference everyone's suggestion
The successful implementation of the following code:mod = Sketchup.active_model
ent = mod.entities
grp = ent.grep(Sketchup::ComponentInstance)
for i in 0...grp.length - 1
grp.each{ |g| next if g == grp[i]
bb = Geom::BoundingBox.new.add(g.bounds.intersect(grp[i].bounds))
if bb.valid?
puts "#{g.name.to_s} and #{grp[i].name.to_s} intersect"
else
puts "#{g.name.to_s} and #{grp[i].name.to_s} do not intersect"
end
bb.clear
}
endNext, I want to know how to calculate the model of dynamic properties of all objects (such as "Lenx", "Leny" ,"Lenz"...etc) after the object intersected the other object.
The case description like this:
First, detect all objects intersect situations like the above code
Second, if name = "column" objects intersect name = "beam" objects(just a simple example)
then, "column" objects dynamic properties("Lenx") deduction "beam" objects dynamic properties("Leny")Thank you for your advice and help
-
RE: How to make toolbar in method(def..end) has parameters
Thanks for everybody help and advice
The problem has been resolved -
RE: How to make toolbar in method(def..end) has parameters
To TIG:
"valueq" is the argument I entered through Webdialog
by WebDialog (JavaScript pass value) to the ruby
I try to packaged this slab code with Class or Method(def...end)
and click the button to be able to run the code
but it seems problems in pass value and convert argument -
RE: How to make toolbar in method(def..end) has parameters
Greg, I'm sorry because I tried it or not successful...
then, I think in this way, use "class...end"the code like this:
class SphereTool
def slab(valueq)
...
end
endsphere_cmd = UI::Command.new("Sphere") {
Sketchup.active_model.select_tool SphereTool.new
}sphere_cmd.small_icon = "sphere_small.gif"
sphere_cmd.large_icon = "sphere_large.gif"
sphere_cmd.tooltip = "Create a sphere"sphere_toolbar = UI::Toolbar.new "Sphere"
sphere_toolbar.add_item sphere_cmd
sphere_toolbar.showbut it shows...
"Nil result (no result returned or run failed)"
Error: #<NoMethodError: undefined methodslab' for #<AS_RubyEditor::RubyEditor:0x00000007e1cad8>> (eval):76:in
block (2 levels) in initialize'
SketchUp:1:in `call'
-
RE: How to make toolbar in method(def..end) has parameters
Sorry...Greg
I try to use instance variables like this:def slab(valueq)
...
end
command = UI::Command.new("ss") { |@valueq| slab(@valueq) }but ruby editor shows the situation like this":
cannot be an instance variable
command = UI::Command.new("ss") { |@valueq| slab(@valueq) }and...if I change the code like this:
def slab(valueq)
...
end
command = UI::Command.new("ss") { |valueq| slab(valueq) }
command.small_icon = command.large_icon = path + "/slab.png"
command.tooltip = command.status_bar_text = "s"
menu.add_item command
toolbar.add_item command
toolbar.showruby editor shows the situation like this":
Error: #<TypeError: no implicit conversion of NameError into String>It seems to be...undefined local variable or method βmenuβ and βtoolbarβ for command...
-
How to make toolbar in method(def..end) has parameters
Hello everyone:
I want to know how to make toolbar in method(def..end) has parameters
e.g.def slab(valueq)
....
....
....
path = File.dirname(FILE) + "/image/"
menu = UI.menu("Plugins").add_submenu("xx")
toolbar = UI::Toolbar.new("xx")
command = UI::Command.new("ss") {slab}
command.small_icon = command.large_icon = path + "/slab.png"
command.tooltip = command.status_bar_text = "s"
menu.add_item command
toolbar.add_item command
toolbar.showThank you for your answer!
-
RE: Detect whether all elements of the model intersect
Hello sdmitch:
First of all, thank you for teaching, I changed your code to meet my needs.
Please look at this picture, ruby console return
"one and two intersect
one and three do not intersect"
so I also want to know how to return
"two and three intersect"
Need to write a loop(for...end)?Because I want to deduct the intersection surface of the overlapping area,
so I need to detect whether all elements of the model intersect.Thank you for teaching again.
-
Detect whether all elements of the model intersect
I want to detect whether all elements of the model intersect
Like this, but I have no solution, please give me advice, Thank you very much!p = mod.entities.find_all {| ent | ent.is_a (Sketchup :: ComponentInstance)?}
bb = p.bounds.intersect (p.bounds)
if bb.valid?
if p.description == "one"
p.get_attribute ("dynamic_attributes", "name")
else
puts "B"
end
else
puts "no"
end