Another grouping a group issue?
-
I'm not quite happy with my 2D Wall Section Tool yet, and improvements are on the way.
http://forums.sketchucation.com/viewtopic.php?f=323&t=39372
Currently the routine that draws each of the 3 arcs, is a group, this group is then transformed and copied repeatedly along the entire wall length.
If I later decide to remove the insulation arcs, I have to delete each 3 arc group individually. Is there a way to group the entire group of insulating arcs for more easy deletion? -
Let's say your '2d-section' is referred to as
group_section
and you can then add some geometry to its entities
group_section.entities.add_line(p0,p1)
etc etc...
BUT for your hatching you just need to make a group inside thegroup_section
group's entities thus
group_hatch=group_section.entities.add_group()
And now add you hatching geometry to the entities of that nested group
group_hatch.entities.add_line(p2,p3)
etc etc
Now you can delete the hatching group in one go as all of its geometry is 'contained'...
I used '.add_line' but any '.add_' method will work...
You can make any number of side by side or nested groups, even groups inside nested groups ! -
I have been struggling with this grouping of groups stuff. The attached code which draws joists @ centers, between 2 points is similar to the insulation example I talked about. This CODE between the IF statement groups each joist.
if( @joist != "OFF" ) #...get the number of joists required for the related @vec/@joc @num_joist = ((@vec/@joc)+1).to_i definitions=model.definitions count=definitions.add entities=count.entities #...draw 1st joist base=entities.add_face(@pt33, @pt33a, @pt3a, @pt3) base=entities.add_line(@pt33, @pt3a) base=entities.add_line(@pt33a, @pt3) #...transform joist location t=Geom;;Transformation.translation(Geom;;Vector3d.new(0, 0, 0)) entities=model.active_entities entities.add_instance(count, t) #...copy joists to their new locations i = 1 while i < @num_joist # Transformation i = i + 1 vec = @pt44b - @pt3a # width betweeen which joists are to be drawn vec.length = @joc*(i-1) t=Geom;;Transformation.translation(Geom;;Vector3d.new(0,@joc*(i-1), 0)) t=Geom;;Transformation.translation(vec) entities.add_instance(count, t) end end # if
I don't know enough about Ruby coding if the
%(#FF0000)[definitions=model.definitions
count=definitions.add
entities=count.entities]
code is interfering with the new grouping of groups proposal. I don't seem to be able to add the proposed code, causing all the grouped joists to be added to a new group..... help! -
This statement just creates a new identity transform:
t = Geom::Transformation.translation(Geom::Vector3d.new(0, 0, 0))
you might as well just use:
t = Geom::Transformation.new()
In your while loop, you have two successive reference assignments to
t
, and the first is frivolous as it's being overwritten by the 2nd.
Either set up the referencevec
and use it, or use the literal, as in the first assignment tot
, but not both.#...copy joists to their new locations i = 1 while i < @num_joist # Transformation i = i + 1 vec = @pt44b - @pt3a # width betweeen which joists are to be drawn vec.length = @joc*(i-1) t=Geom;;Transformation.translation(Geom;;Vector3d.new(0,@joc*(i-1), 0)) t=Geom;;Transformation.translation(vec) entities.add_instance(count, t) end end # if
General issues:
Identifiers: choose descriptive identifiers for your instance vars, so that when you post code, we know what they represent. Otherwise we have to guess, (if we even wish to try, and many readers will just go on to the next post.)
So help yourself, by helping us to help you.
Write more understandable code.
For example, reusing the referencecount
might save a few bytes of memory, but big deal. This code would be wrapped within a method anyway, and all locals would be garbage-collected when the method call returns.
So I would usejoist = definitions.add("Joist")
andjoist_ents = joist.entities
, then further down use a different reference to refer to the context entities (like:mod_ents
and/oract_ents
.)Next issue...
while
loop. Normally used when you don't know when the exit condition will be met. But you do, .. the user will tell the method how many joists they want.
So use:
for i in 1..@num_joists do ... repetitive code end
and you don't need to initi
, nor incrementi
during the loop, as thefor
will do it automatically.@tomot said:
I don't seem to be able to add the proposed code, causing all the grouped joists to be added to a new group..... help!
You are adding instances of
ComponentInstance
, notGroup
. -
By the way... the word
count
is one of the standard method names in the API. You should avoid using it (it might confuse Ruby into thinking your making a method call. Sometimes Ruby can tell the difference, sometimes not.)You should check the method index before choosing var names:
http://code.google.com/apis/sketchup/docs/methods.html#index_c -
I forgot to mention: I have used this particular statement with and without if, it replicates whatever you throw into it. I did not write it. I simply copied it blindly, and it works flawlessly, in this particular situation it replicates the three statements starting with base=entities.... into a group. However what it does not do presently is collect all grouped base=entities...., into one master group containing all base=entities....
Seems almost too easy too describe in words, were it not for Ruby getting in my way. -
@dan rathbun said:
By the way... the word
count
is one of the standard method names in the API. You should avoid using it (it might confuse Ruby into thinking your making a method call. Sometimes Ruby can tell the difference, sometimes not.)You should check the method index before choosing var names:
http://code.google.com/apis/sketchup/docs/methods.html#index_cwhile i < @num_insul # Transformation i = i + 1 vec = @pt44b - @pt3a vec.length = @vec4*(i-1) t=Geom;;Transformation.translation(Geom;;Vector3d.new(0,@vec4*(i-1), 0)) t=Geom;;Transformation.translation(vec) entities.add_instance(count, t) end
Interesting! I have 2 scripts, on replicates joists the other studs both use count. One script constantly gives me an '<' error in the console the other does not. ....very aggravating!
-
I don't know who / where you copied it from.. but it's a mess!
(Sometimes you have to do the cleanup yourself.)Since it adds the instances to the
active_entities
, then IF the user (you,) are not within aGroup
orComponent
editing context, then the new joists will be added to themodel.entities
, because in this casemodel.entities == model.active_entities
, understand?You would need to have double-clicked on a
Group
orComponent
before running the "joist" command, in order to have them added INSIDE.Or... you create an argument for the method, that you use to pass a reference to the
Group
orComponent
that you wish the joists add to. -
I will chew your suggestions over Dan .... tomorrow is another day!
-
@tomot said:
Interesting! I have 2 scripts, on replicates joists the other studs both use
count
. One script constantly gives me an '<' error in the console the other does not. ....very aggravating!Yep.. and same with:
entities.add_instance(count, t)
The word 'entities' is a method name. It often works OK, but is poor form.
Using something like:
grp_ents.add_instance(joist, tx_vec)
is much better, and more understandable.
Advertisement