DC instance make unique
-
I'm still not entirely sure why it has to be a DC - why not just a component ?
If it's a DC whenever you add an instance of it it's already made unique! It's a DC thing. Any Components inside it are unlikely to be though... -
Hi TIG.
@unknownuser said:
I'm still not entirely sure why it has to be a DC - why not just a component ?
Since you know what I'm working on a.t.m. Are you refering to why I'm using DC's or why DC are the cause of this problem?
But yes it is the components inside that's the problem. Actually, I really do not need the additional instance. I'm just after the face and edge collection from the components inside the DC.
Iterating through nested component entities I get perculiar results.
If putting the DC inside a group and explode the group, it crashes sometimes. Although if I iterate the group.entities and explode, it doesent crash. BUT only 1 component inside get's exploded that way . Using group.ents.to_a or not doesent matter. Neither "next if not e.valid?" or something like that.
If you have a better way to get to the face or edge entities inside the nested components without exploding them, I would be most greatful to hear about it
Then I wouldent have to do this method and the original DC could be left in peace.
-
Please explain [simply] why you are using a DC as opposed to an ordinary Component...
-
Well I'll try.
TIG, you pretty much know what I'm after. It's for the stamp tool.
So for ex let's say I have a pattern of concrete with triangles. These triangles should be adjustable in size. Also when I scale up or down to cover the faces of various size, I don't want the scaling to affect the interior components. Main concepts of DC.
I think I know what you are getting at though. I wasent specific enough when I said "stamp tool".
Maybe you thought the user would just stamp a component and move it around and stamp again? One could do that as well.
But it can be painful to align advanced patterns. Better of, cover the whole face. Therefore DC.I hope this makes things clearer?
-
You could scale instances of any component using a [random] transformation ?
I'm still not clear what you are trying to do with this.If you look at AutoCAD concrete hatching it is NOT random.
It is a 'tiled' set of random looking line patterns, so why not make a big tile-able concrete-hatching component of edges, add it and then repeat it X/Y and then explode all, intersect t with a face, then trim to remove unwanted edges and finally remove all residual faces ?
there are no CAD PATTs that are random they all tile, some just have a bigger 'repeat' to fool you... -
Gulp I did not think of making them only tileable. I'm a disaster...
I was stuck in my mind thinking of DC to do it all.
OK so from this on, if things go better. Step 1 make "manual" stamp tool. Step 2 "inbuilt" library, like your 2dtools hatches. So the rule here IF the user wants to make own patterns, is NO subcomponents?
I don't think it's a good idea to ditch the manual stamp tool idea. That could be useful as well, for precision.
Alright, will try what you say. Thanks TIG for putting me on the right track.
-
Ehum, actually the problems remain using non nested components. If I tile components there are multiple, no?
The problem was exploding nested components. Now it is exploding multiple components.If I put the components inside a group and explode the group.entities(iterate) only 1 component get's exploded.
I get constant splats following advice on this page. http://forums.sketchucation.com/viewtopic.php?f=180&t=38925&p=343823&hilit=group+from+selection#p343823
This is what I do: (first I iterate through selection and add to arrays: faces[], edges[], componentinstances[])
Then
#comps=array of componentinstances gp2=ents.add_group(comps) cents=gp2.entities cents.each{|e| # does NOT like gp2.to_a CRASH! next if not e.valid? e.explode if e.class==Sketchup;;ComponentInstance }
Probably doing some fundamential misstake, but cannot find any relevant info about this particular problem..
I can only imagine it has to do with the fact that I am adding several components to the group.
OR maybe it doesent work to run instances through an iterator? The iterator think's the instances are the same object? BUG?
That makes no sence though... -
I got it. Stupid missunderstanding.
If comps is an array of entities I add to the group. It's THEM I should explode. Not give the group entities a new name and
try to explode that object.if comps gp2=ents.add_group(comps) comps.each{|e| # does NOT like gp2.to_a CRASH! next if not e.valid? e.explode if e.class==Sketchup;;ComponentInstance }
It's funny I always find the solution 1 min after typing it on this forum.
-
Never use
ents.add_group()
with amy objects within the()
... UNLESS 'ents
' is theactive_entities
.
If it's not then you must add objects to theents
AFTER creating the group as an 'empty group()
'... -
Ok, thanks for reminding me. It even say so in the API, groups should not be created that way.
But I don't know how to do otherwise, if not creating some new entities..So how do I do it in this case. gp2=ents.add_group(). How do I add comps to gp2? comps=gp2.entities will not work will it?
-
gp=ents.add_group()
assuming comp1 is a component-instance
comp2=gp.entities.add_instance(comp1.definition, comp.transformation)
comp1.erase! so it's 'moved' into the group.
OR if it's just a definition and you have a transformation called 'tr'...
comp=gp.entities.add_instance(definition, tr)
IF it's s group it's slightly more convoluted to move it into a group that's not in the active_entities...
gp=ents.add_group()
gp2=gp.entities.add_instance(gp1.entities.parent, gp.transformation)
gp1.erase!
gp1=gp2you have effectively moved gp1 into gp...
-
Thank's a lot TIG! This is new to me and very useful. This only work's with 1 object, no? But I might have multiple components in an array. I will investigate..
Strange I haven't picked this up earlier, been reading this forum very much lately. There is so much to learn...
-
This did the trick! I mean created multiple instances inside group.
if comps gp2=ents.add_group() cents=gp2.entities comps.each{|e| cents.add_instance(e.definition, e.transformation) } cents.each{|e| #if e.class==Sketchup;;ComponentInstance #obselete? e.explode } end
Edited: Aahh heck... Faced with the same problem again. Can only explode 1 instance in the group..
And if I explode the group gp2.explode it crashes. Added the change to the snippets.. -
Yeyy! Now I have exploded all instances inside the group. Changed from cents.each to cents.to_a.each
I know about that method. Stupid did not think about doing that earlier...
Main thing here. Working with instances it is important to get them exploded?
Even if I added 2 instances to gp .Exploded 1 of the instances. Then made a group copy like gp1=gp.copy.
I got splats erasing first group called gp.
Now when every entities is exploded, I can remove the original group safely after copying it. -
Stop iterating
entities
collections that you will be changing during the iteration !
Fix the list withentities.to_a
then all is well even when you explode/erase or otherwise change things... -
Yes
Anyway. Now it's possible to collect edges, faces even materials etc. Nice!
-
@tig said:
If it's a DC whenever you add an instance of it it's already made unique! It's a DC thing.
This is not true in manual mode. Adding another instance from the Components dialog, does just that.
Afterward... editing one of then, edits them all.So.. NEW Question:
I do not see a dedicated boolean API method to test a
Group
orComponentInstance
for uniqueness.I suppose it would be ...
obj.definition.instances==0
for aComponentInstance
.. and for a
Group
:
model.definitions.any?{|d| d.group? && d.instances.length==0 && d.instances.include?(obj) }
I wonder if any of us would like a way to always force a definition to clone itself, so that all instances are always unique.
maybe aforce_unique
attribute? -
@unknownuser said:
I do not see a dedicated boolean API method to test a Group or ComponentInstance for uniqueness.
Interesting reading.
That confuses me how groups work in SU. It feels like they are Component "light", where they logically(in my head) should only be a group of geometry, and not more than that.
I guess uniqueness has an importance when working with nested DC's. Sometimes find them hard to explode.
-
@jolran said:
That confuses me how groups work in SU.
Sometimes I confuse myself, as well.
@unknownuser said:
](http://code.google.com/apis/sketchup/docs/ourdoc/group.html)":1yyw26bz]Groups in SketchUp are very similar to Components, except that there is
no instancing of groups
.That means that you always will have one and only one of each of your groups.
Now that's not correct.
- Take an empty model. (It helps to purge the "person" component.)
- Draw a cube, and group it.
- Then select it, and choose "Copy" from the Edit menu.
- Then select Paste from the edit menu, and put the copy somewhere.
- Do it again, so there are 3 of them.
Then in the console:
d = Sketchup.active_model.definitions d[0]
#Sketchup::ComponentDefinition:0x6227580
d[0].group?
true
puts d[0].instances
#Sketchup::Group:0x62487bc
#Sketchup::Group:0x62487a8
#Sketchup::Group:0x6248794Of course, they share the same primitives...
g = d[0].instances g[0].entities.to_a == g[1].entities.to_a
true
@jolran said:
It feels like they are Component "light", where they logically (in my head) should only be a group of geometry, and not more than that.
Your on the correct track ....
@unknownuser said:
](http://code.google.com/apis/sketchup/docs/ourdoc/group.html)":1yyw26bz](In the actual implementation, SketchUp keeps track of groups as a special kind of Component that combines properties of definitions and instances, ...
If you compare the method lists, between
Group
andComponentInstance
, you'll see they have nearly the same methods.
The difference? AGroup
cannot be saved out to a file (directly) for use in other models, and it's easier to get at aComponentInstance
's definition, because there's an API method for it. -
That's all very interesting, and probably quite important for us new to Sketchup Ruby to understand how groups and components works.
@unknownuser said:
If you compare the method lists, between Group and ComponentInstance, you'll see they have nearly the same methods.
The difference? A Group cannot be saved out to a file (directly) for use in other models, and it's easier to get at a ComponentInstance's definition, because there's an API method for it.I was wondering about behaviors? I noticed that if you have a face, draw a square on it and 3pl click to select. Then make a group out of that, it will behave like a cutting component onto that face. You can even unglue it if you rightclick.
However there is no "glue_to" method for groups in the API.
Advertisement