Get rotation(transformation)
-
I couldent find any "container" in the API. Does that mean boundingbox or entity-container perhaps?
Anyway i figured out a way through the API to get what I want. Just need to copy the lines on the
vectors direction. pt1 and pt6. Further down is noted where I have problems.
I will have to make an ekvation based on user_input "distance between lines" and how many times to copy to
clear(pass by) pt 6. Any thoughts?Code is very unfinished I guess.
mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection face_group = ent.add_group(sel) Sketchup.active_model.selection.add( face_group ) bbox = face_group.bounds bpt1 = bbox.corner(0) bpt2 = bbox.corner(1) bpt3 = bbox.corner(2) bpt4 = bbox.corner(3) bpt5 = bbox.corner(4) bpt6 = bbox.corner(5) bpt7 = bbox.corner(6) bpt8 = bbox.corner(7) pt1 =bpt1 pt2 =bpt2 pt3 =bpt3 pt4 =bpt4 pt5 =bpt5 pt6 =bpt6 pt7 =bpt7 pt8 =bpt8 x_cen = bbox.center x_vect = pt1.vector_to pt4 diag_vect = pt1.vector_to pt6 x_ang = x_vect.angle_between(diag_vect).radians user_input = 30 # will get shorter alias user_length = 20 # will get shorter alias h_group =ent.add_group() line_group=ent.add_group() ###==new empty group line_group.entities.add_line(pt1, pt6) tr1 = Geom;;Transformation.rotation x_cen, [0,1,0],(x_ang).degrees tr2 = Geom;;Transformation.rotation x_cen, [0,1,0],(user_input).degrees #tr3 = Geom;;Transformation.translation pt4 ent.transform_entities tr1, (line_group) ent.transform_entities tr2, (line_group) #ent.transform_entities tr3, (line_group) vector=diag_vect gp=line_group groups=[gp] 15.times{|i| tgp=gp.copy # code below does not work. Wanto translate in vector * 20(user_length) tgp.transform!(Geom;;Transformation.translation(vector)*(user_length)) gp=tgp groups << gp }
-
Doh!
I used the term 'container' to refer to the generic 'entities container'...
So the 'model' has 'entities'
Any 'group' in the model has 'entities'
Any 'component-definition' in the model had 'entities'...
[Whereas the component-instances in the model have definitions that have entities...]So when I say 'container' think of it as the "thing that contains the entities you are interested in"...
Can't comment on your code... too busy - any takers ??
-
Do you want the translation vector to have a length of: "user_length = 20" ?
# code below does not work. Wanto translate in vector * 20(user_length) vector.length = user_length tgp.transform!(Geom;;Transformation.translation(vector))
-
@unknownuser said:
I used the term 'container' to refer to the generic 'entities container'...
I suspected it was something like that you meant. I'm so new on this so I dont grasp the "talk"
donte walk the walk etither@unknownuser said:
Do you want the translation vector to have a length of: "user_length = 20" ?
Hi Kyyu. I want to have multiple copies in vector direction. User-length is the amount of distance
between copies. In this case 20.I should have documented my code better. Its difficult to understand want I am trying to do.
-
Once you have transformed the vector you can change its length using
my_transformed_vector.length=20.0
all of the values will adjust to suit the new length BUT the vector's length will then be 20"... -
YEY! That works!
I dont know if it will matter if the vector gets shortened, just yet.
Was thinking of grouping the result. Make an duplicate. Scale -1 in vector and do an intersect with.
You probably figured out already what this plugin will do.Thank you TIG!
-
Could we go back a few steps and explain what 'it' is you are trying to achieve - it may be much easier that you think...
-
Yes, I hope soo
Ok. So the idea is to make a Hatchplugin.
First step is to use sketchup tools and make a face. Wall, rectangle whatever. Select it and run the plugin
with a simple promt.In general getting input from user about desired line_angle and distance between them.
Make the lines and some sort of grouping before intersect_with method.
Wich hopefully will give the result of hatched lines.So by using boundingbox One can use the plugin on unregular faces, not just squares.
I wish then to copy lines across the diagonal in the boundingbox, making sure I get edges in the corners.
Why boundingbox? For ex. If I have an edge that is 45 degrees com to X , copying that line from center in an array straight up in Z until it reaches the boundingbox will leave the corners uncovered.Maybe if I new how many copies to clear the boundingbox with the last copy of edge that may be an easier
method. But that all depend on how the boundingbox is shaped?
Same goes for copying along the diagonal.
You may be right, there might be some easier method of doing this. But I'm no math expert and struggling here
understanding what I just did.
Help would be very welcomed, and mentioned if I get this to work -
Well... here's how I'd do it...
<span class="syntaxdefault">module TIG<br /> def self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">hatchfaces</span><span class="syntaxkeyword">()<br /> </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> ents</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities<br /> name</span><span class="syntaxkeyword">=</span><span class="syntaxstring">'Hatching#1'<br /> </span><span class="syntaxdefault">defs</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definitions<br /> spacing</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">2.0 </span><span class="syntaxcomment">### 2 inches ###<br /> </span><span class="syntaxdefault">ss</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br /> faces</span><span class="syntaxkeyword">=[]; </span><span class="syntaxdefault">ss</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">faces </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">e </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.class==</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'hatchfaces'</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">faces</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">names</span><span class="syntaxkeyword">=[]; </span><span class="syntaxdefault">defs</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">d</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">names </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">instances</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">name </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">d</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">group</span><span class="syntaxkeyword">?}<br /> </span><span class="syntaxdefault">name</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">next</span><span class="syntaxkeyword">! while </span><span class="syntaxdefault">names</span><span class="syntaxkeyword">.include?(</span><span class="syntaxdefault">name</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">gp</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_group</span><span class="syntaxkeyword">()<br /> </span><span class="syntaxdefault">gp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">name</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">name<br /> gents</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">gp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">entities<br /> face</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">bb</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds<br /> di</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">bb</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">diagonal<br /> pt</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">position<br /> ve</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vector_to</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">po</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.clone<br /> </span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">rotation</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">45.degrees</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">vp</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">ve</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transform</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">vp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">di</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">2<br /> tot</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">0<br /> until tot</span><span class="syntaxkeyword">>=</span><span class="syntaxdefault">di<br /> ps</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">vp</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">pe</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">vp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_line</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">ps</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">pe</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">!(</span><span class="syntaxdefault">ve</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">spacing</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">ps</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">po</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">vp</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">pe</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">po</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">vp</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_line</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">ps</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">pe</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">po</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">!(</span><span class="syntaxdefault">ve</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">reverse</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">spacing</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">tot</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">tot</span><span class="syntaxkeyword">+</span><span class="syntaxdefault">spacing<br /> end</span><span class="syntaxcomment">#until<br /> </span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new()<br /> </span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">intersect_with</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">tr</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">! if </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">valid</span><span class="syntaxkeyword">? and </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.class==</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge </span><span class="syntaxkeyword">and </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">faces</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length</span><span class="syntaxkeyword">==</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">}<br /> </span><span class="syntaxdefault">gents</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_a</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">erase</span><span class="syntaxkeyword">! if </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">valid</span><span class="syntaxkeyword">? and </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.class==</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">}<br /> }<br /> </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">commit_operation<br /> end<br />end<br /></span><span class="syntaxcomment">### usage; select faces, TIG.hatchfaces<br /> </span><span class="syntaxdefault"></span>
-
WOW, you rewrote the whole script?!!! You are quite amazing. But, but.. Its your plugin, then??
Heh, I almost got mine to work except the "petite" distance between lines thingy..
Can I load the code in ruby code editor and launch? Cause nothing happends when I run your script.
-
Please use it [or ideas in it] as you will - for example it doesn't always set the hatching at 45 degrees to where you might want just relative to the first edge of each face...
There's no options for the angle or spacing - add a dialog for those?
It's not optimized as it often makes more/longer edges than it needs to make the hatching but it was a quick kludge to make it work - to see what it does disable the closing parts that intersect/erase edges etc and use it on one face...It has ideas in it that should help you...
PS: You have to have one or more faces selected before running it...
-
You are so helpful. I can almost not believe it..
Thank you TIG!I will continue with my script since I understand easier where variables are pointing to.
See where I have gone wrong in some areas and use your script as a guidence.Thanks a million!
-
@jolran said:
I'm getting it to work almost.
@unknownuser said:
vector.length=20.0
The copied distance will always be desired length on the vectors line, but depending on the angle of diagonal the edges will not be same distance apart. So I guess I will have to do another compensation? Or is there some Quick fix like the last one(thank you TIG)
I'm guessing will have to do a comparison between Diagonal, user(desired angle, here 45 deg) and somehow
compensate the copy distance for that. Boy this is hard..Here is a example of finding the normal vector of a grouped line, using a cross product. The cross product of two vectors prduces a third vector, at right angles to the original ones.
model = Sketchup.active_model ent = model.entities sel = model.selection line = ent.add_line [3,3,0], [5,5,0] group = ent.add_group line v1 = line.vertices[0].position.transform(group.transformation) v2 = line.vertices[1].position.transform(group.transformation) v = v1.vector_to v2 # I used z vector as 2nd vector, but can try "face.normal" for general case normal_vec = v.cross([0,0,1]) #cross product to get normal vector pt = [0,0,0] demo = ent.add_line pt, pt.offset(normal_vec) #drew demo line representing normal vector demo.material = 'red' n = normal_vec n.length = 1 g1 = group.copy g1.transform! n # moved copied group using normal vector
-
Hi Kyyu!
Interresting. So you mean I use the 3rd vector for measuring? Or was it meant to be
a method to get an angle 45 deg of the vector?
Remember 45 deg is just an example for this particular hatching. The user must be able to
choose any angle for the lines across the face.I will look into it more and see if I understand you code a little better.
Thank you Kyyu. -
@jolran said:
Hi Kyyu!
Interresting. So you mean I use the 3rd vector for measuring? Or was it meant to be
a method to get an angle 45 deg of the vector?
Remember 45 deg is just an example for this particular hatching. The user must be able to
choose any angle for the lines across the face.I will look into it more and see if I understand you code a little better.
Thank you Kyyu.The 3rd vector would be your translation vector. In your code you have it as:
vector=diag_vect vector.length= user_length
It's perpendicular to what ever your final line is. Here, I just changed the line to a random new angle, not 45 deg. I set the length of the vector (distance of translation) to 1.
-
Translation vector? The translation must be on the diagonal or the lines wont cover the whole face.
I already have the rotation of lines, copy/translation set up. Except that the "bug" is that
the translation distance doesent get 100% accurate if the face is very distorted.
Maybe that is what you are trying to fix, and I don't see it.
If thats the case sorry I'm a noob, you know.The angles of lines on the picture are the identical. Although they don't appear to be.
-
Hate to bother again, but I've been going on all day and intersect_with is troublesome.
Tried TIG's combo, and others but I think I'm making a fundamentional fault.
Doesent intersect_with work with nested groups?tr3=Geom::Transformation.new()
face_group.entities.intersect_with(recursion,tr3,face_group,tr3,true,[hatch_lines_group]) -
If you read through the way I did it... I make a hatching group then simply add a face and overly long hatching lines to it, intersect everything with each other, erase the faceless edges outside of the face perimeter and then erase the faces too. I never use subgroups - if you want to then just explode them...
You are better off transforming points/vectors and drawing the edges that grouping things endlessly/needlessly it'll be slooooow -
@unknownuser said:
I make a hatching group then simply add a face and overly long hatching lines to it, intersect everything with each other, erase the faceless edges outside of the face perimeter and then erase the faces too
Aha! Did not quite understand what was going on.
Yes, yes I will TRY to do the same. That way I will learn the right way. Slow doesent sound good
My resulted line_groups apears pretty fast on screen for the moment though, and its possible to make
a manual intersect with selected. But a lot cooler if it is manual. -
@jolran said:
...Except that the "bug" is that the translation distance doesent get 100% accurate if the face is very distorted.
Maybe that is what you are trying to fix, and I don't see it.
If thats the case sorry I'm a noob, you know.Yes, that is what I am showing how to fix.
Advertisement