Thanks for the response I suspected something like that was going on. I do have code to make sure that only 2 faces have been selected and no other parts of the model. I will look into using the tool class so I can get the correct order of faces. Again Thanks to both of you for all of your help.
Latest posts made by stevo7122
-
RE: Flatten Plane / Match plane
-
RE: Flatten Plane / Match plane
Sorry I meant to say clicked on a different face first...For some reason I keep wanting to say plane..
-
RE: Flatten Plane / Match plane
I have been doing some debugging of sorts and if you do a puts f0.normal and a puts f1.normal then select face1 then face2 (look at the two values and the order they are outputted) then perform an undo and select face2 then face1 it produces the same values in the same order. Shouldn't the order be reversed if I clicked on a different plane first in each instance?
-
RE: Flatten Plane / Match plane
As an edit I just realized I think my comments should be #first face normal and #second face normal not #first plane normal etc...
-
RE: Flatten Plane / Match plane
Right. However in the array will the first position = the first item clicked? For example if I select one face the first array position[0] should contain that face. And in another instance if i click on the first face then the second face will the position[0] still be the first face I clicked on or will the second face be in that position as it changes how the model is enumerated? For some reason when I use the code no matter which face I click on it always flattens the same face regardless of the first face clicked. Currently as it stands if I click the first face and then the second face it will always flatten the first face to the second face....Basically to test the code I will select 1 face then select the next face and it will flatten. However If I perform an undo to reset the faces to the original position and select a different face as the first one it will still flatten the same face regardless of which order I clicked on.
` f0=m.selection[0]; #first face selected
f1=m.selection[1]; #second face selectedn0=f0.normal; #first plane normal
n1=f1.normal; #second plane normalc=n0.cross(n1);
set a equal to the angle between the first and second faces.
a=n0.angle_between(n1);
t=Geom::Transformation.rotation(f0.vertices[0].position,c,-a);
m.active_entities.transform_entities(t,f1);
m.commit_operation;` -
RE: Flatten Plane / Match plane
Technicallly the first face clicked should be f0=m.selection[0] If I were to select two faces...correct?
-
RE: Flatten Plane / Match plane
I think my issue is i'm not actually capturing the first triangle being clicked anywhere I'm just enumerating the selected model and incidently just reversing the code. I think I need to some how determine which triangle was clicked first I.E. f0 or f1 and then adjust accordingly.
-
RE: Flatten Plane / Match plane
Shouldn't this work given that f is equal to the first plane selected or am i not understanding something?
-
RE: Flatten Plane / Match plane
thomthom I just purchased your vertex tools and will give them a try. I do have one last issue. It seems that no matter which order I select to flatten the two triangles it always flattens to the plane of the same triangle. What i'm wanting is to flatten to the plane of the first selected triangle depending on which order I select. Using Tig's code below I removed the z axis and set it equal to the normal of the first plane:
` #Set m = to the active Model
m=Sketchup.active_model;
m.start_operation('f');#Get the first plane and store it in f
f=m.selection[0];
#n0=Z_AXIS.clone;#Get the normal of the second plane and store it in n0
n0=m.selection[1].normal;#set n1 = to the first planes normal.
n1=f.normal;#Set c equal to the cross vector of the first plane.
c=n0.cross(n1);set a equal to the angle between the first and second faces.
a=n0.angle_between(n1);
t=Geom::Transformation.rotation(f.vertices[0].position,c,-a);
m.active_entities.transform_entities(t,f);
m.commit_operation` -
RE: Flatten Plane / Match plane
I think I figured it out. I actually needed to set n0=selection[1].normal I.E. the normal of the other plane...One last quick question is their a way to remove the conjoined edge between the two triangles after I make them coplanar? Im sure in the api you can find the conjoined edge is their a delete function that you would perform?Thank you both for all of your help.