[Bf-extensions-cvs] [47953165] blender-v2.82-release: PDT: Add features to Command Line

Alan Odom noreply at git.blender.org
Tue Jan 14 22:32:14 CET 2020


Commit: 479531654816970b55be491ccd48b723c002c50f
Author: Alan Odom
Date:   Mon Dec 30 14:43:35 2019 +0000
Branches: blender-v2.82-release
https://developer.blender.org/rBA479531654816970b55be491ccd48b723c002c50f

PDT: Add features to Command Line

Add "Re-Run" button to repeat last command line input.
Add "Maths Output" to take result of calculation when the `mo` command is used.
Allow commas in maths operation so calls like `hypot(3,4)` can be used.

===================================================================

M	precision_drawing_tools/__init__.py
M	precision_drawing_tools/pdt_command.py
M	precision_drawing_tools/pdt_menus.py
M	precision_drawing_tools/pdt_msg_strings.py

===================================================================

diff --git a/precision_drawing_tools/__init__.py b/precision_drawing_tools/__init__.py
index 1f1d4454..e99e7735 100644
--- a/precision_drawing_tools/__init__.py
+++ b/precision_drawing_tools/__init__.py
@@ -96,6 +96,7 @@ from .pdt_msg_strings import (
     PDT_DES_OFFDIS,
     PDT_DES_OFFPER,
     PDT_DES_OPMODE,
+    PDT_DES_OUTPUT,
     PDT_DES_PIVOTDIS,
     PDT_DES_PPLOC,
     PDT_DES_PPSCALEFAC,
@@ -358,6 +359,11 @@ class PDTSceneProperties(PropertyGroup):
         update=command_run,
         description=PDT_DES_VALIDLET,
     )
+    mathsout : FloatProperty(
+        name="Maths output",
+        default=0,
+        description=PDT_DES_OUTPUT,
+    )
     error : StringProperty(name="Error", default="")
 
     # Was pivot* -- is now pivot_*
