<html><head><title>Macro Align Object to View</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro Align Object to View</h1></div> <div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;"> <tr> <td class="ctTitle"> <h3><span class="mw-headline" id="Macro_Align_Object_to_View"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Text-x-python.png" class="image"><img alt="Text-x-python.png" src="32px-Text-x-python.png" width="32" height="32" srcset="/wiki/images/2/2c/Text-x-python.png 1.5x" /></a> Macro Align Object to View</span></h3> </td></tr> <tr> <th class="ctOdd">Description </th></tr> <tr> <td class="ctEven left macro-description">This macro aligns the selected object to the current View. </td></tr> <tr> <th class="ctOdd">Author </th></tr> <tr> <td class="ctEven macro-author"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Mario52" title="User:Mario52">Mario52</a> </td></tr> <tr> <th class="ctOdd">Links </th></tr> <tr> <td class="ctEven"><a href="Macros_recipes.html" title="Macros recipes">Macros recipes</a><br /><a href="How_to_install_macros.html" title="How to install macros">How to install macros</a><br /><a href="Customize_Toolbars.html" title="Customize Toolbars">How to customize toolbars</a> </td></tr> <tr> <th class="ctOdd">Version </th></tr> <tr> <td class="ctEven macro-version">0.1 </td></tr> <tr> <th class="ctOdd">Date last modification </th></tr> <tr> <td class="ctEven macro-date">2015-01-16 </td></tr> <tr> <th class="ctOdd"> </th></tr> <tr> <td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div> <ul> <li class="toclevel-1"><a href="#Macro_Align_Object_to_View"><span class="tocnumber">1</span> <span class="toctext">Macro Align Object to View</span></a></li> <li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">2</span> <span class="toctext">Description</span></a></li> <li class="toclevel-1 tocsection-2"><a href="#How_to_use"><span class="tocnumber">3</span> <span class="toctext">How to use</span></a></li> <li class="toclevel-1 tocsection-3"><a href="#Script"><span class="tocnumber">4</span> <span class="toctext">Script</span></a></li> <li class="toclevel-1 tocsection-4"><a href="#Example"><span class="tocnumber">5</span> <span class="toctext">Example</span></a></li> <li class="toclevel-1 tocsection-5"><a href="#Credits"><span class="tocnumber">6</span> <span class="toctext">Credits</span></a></li> </ul> </div> </td></tr> </table> <p><br /> </p> <h2><span class="mw-headline" id="Description">Description</span></h2> <p>This macro aligns and Position the selected object to the current View. </p> <h2><span class="mw-headline" id="How_to_use">How to use</span></h2> <ul><li> Direct your view, select your object and run the macro</li> <li> Your object will be the placement of the camera coordinates</li></ul> <h2><span class="mw-headline" id="Script">Script</span></h2> <p><b>Macro Align Object to View.FCMacro</b> </p> <pre># This macro place your object selected to the position ActiveView (camera) # extact # 16/01/2015 __title__="FCCamera" __author__ = "Mario52" import pivy from pivy import coin sel = FreeCADGui.Selection.getSelection() Nameelement = sel[0].Name App.Console.PrintMessage(str(Nameelement)+"\n") pl = FreeCAD.Placement() pl.Rotation = FreeCADGui.ActiveDocument.ActiveView.getCameraOrientation() pl.Base = FreeCAD.Vector(0.0,0.0,0.0) App.ActiveDocument.getObject(Nameelement).Placement=pl </pre> <h2><span class="mw-headline" id="Example">Example</span></h2> <center> <ul class="gallery mw-gallery-traditional" style="max-width: 686px;_width: 686px;"> <li class="gallerybox" style="width: 335px"><div style="width: 335px"> <div class="thumb" style="width: 330px;"><div style="margin:15px auto;"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Align_Object_to_View_01.png" class="image"><img alt="" src="296px-Macro_Align_Object_to_View_01.png" width="296" height="200" srcset="/wiki/images/thumb/1/15/Macro_Align_Object_to_View_01.png/444px-Macro_Align_Object_to_View_01.png 1.5x, /wiki/images/1/15/Macro_Align_Object_to_View_01.png 2x" /></a></div></div> <div class="gallerytext"> <p>Your object in its original position XY. </p> </div> </div></li> <li class="gallerybox" style="width: 335px"><div style="width: 335px"> <div class="thumb" style="width: 330px;"><div style="margin:15px auto;"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Align_Object_to_View_02.png" class="image"><img alt="" src="296px-Macro_Align_Object_to_View_02.png" width="296" height="200" srcset="/wiki/images/thumb/5/5d/Macro_Align_Object_to_View_02.png/444px-Macro_Align_Object_to_View_02.png 1.5x, /wiki/images/5/5d/Macro_Align_Object_to_View_02.png 2x" /></a></div></div> <div class="gallerytext"> <p>Rotate the screen X? Y? Z? or use this macro <a href="Macro_Rotate_View.html" title="Macro Rotate View">Macro_Rotate_View</a> for precise rotation. </p> </div> </div></li> </ul> </center> <center> <ul class="gallery mw-gallery-traditional" style="max-width: 686px;_width: 686px;"> <li class="gallerybox" style="width: 335px"><div style="width: 335px"> <div class="thumb" style="width: 330px;"><div style="margin:15px auto;"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Align_Object_to_View_03.png" class="image"><img alt="" src="296px-Macro_Align_Object_to_View_03.png" width="296" height="200" srcset="/wiki/images/thumb/b/b7/Macro_Align_Object_to_View_03.png/444px-Macro_Align_Object_to_View_03.png 1.5x, /wiki/images/b/b7/Macro_Align_Object_to_View_03.png 2x" /></a></div></div> <div class="gallerytext"> <p>Select the object and run the macro (the object face the screen). </p> </div> </div></li> <li class="gallerybox" style="width: 335px"><div style="width: 335px"> <div class="thumb" style="width: 330px;"><div style="margin:15px auto;"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Align_Object_to_View_04.png" class="image"><img alt="" src="296px-Macro_Align_Object_to_View_04.png" width="296" height="200" srcset="/wiki/images/thumb/e/e5/Macro_Align_Object_to_View_04.png/444px-Macro_Align_Object_to_View_04.png 1.5x, /wiki/images/e/e5/Macro_Align_Object_to_View_04.png 2x" /></a></div></div> <div class="gallerytext"> <p>Your object return in the XY display and in its new coordinates position (Placement,Angle) </p> </div> </div></li> </ul> </center> <h2><span class="mw-headline" id="Credits">Credits</span></h2> <p>Tanks Simplified code to rentlau_64 </p> <div style="clear:both"></div> </div> </div> </div><div class="printfooter"> Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Align_Object_to_View&oldid=239859">http://www.freecadweb.org/wiki/index.php?title=Macro_Align_Object_to_View&oldid=239859</a>"</div> <div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div> </div> </div> <div id="mw-navigation"> <h2>Navigation menu</h2> </body></html>