Author Topic: vl-string-left-trim  (Read 1335 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2055
vl-string-left-trim
« on: December 14, 2019, 02:07:46 PM »
I can't seem to get this to work properly:


(substr (vl-filename-base (getvar "dwgname")) 1 16)
result = "190240 256830086"

(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30))
result = "190240 256830086 4420 Sugargrove Ln"

(vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)))
result = "Sugargrove Ln"
result should be = "4420 Sugargrove Ln"

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: vl-string-left-trim
« Reply #1 on: December 14, 2019, 02:34:45 PM »
You should try instead :

(substr (vl-filename-base (getvar "dwgname")) 17)

(vl-string-left/right-trim) is known with this behavior to remove additional characters that are found in pattern string... To me even (vl-string-trim) is not 100% reliable... The best choice is to try to avoid them and use ordinary (substr) function...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1777
  • BricsCAD 18
Re: vl-string-left-trim
« Reply #2 on: December 14, 2019, 03:19:19 PM »
The first argument of the vl-string-left-trim function is not a pattern but a character set. So what the OP is seeing is the correct bahavior.

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #3 on: December 14, 2019, 04:02:22 PM »
I think I have found the problem.
When I rename the file, I get the vl-string-left-trim error.
Other wise it works ok.

I'm using BricsCAD
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: vl-string-left-trim
« Reply #4 on: December 14, 2019, 05:01:59 PM »
(vl-string-left/right-trim) is known with this behavior to remove additional characters that are found in pattern string... To me even (vl-string-trim) is not 100% reliable... The best choice is to try to avoid them and use ordinary (substr) function...

I get the vl-string-left-trim error.

Note that this behaviour is not an error, nor is it an issue with the apparent 'reliability' of the vl-string-*-trim functions. The vl-string-left-trim function is operating exactly as designed and described by the documentation, removing all characters which appear in the supplied character set argument.

In the given example posted by GDF, the character set is:

Code: [Select]
"190240 256830086"
Therefore, the vl-string-left-trim function will remove all occurrences of the characters " ","0","1","2","3","4","5","6","8","9" from the left of the string, until a character is reached which is not a member of this set.

Applied to the string:

Code: [Select]
"190240 256830086 4420 Sugargrove Ln"
This correctly returns the result:

Code: [Select]
"Sugargrove Ln"
As the characters " ", "0", "2" & "4" are a member of the character set.

This discussion is very similar to this recent thread.

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #5 on: December 14, 2019, 09:15:22 PM »
Sorry, I'm still confused


Example one: (file has been renamed with 190240 as part of the file Name)
190240 256830086 4420 Sugargrove Ln L10 B05 3013 TXW YR V3.dwg

(substr (vl-filename-base (getvar "dwgname")) 1 16)
result = "190240 256830086"

(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30))
result = "190240 256830086 4420 Sugargrove Ln"

(vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)))
result = "Sugargrove Ln"
result should be = "4420 Sugargrove Ln"




Example two:  (original file 190239 as part of the file Name)
190239 256830086 4420 Sugargrove Ln L10 B05 3013 TXW YR V3

(substr (vl-filename-base (getvar "dwgname")) 1 16)
result = "190239 256830086"

(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30))
result = "190239 256830086 4420 Sugargrove Ln"

(vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)))
result = "4420 Sugargrove Ln"


Code: [Select]
;;;Victor Delgado  VDelgado@alhansen.com
(defun ARCH:UpdateBlocks  (BlockName AttTag AttVal / ssBlocks ssObjects Block)
  (vl-load-com)
  (setq ssBlocks (ssget "x" (list (cons 2 BlockName))))
  (if ssBlocks
    (progn (setq ssObjects
                  (vla-get-ActiveSelectionSet
                    (vla-get-ActiveDocument (vlax-get-acad-object))))
           (vlax-for
                  Block  ssObjects
             (foreach
                    Attribute  (vlax-invoke Block "GetAttributes")
               (if (= (vla-get-TagString Attribute) AttTag)
                 (vla-put-TextString Attribute AttVal))
               (vla-update Attribute)))))
  (princ))

(ARCH:UpdateBlocks "DRHortonTBH" "ADD" (vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 27))))

« Last Edit: December 14, 2019, 09:38:06 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ribarm

  • Water Moccasin
  • Posts: 2334
  • Marko Ribar, architect
Re: vl-string-left-trim
« Reply #6 on: December 15, 2019, 12:15:23 AM »
Sorry, I'm still confused

Example one: (file has been renamed with 190240 as part of the file Name)
190240 256830086 4420 Sugargrove Ln L10 B05 3013 TXW YR V3.dwg

(substr (vl-filename-base (getvar "dwgname")) 1 16)
result = "190240 256830086"

(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30))
result = "190240 256830086 4420 Sugargrove Ln"

(vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)))
result = "Sugargrove Ln"
result should be = "4420 Sugargrove Ln"




Example two:  (original file 190239 as part of the file Name)
190239 256830086 4420 Sugargrove Ln L10 B05 3013 TXW YR V3

(substr (vl-filename-base (getvar "dwgname")) 1 16)
result = "190239 256830086"

(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30))
result = "190239 256830086 4420 Sugargrove Ln"

(vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)))
result = "4420 Sugargrove Ln"

It is perfectly fine - look in your second example :
Char set : "190239 256830086" don't contain number 4, so left trimming is fine - first char from left is 4 : "4420 Sugargrove Ln"

But as I stated before, if you know this numbers marked red :
(vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)
        (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)))

