Identifying a group
-
hi,
i went thru some topics about it, but i still can't get it:why does this ruby does not identify the group selected?
selection = Sketchup.active_model.selection if selection.is_a?(Sketchup;;Group) puts "selection is a group" selection = group.entities.parent.entities() end
or do i have to go "insode" the group to be able to select the entities?
i my case i don't get the message "selection is a group" at all, when 1 group is selected.
zjanx and ragards
stan -
Hi Stan.
The selection is a collection of entities. You can index and iterate the selection set similar to an Array.
sel = Sketchup.active_model.selection puts "#{sel.size} entities selected." first_ent = sel.first third = sel[2] for e in sel if e.is_a?(Sketchup;;Group) puts "Found a Group" end end
-
hi jim,
thanx very much.
i understood iterating thru selection-items, which btw. solves also the next step
for the eruby to work onall groups in the selection.
i put this small helper online, when it is finished (have to solve the selection of components , especially nested components in the selected group, to read the items-properties of the planes inside those components.
so thanx, this step works !!!!
stan
-
@artmusicstudio said:
all groups in the selection.
easy one:
grps = sel.grep(Sketchup::Group)
The
grep
filter method is very fast,... and comes from theEnumerable
module which is mixed into many collection classes.
Thegrep
method creates a newArray
instance.This then leads to:
for grp in grps gt = grp.transformation comps = grp.entities.grep(Sketchup;;ComponentInstance) next if comps.empty? for comp in comps ct = comp.tranformation ents = comp.defintion.entities # process component's entities, etc. end end
-
hi dan,
thanx, ok, again something for my limited brain capacity ( -:) ) ,
what i have to achive is
-iterate thru selection (can be groups, compnents or pure entities and combined)
-check for pure entities in it - at model level (done, works)
-check for pure entities in groups inside ( 1 level deep only, done, works)
+
-check for entities in groups within selected groups ( 1 level deep only)
-check for entities in components within selected groups ( 1 level deep only)
-check for entities in components within selected groups ( 1 level deep only)
-check for entities in components within selected components( 1 level deep only)
so some brainwork is necessary.
we shall see.by the way:
when i iterate thru pure elements within a group, the ruby reads them chronologically, so
newer elements are read out later then the older ones.now, i think of finding a way to iterate depending of the Z height.
is there a way to say directly in the iteration routine, start with lowest elements and go up to the highest?
the result: the found planes would always be numbered from 1 to x like floors !
i still have no idea, how to realise this.
stan
-
@artmusicstudio said:
now, i think of finding a way to iterate depending of the Z height.
is there a way to say directly in the iteration routine, start with lowest elements and go up to the highest?
You make an array COPY of the collection, and the sort the array using the
sort()
method that is mixed in from theEnumerable
module.Use the entity
bounds()
method to get aGeom::BoundingBox
, and it'smin()
method to get aGeom::Point3d
, and use it'sz()
method to getLength
objects for the compare expression.def z_sort(coll) coll.to_a.sort {|a,b| a.bounds.min.z <=> b.bounds.min.z } end
The trick is that the
Comparable
module must be mixed into the final object's class, on both sides of the compare<=>
operator. This will always be true for Numeric and String subclasses. At the console:
Length.ancestors %(darkgreen)[>> [Length, Float, JSON::Ext::Generator::GeneratorMethods::Float, Numeric, Comparable, Object, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]]
Notice thatComparable
is already mixed in ?
Advertisement