<div dir="ltr">James,<div><br></div><div>I believe this example snippet performs the function you want.  </div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><b>diff --git a/rstbx/diffraction/fastbragg/fastbragg_ext.cpp b/rstbx/diffraction/fastbragg/fastbragg_ext.cpp</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><b>index d544d22..380e84f 100644</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><b>--- a/rstbx/diffraction/fastbragg/fastbragg_ext.cpp</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><b>+++ b/rstbx/diffraction/fastbragg/fastbragg_ext.cpp</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,187,199)">@@ -22,6 +22,13 @@</span><span style="font-variant-ligatures:no-common-ligatures"> namespace boost_python { namespace {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">   {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">     return boost::python::make_tuple(1,2,3,4);</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">   }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,189,38)">+</span><span style="font-variant-ligatures:no-common-ligatures;background-color:rgb(153,18,0)">  </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+  static double</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+  get_distance_mm(camera const&amp; c) { return c.distance*1000.; }</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+  static void</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+  set_distance_mm(camera&amp; c, double const&amp; value) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+      c.distance = value/1000.;}</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"> </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">   void</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">   init_module() {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(52,187,199)">@@ -57,6 +64,9 @@</span><span style="font-variant-ligatures:no-common-ligatures"> namespace boost_python { namespace {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">       .add_property(&quot;distance&quot;,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">                      make_getter(&amp;camera::distance,rbv()),</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">                      make_setter(&amp;camera::distance,dcp()))</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+      .add_property(&quot;distance_mm&quot;,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+                     make_function(&amp;get_distance_mm,rbv()),</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(52,189,38)"><span style="font-variant-ligatures:no-common-ligatures">+                     make_function(&amp;set_distance_mm,dcp()))</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">       .add_property(&quot;Ybeam&quot;,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">                      make_getter(&amp;camera::Ybeam,rbv()),</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">                      make_setter(&amp;camera::Ybeam,dcp()))</span></p></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Use it with this example python script:</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">from</span><span style="font-variant-ligatures:no-common-ligatures"> rstbx.diffraction.fastbragg </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">import</span><span style="font-variant-ligatures:no-common-ligatures"> camera</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">c = camera()</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">c.distance = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">10.</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)"># meters</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">print</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">&quot;distance is %f millimeters&quot;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">%( c.distance_mm )</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">c.distance_mm = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">10.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)">print</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">&quot;distance is %f meters&quot;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">%( c.distance )</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><br></span></p><p style="margin:0px;line-height:normal">Output is:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">distance is 10000.000000 millimeters</span></p><p style="margin:0px;line-height:normal">
</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">distance is 0.010000 meters</span></p><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">So problem solved.<br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Nick</span></div><p style="margin:0px;line-height:normal"><br></p></span></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Nicholas K. Sauter, Ph. D.<br>Senior Scientist, Molecular Biophysics &amp; Integrated Bioimaging Division<div>Lawrence Berkeley National Laboratory<br>1 Cyclotron Rd., Bldg. 33R0345<br>Berkeley, CA 94720<br>(510) 486-5713<br></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, Feb 21, 2017 at 5:08 PM, Nicholas Sauter <span dir="ltr">&lt;<a href="mailto:nksauter@lbl.gov" target="_blank">nksauter@lbl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><a href="http://phenix-online.org/mailman/listinfo/cctbxbb" rel="noreferrer" target="_blank"></a>Quick question from James Holton and myself.<br><br></div>We want to use a boost python *.add_property() to add a make_getter and make_setter to our wrapper, so we can expose a class variable to the Python layer.<br><br></div>However, we want to execute a change of measurement units, i.e., the Python value will always be given in millimetres, and the C++ value always in metres.<br><br></div>How can this be done within a simple add_property() paradigm?<br><br></div>Nick<br></div>
</blockquote></div><br></div>