@@ -449,6 +455,7 @@ classes = (
     PDTSceneProperties,
     PDTPreferences,
     pdt_bix.PDT_OT_LineOnBisection,
+    pdt_command.PDT_OT_CommandReRun,
     pdt_design.PDT_OT_PlacementAbs,
     pdt_design.PDT_OT_PlacementDelta,
     pdt_design.PDT_OT_PlacementDis,
diff --git a/precision_drawing_tools/pdt_command.py b/precision_drawing_tools/pdt_command.py
index 423bc83c..b293dc0d 100644
--- a/precision_drawing_tools/pdt_command.py
+++ b/precision_drawing_tools/pdt_command.py
@@ -23,6 +23,7 @@
 #
 import bpy
 import bmesh
+from bpy.types import Operator
 from mathutils import Vector
 import math
 from .pdt_functions import (
@@ -88,6 +89,7 @@ def pdt_help(self, context):
     label(text="- Math Options:")
     label(text="x, y, z: Send result to X, Y and Z input fields in PDT Design")
     label(text="d, a, p: Send result to Distance, Angle or Percent input field in PDT Design")
+    label(text="o: Send Maths Calculation to Output")
     label(text="")
     label(text="Note that commands are case-insensitive: ED = Ed = eD = ed")
     label(text="")
@@ -102,6 +104,26 @@ def pdt_help(self, context):
     label(text="'- Segments: 4 (int) -- choosing an even amount of segments gives better geometry")
     label(text="'- Profile: 0.5 (float[0.0;1.0]) -- 0.5 (default) yields a circular, convex shape")
 
+class PDT_OT_CommandReRun(Operator):
+    """Repeat Current Displayed Command."""
+
+    bl_idname = "pdt.command_rerun"
+    bl_label = "Re-run Current Command"
+    bl_options = {"REGISTER", "UNDO"}
+
+    def execute(self, context):
+        """Repeat Current Command Line Input.
+
+        Args:
+            context: Blender bpy.context instance.
+
+        Returns:
+            Nothing.
+        """
+        command_run(self, context)
+        return {"FINISHED"}
+
+
 def command_run(self, context):
     """Run Command String as input into Command Line.
 
@@ -129,7 +151,7 @@ def command_run(self, context):
         Valid Second Letters (as 'mode' - pg.command[1])
 
             A = Absolute XYZ, D = Delta XYZ, I = Distance at Angle, P = Percent
-            X = X Delta, Y = Y, Delta Z, = Z Delta (Maths Operation only)
+            X = X Delta, Y = Y, Delta Z, = Z Delta, O = Output (Maths Operation only)
             V = Vertex Bevel, E = Edge Bevel
 
             Capitals and lower case letters are both allowed
@@ -145,8 +167,6 @@ def command_run(self, context):
             Example; madegrees(atan(3/4)) - sets PDT Angle to smallest angle of 3,4,5 Triangle;
             (36.8699 degrees)
 
-            This is why all Math functions are imported
-
     Returns:
         Nothing.
     """
@@ -170,7 +190,7 @@ def command_run(self, context):
         context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
         return
     mode = cmd[1].lower()
-    if mode not in {"a", "d", "e", "g", "i", "p", "v", "x", "y", "z"}:
+    if mode not in {"a", "d", "e", "g", "i", "o", "p", "v", "x", "y", "z"}:
         pg.error = PDT_ERR_BADSLETTER
         context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
         return
@@ -178,16 +198,13 @@ def command_run(self, context):
     # --------------
     # Math Operation
     if oper == "M":
-        if mode not in {"x", "y", "z", "d", "a", "p"}:
+        if mode not in {"x", "y", "z", "d", "a", "p", "o"}:
             pg.error = f"{mode} {PDT_ERR_NON_VALID} Maths)"
             context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
             return
         exp = cmd[2:]
         namespace = {}
         namespace.update(vars(math))
-        if "," in exp:
-            pg.error = PDT_ERR_NOCOMMAS
-            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
         try:
             num = eval(exp, namespace, namespace)
         except ValueError:
@@ -206,6 +223,8 @@ def command_run(self, context):
             pg.angle = num
         elif mode == "p":
             pg.percent = num
+        elif mode == "o":
+            pg.mathsout = num
         return
     # "x"/"y"/"z" modes are only legal for Math Operation
     else:
diff --git a/precision_drawing_tools/pdt_menus.py b/precision_drawing_tools/pdt_menus.py
index 3095f775..a3b03a40 100644
--- a/precision_drawing_tools/pdt_menus.py
+++ b/precision_drawing_tools/pdt_menus.py
@@ -355,3 +355,7 @@ class PDT_PT_PanelCommandLine(Panel):
         row.label(text="Comand Line, uses Plane & Mode Options")
         row = layout.row()
         row.prop(pdt_pg, "command", text="")
+        # Try Re-run
+        row.operator("pdt.command_rerun", text="", icon="LOOP_BACK")
+        row = layout.row()
+        row.prop(pdt_pg, "mathsout", text="Maths Output")
diff --git a/precision_drawing_tools/pdt_msg_strings.py b/precision_drawing_tools/pdt_msg_strings.py
index 2c6cab25..72f55924 100644
--- a/precision_drawing_tools/pdt_msg_strings.py
+++ b/precision_drawing_tools/pdt_msg_strings.py
@@ -158,7 +158,8 @@ PDT_DES_LIBMATS       = "Materials in Library"
 PDT_DES_LIBMODE       = "Library Mode"
 PDT_DES_LIBSER        = "Enter A Search String (Contained)"
 PDT_DES_OBORDER       = "Object Order to Lines"
-PDT_DES_VALIDLET      = "Valid 1st letters; C D E G N P S V, Valid 2nd letters: A D I P"
+PDT_DES_VALIDLET      = "Valid 1st letters; C D E G N P S V, Valid 2nd letters: A D I O P"
+PDT_DES_OUTPUT        = "Output for Maths Operations"
 PDT_DES_PPLOC         = "Location of PivotPoint"
 PDT_DES_PPSCALEFAC    = "Scale Factors"
 PDT_DES_PPSIZE        = "Pivot Size Factor"



More information about the Bf-extensions-cvs mailing list