Problem

It is to convert scale variables/ parameters to string or back to numeric type. This is very tricky, if the notation is not metric, but the imeprial one, which is used in USA.

Solution

The solution is a simple case detection with string operations. See also the table for GLOB_SCALE.

Script - Scale from string to numeric

!»» Example with automatic scale string of drawing stamps
scaleS=AC_DrawingScale

!»» CONVERT SCALE-STRING TO NUMERIC
scaleN=0
!»» Cut of "M" at the beginning. Not needed.
s=STRSTR(scaleS,"M")
IF s
THEN scaleS=STRSUB(scaleS,s+1,STRLEN(scaleS)-s)
!»» Imperial or metric?
s=STRSTR(scaleS,"=")
!»» Converting ...
IF s THEN
  !»» Scale notation is imperial
  sts=SPLIT(STRSUB(scaleS,1,s-1),"%n",lengthR)
  sts=SPLIT(STRSUB(scaleS,s+1,STRLEN(scaleS)-s),"%n",lengthP)
  IF lengthR THEN scaleN=lengthP/lengthR ELSE scaleN=MAX(lengthP,0)
  ELSE
  !»» Scale notation is metric
  s
=STRSTR((scaleS,":")
  IF s THEN
    sts=SPLIT(STRSUB(scaleS,1,s-1),"%n",lengthR)
    sts=SPLIT(STRSUB(scaleS,s+1,STRLEN(scaleS)-s),"%n",lengthP)
    IF lengthR THEN scaleN=lengthP/lengthR ELSE scaleN=MAX(lengthP,0)
    ELSE
    sts=SPLIT(scaleS,"%n",scaleN)
    ENDIF
  ENDIF
!»» scaleN contains the divisor of the scale.


!»» PRINT RESULTS

TEXT2 0,0,
"»"+scaleS+"« - »"+STR("%^.3",scaleN)+"«"

Script - Scale from numeric to string (imperial)

!»» Example with project scale
scaleN=GLOB_SCALE

!»» CONVERT NUMERIC TO IMPERIAL NOTATION
IF scaleN<2000 AND NOT(scaleN>=100 AND FRA(scaleN/10)<0.001 ) THEN
  scaleI=
STR("%^.128fi",1" * 12/scaleN)+´=1'0"´
  ELSE
  scaleI=´1"=´+
STR("%^.32ffi",scaleN*1")
  ENDIF
!»» scaleI contains the imperial scale string.


!»» PRINT RESULTS

TEXT2 0,0,
"»"+STR("%.3",scaleN)+"«  -  »"+scaleI+"«"

Script - Scale from numeric to string (metric)

!»» Example with project scale
scaleN=GLOB_SCALE


!»» CONVERT NUMERIC TO METRIC NOTATION

praefix="M "
IF scaleN<1 THEN
  scaleM=praefix+
STR("%^.0m",1/scaleN)+":1"
  ELSE
  scaleM=praefix+"1:"+STR("%^.0m",scaleN)
  ENDIF
!»» scaleM contains the metric scale string.

!»» PRINT RESULTS

TEXT2 0,0,
"»"+STR("%.3",scaleN)+"«  -  »"+scaleM+"«"