0

Original question: how to copy a text/numeric field value to clipboard on linux for blender v2.93.4? https://blender.stackexchange.com/questions/239139/how-to-copy-a-text-numeric-field-value-to-clipboard-on-linux-for-blender-v2-93-4

I open blender,
click on the cube,
show it's transform,
click on Dimension X,
it selects the text "2 m",
I type 5, hit enter, it shows "5 m", I click on it again, it selects "5 m",
I hit ctrl+c while the mouse is over the "5" selected number,
I hit TAB (goes to Y field),
I hit ctrl+v but it paste something that was on clipboard before, not "5 m"! not even "5" if I try it! The problem is that it does not COPY to clipboard, it can paste from but not copy to!

I added several keymapings for the "text.copy" action (beyond ctrl+c ctrl+insert), like mouse move, F5, etc but the problem seems to be blender cant send anything to the X clipboard.

I tried to find a way to let it dump to terminal or the blender info, but I cant find a way to let it happen with precision.
If I run blender like blender --log "*undo*" it will dump imprecise displayed value like "2.12 m" instead of precise full value "2.12345", it helps but not enough.
If it could be logged with precision, if the displayed value could be shown precisely, may be it could work.

Any other tricks you can imagine that could let it happen?

gcore ... |strings can find a unique "plain text" number I type there (3 times while the text is seleted, one time while not), but there is no constant text nearby that could be used as a clue/tip/hook that it is the selected text. May be something hexadecimal?

I think this may be some python bug? but I couldnt find where in blender code yet.

blender 2.93.4 ubuntu 20.04

Related: https://blender.stackexchange.com/questions/124294/clipboard-not-working-on-ubuntu-18-04-in-blender-2-79b, but nothing there helps.

1
  • I found there is some problem related to parcellite, if I pkill it, blender will copy text normally! Trying to find a way to make both cope. Commented Oct 9, 2021 at 21:13

1 Answer 1

0

It was a problem related to parcellite.
To make blender and parcellite cope, you have to disable parcellite's "Clipboard/UseCopy(Ctrl+C)" option, and let it work only using the "Primary(selection)".


Old overkill answer:

what the script below does?

  • takes a screenshot from the mouse selection,
  • OCR it,
  • send it to clipboard
  • or inform on failure.

totally overkill, but may work for other applications too:

cat >copyThruOCR.sh

#!/bin/bash

echo "HELP:"
echo "depends on: scrot, tesseract, yad, xterm"
echo "bind this script to ex.: Alt+C using xbindkeys-config (remember to run xbindkeys just after)"
echo "use dark mode for best contrast on the application, so ex.: clicking the the field in blender will make it black background and white text!"
echo "tip: select more to the left than the limit of the text/number, works better"
echo "tip: select just below the text/number, if it is too much below it may just fail"
echo "it may still fail sometimes..."

set -x
FUNC() {
  strFl="/tmp/`basename $0`.png";
  rm "$strFl" "$strFl.txt"
  bFail=false
  str=""
  strP=""
  fSleep=0.25
  iScrotRetryMax=8; # 2s
  for((iScrotRetry=0;iScrotRetry<iScrotRetryMax;iScrotRetry++));do
    if scrot -s "${strFl}";then break;fi
    
    declare -p iScrotRetry
    sleep $fSleep;
  done
  if [[ -f "${strFl}" ]];then
#    if tesseract --dpi 300 --psm 8 "${strFl}" "$strFl";then
#    if tesseract --dpi 300 "${strFl}" "$strFl";then
    if tesseract --psm 6 "${strFl}" "$strFl" -c tessedit_char_whitelist="+-.0123456789" >/dev/null 2>&1;then
      str="$(head -n 1 "${strFl}.txt")" #1st line
      str="$(echo "$str" |cut -d " " -f1)" #1st word/column
      str="$(echo "$str" |tr -d "\r\n ")" #remove anything invalid
      
      echo "RESULT:"
      echo "$str"

      echo   
      echo "TextFile:"   
      cat "${strFl}.txt"   
      echo
      
      if [[ -z "`echo -n "${str}" |tr -d '[:digit:].+-'`" ]];then #COMMENT this number check if you prefer everything
        echo "COPYING TO CLIPBOARD: '${str}'"    
        echo -n "$str" |xclip -i -selection primary -rmlastnl;   
        echo -n "$str" |xclip -i -selection secondary -rmlastnl;   
        echo -n "$str" |xclip -i -selection clipboard -rmlastnl;   
      else
        strP="PROBLEM: not a number"
        bFail=true
      fi
    else
      strP="PROBLEM: tesseract fail"
      bFail=true
    fi
  else
    strP="PROBLEM: scrot fail"
    bFail=true
  fi
  
  echo "$strP"
  if $bFail;then yad --geometry=100x50+0+0 --title "`basename $0` FAILED" --text "$strP. '$str'" --timeout 1 --ontop --center;fi #COMMENT to get no warning

  read -p "press a key to exit (2s)..." -t 2 -n 1
};export -f FUNC;

xterm -geom 50x100+0+0 -e bash -c FUNC;exit #COMMENT to not show terminal log
FUNC

if you can improve it (make it more reliable), drop your tips to help!
I would like to let it automatically grab a rectangle around the mouse location, the problem is a way to clean it's unnecessary contents in a way that the OCR will work properly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .