Move an edge?
-
This seems so basic, but how do you move an edge? It does not have a transform! method. I tried transforming the two point3d objects of the two vertices, but could not get it to work.
-
Heh good question, havent tried. Maybe you will have to group the edge temporarely?
-
Entities.transform_by_vectors
and
Entities.transform_entitiesmention that you must be in the correct edit context.
-
@daiku said:
I tried transforming the two
point3d
objects of the two vertices, but could not get it to work.Geom::Point3d
objects are an abstract class. Meaning that aSketchup::Model
does not have these objects in it'sEntities
.Only subclasses of
Sketchup::Entity
can be stored into the model. Most of what you "see" in a model, are subclasses ofSketchup::Drawingelement
(which is a child class ofSketchup::Entity
.)You would need to transform a
Sketchup::Vertex
, not aGeom::Point3d
object. -
@dan rathbun said:
Only subclasses of
Sketchup::Entity
can be stored into the model. Most of what you "see" in a model, are subclasses ofSketchup::Drawingelement
(which is a child class ofSketchup::Entity
.)You would need to transform a
Sketchup::Vertex
, not aGeom::Point3d
object.But Sketchup::Vertex is not a subclass of Drawingelement, and does not respond to transform!
-
Sketchup::Vertex.superclass
Sketchup::Entity
There are many objects "in the model" that are not subclasses of
Sketchup::Drawingelement
examples:
Sketchup::Layer Sketchup::Page Sketchup::Material
etc.Only
Group
andComponentInstance
have atransform!()
method.But that does NOT mean you cannot apply a transformation using the methods in the
Entities
object... -
OK, So I need to put all the edges I want to move into an entities container, and then use the container's transform methods. Can I put existing geometry into an entities container? It seems that the only way to add an edge is to pass in the endpoints, and it will return the resulting edge. Doesn't seem like this will add the original edge, but rather create a new one.
-
Misunderstood how entities.transform_entities works. It's a method of an existing entities container (in my case, a comp def). You pass it the transform, and an array of entities to be transformed. Moving forward again!
-
The API is badly phrased....
You are making it seem more complicated that it is or needs to be...
You can group.transform!(transformation) and ditto for instances and point3d [useful if you are using them to construct edges etc].
You can't .transform! an edge or a face etc.
You can use one of the two entities methods to transform entities and vertices.
The entities need to be the entities where the listed objects are... so let's say we have an array of edges to be translated called 'edges' that should all be in the same 'context'...
tr=Geom::Transformation.translation(Geom::Vector3d.new(0,0,1))
to move everything up in the z 1".
edges[0].parent.entities.transform_entities(tr, edges)
all of the edges move up 1"
Now let's assume we have an array of faces that we want to move in the same way - one way is to move their vertices [you could of course get the faces and their edges in an array and .uniq! it, then transform those as an alternative]
verts=[] faces.each{|face|verts << face.vertices} verts.flatten! verts.uniq! faces[0].parent.entities.transform_entities(tr, verts)
this method is very common.
The other method isentities.transform_by_vectors(objs_array, verts_array)
If the vector is the same for each object you could use theents.transform_entities(translation_transformation)
method, but this alternative allows you to manipulate an array [of say vertices] by individual vectors en mass - you need to compile two arrays - an array of objects (which are often vertices) and an array of matching vectors - one for each object to be transformed; this is useful when the vertices need to move by different amounts - see my DropVertices ruby for an example of this... -
TIG ya might as well break down and write up a
Transformation
tutorial for the new SCF section. -
I have struggled with this problem also. When I use the vector transform to change the z value of a curve vertex by an offset or absolute amount, it seems to work as expected. But, trying to do the same with the x or y value, gives some rather strange results and I'm baffled as to why.
-
Moving one vertex and then perhaps another will often have a quite different results, compared to moving them all in one fell swoop with the entities. transformation methods that do all of the changes together...
-
@tig said:
Moving one vertex and then perhaps another will often have a quite different results, compared to moving them all in one fell swoop with the entities. transformation methods that do all of the changes together...
Plus - it's much much faster to perform one big entity transformation instead of many.
Advertisement