Instance transformations not remembered
-
I am trying to program the insertion of a component instance in a way that I can rotate it using key strokes. I have succeeded in all but one aspect.
Using MyTools I can load the instance and move it attached to the cursor. I can also capture key strokes to rotate it. However, when I start to move the mouse again the visible instance has reverted to the unrotated instance. It seems to forget the rotation transformation.
I have even renamed the rotated instance and told the subsequent mouse move to refer to the renamed instance but is still shows the unrotated instance.
Is this a bug or am I doing something wrong?Andrew
-
It should be possible to do what you describe, do I'm going to hazard a guess that it's a bug in your code. But it's hard to give specific advice without seeing any sample code.
-
-
Thank you for helping.
I have a component called SC11 wich is generated in a seperate Class. I create an instance of that component in the Class called $v_inst and it is positioned at [0,0,0]. This is picked up in the Mouse Move in the Mytools class as follows:<span class="syntaxdefault"></span><span class="syntaxkeyword">class </span><span class="syntaxdefault">MyTool<br /> def activate<br /> puts </span><span class="syntaxstring">"Your tool has been activated."<br /> </span><span class="syntaxdefault">end<br /> <br /> def onKeyDown</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">key</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">repeat</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">flags</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">)<br /> case </span><span class="syntaxdefault">key<br /> when VK_LEFT then arotate </span><span class="syntaxcomment"># just this one for starters<br /> </span><span class="syntaxdefault">end<br /> end<br /><br /> def arotate<br /> <br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">v </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Vector3d</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">) </span><span class="syntaxcomment"># about a vertical axis<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">pt </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(@</span><span class="syntaxdefault">curpt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">)<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">v</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">90.degrees<br /> $v_inst </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">$v_inst</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">$v_inst</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">name </span><span class="syntaxkeyword">= </span><span class="syntaxstring">"90"<br /> </span><span class="syntaxdefault">$v_mk </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">true<br /> end<br /> <br /> def onMouseMove</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">flags</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">x</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">y</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">)<br /> @</span><span class="syntaxdefault">curpt</span><span class="syntaxkeyword">=</span><span class="syntaxstring">""<br /> </span><span class="syntaxdefault">view</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">curpt </span><span class="syntaxkeyword">= (</span><span class="syntaxdefault">view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">inputpoint</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">y</span><span class="syntaxkeyword">))<br /> @</span><span class="syntaxdefault">pt </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Point3d</span><span class="syntaxkeyword">.new(@</span><span class="syntaxdefault">curpt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position</span><span class="syntaxkeyword">)<br /> @</span><span class="syntaxdefault">ttr</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new @</span><span class="syntaxdefault">pt<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">tttr</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new @</span><span class="syntaxdefault">pt </span><span class="syntaxcomment">#just in case it makes a difference<br /> </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">$v_mk <br /> then<br /> $v_inst1</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transformation </span><span class="syntaxkeyword">= @</span><span class="syntaxdefault">tttr<br /> </span><span class="syntaxkeyword">else<br /> </span><span class="syntaxdefault">$v_inst</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">transformation </span><span class="syntaxkeyword">= @</span><span class="syntaxdefault">ttr <br /> end<br /> end<br />end<br /></span><span class="syntaxcomment">##################### </span><span class="syntaxdefault"></span>
When it runs the instance moves with the cursor and can be rotated time after time with the left arrow. But as soon as the cursor moves again it reverts to the untransformed instance.
I would be most grateful if you can see where I am going wrong.
Andrew
-
Ah! You're replacing the transformation when you use
instance.transformation=
Either you need to make the transformation you replace with include the rotation, or you must calculate the relative offset and use
instance.transform!
-
Thanks a million. That has cracked it.
I used the offset method
Best wishesAndrew
Advertisement