I would suggest that you use more confident - just simple :
(substr (getvar 'dwgname) 17 (- 30 16))
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1777
  • BricsCAD 18
Re: vl-string-left-trim
« Reply #7 on: December 15, 2019, 04:09:51 AM »
Maybe use this instead:
Code: [Select]
(vl-string-subst "" "ab" "ababc") => "abc"

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #8 on: December 15, 2019, 07:28:25 AM »
Thanks everyone for the help!
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #9 on: December 15, 2019, 08:35:35 AM »
Because the address is of different lengths in the drawing file names.
I got the following to work in all cases:

(substr (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 27)) 18)

I was going about it the wrong way using vl-string-left-trim.

Thanks again.




Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #10 on: December 15, 2019, 11:41:46 AM »
This is my updated code, that propagates the titleblock attributes based upon the drawing file name.


Code: [Select]

(defun C:TBUP (/ client subdiv city)
  ;;(command ".qsave")
  ;;(ARCH:UpdateBlocks "DRHortonTBH" "DRHNO" (getstring T "\n* Enter DRH #: \"3013 XL V? R?\""))
  (cond
    ((/= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "DRHNO" (strcat (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 13) 5)
        (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 4) 5))))
    ((= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "DRHNO" (strcat (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 16) 5)
        (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 7) 8)))))
  (ARCH:UpdateBlocks "DRHortonTBH" "DATE" (ARCH:C_DATE-ISSUE (getvar "tdupdate")))
  (ARCH:UpdateBlocks "DRHortonTBH" "BPSNO" (vl-Filename-Base (vl-Filename-Directory (getvar "DwgPrefix"))))
  ;;(ARCH:UpdateBlocks "DRHortonTBH" "PLANNO" (strcat "PLAN " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 17) 14)))
  (cond
    ((/= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "PLANNO" (strcat "PLAN " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 17) 14))))
    ((= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "PLANNO" (strcat "PLAN " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 20) 17)))))
  (ARCH:UpdateBlocks "DRHortonTBH" "JOBNO" (substr (vl-filename-base (getvar "dwgname")) 8 9))
  (setq client (getstring T "\n* Enter Residence Client:"))
  (cond
    ((/= client "")(ARCH:UpdateBlocks "DRHortonTBH" "RES" client))
    ((= client "")(ARCH:UpdateBlocks "DRHortonTBH" "RES" "RESIDENCE")))
  (setq client nil)
  ;;(ARCH:UpdateBlocks "DRHortonTBH" "SUB" (getstring T "\n* Enter Subdivision:"))
  (setq subdiv (getstring T "\n* Enter Subdivison:"))
  (cond
    ((/= subdiv "")(ARCH:UpdateBlocks "DRHortonTBH" "SUB" subdiv))
    ((= subdiv "")(ARCH:UpdateBlocks "DRHortonTBH" "SUB" "Highcroft Estates, Phase 1")))
  (setq subdiv nil)
  (cond
    ((/= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "LB" (strcat "LOT " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 24) 2)
        ", BLOCK " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 20) 2))))
    ((= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "LB" (strcat "LOT " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 27) 2)
        ", BLOCK " (substr (getvar "dwgname")(- (strlen (getvar "dwgname")) 23) 2)))))
  ;;(ARCH:UpdateBlocks "DRHortonTBH" "ADD" (vl-string-left-trim (substr (vl-filename-base (getvar "dwgname")) 1 16)(substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 27))))
  (cond
    ((/= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "ADD" (substr (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 27)) 18)))
    ((= (substr (getvar "dwgname")(- (strlen (vl-filename-base (getvar "dwgname"))) 1) 1) "R")
      (ARCH:UpdateBlocks "DRHortonTBH" "ADD" (substr (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 30)) 18))))
  ;;(ARCH:UpdateBlocks "DRHortonTBH" "CITY" (getstring T "\n* Enter City State:"))
  (setq city (getstring T "\n* Enter City State:"))
  (cond
    ((/= city "")(ARCH:UpdateBlocks "DRHortonTBH" "CITY" city))
    ((= city "")(ARCH:UpdateBlocks "DRHortonTBH" "CITY" "Arlington, TX 76001")))
  (setq city nil) 
  (ARCH:MsgBox1
    " Arch2Program© : Message"
    64
    (strcat
      "DR Horton Titleblock Updated Successfully"
    )
    2
  )
  (princ))

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

MP

  • Seagull
  • Posts: 17630
Re: vl-string-left-trim
« Reply #11 on: December 15, 2019, 12:24:38 PM »
I can't help thinking there's an abbreviated version begging to be outed. Is it possible to get a representative sample of dwg names?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #12 on: December 15, 2019, 01:06:16 PM »
Michael, see previous post above...

190240 256830086 4420 Sugargrove Ln L10 B05 3013 TXW YR V3.dwg

190240 256830086 1234 Anystreet Drive L10 B05 3013 TXW YR V3 R2.dwg
« Last Edit: December 15, 2019, 01:10:57 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

MP

  • Seagull
  • Posts: 17630
Re: vl-string-left-trim
« Reply #13 on: December 15, 2019, 01:24:41 PM »
Thanks GDF.

Would the rev number (assuming that's what it represents) ever be more than 1 digit or alpha numerical?

"190240 256830086 1234 Anystreet Drive L10 B05 3013 TXW YR V3 R12.dwg"

"190240 256830086 1234 Anystreet Drive L10 B05 3013 TXW YR V3 R1A.dwg"

"190240 256830086 1234 Anystreet Drive L10 B05 3013 TXW YR V3 R12A.dwg"


?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

GDF

  • Water Moccasin
  • Posts: 2055
Re: vl-string-left-trim
« Reply #14 on: December 15, 2019, 01:38:17 PM »
No
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64