+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Apr 2016
    Posts
    8

    Default Error: bad argument value: string position out of range 17

    Registered forum members do not see this ad.

    I have been having problems loading a lisp that has previously worked, without a problem for years, but now throws a message "Error: bad argument value: string position out of range 17".

    The lisp is loaded on opening of each drawing in the acaddoc.lsp, which has not changed. It is supposed to open a csv and update blocks.

    From what I can tell, it seems as though AutoCAD cant find the csv file in the Working Directory. (When opening a drawing with the lisp loaded in acaddoc.lsp specifying the name via findfile "name.csv")

    When I load the lisp through APPLOAD and manually select the file, via getfiled, it works. (findfile Nil)


    The Name of the csv has not changed in the acaddoc.lsp and the file is definitely in the same folder as the opened drawing.

    So my questions are,

    Is there any Variable in AutoCAD (Map 3d 2016) that could have changed to cause this?

    Is it a bug?

    Are there methods of finding the specified file in the same directory, (as the opened drawing), other than findfile? vla-get-FoundPath perhaps?

    How can I debug using VLISP?

    I tried (VL-BT) and get this;

    Backtrace:
    [0.19] (VL-BT)
    [1.15] (#<SUBR @00000005a96e3cc8 -rts_top->)
    [2.12] (#<SUBR @0000000588588700 veval-str-body> "(vl-bt)" T #<FILE internal>)
    :CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
    :ARQ-SUBR-CALLBACK.3 (nil 0)
    nil

    I'm not sure what it means?
    It's the first time I've used VLISP and only have a basic knowledge of VBA through a TAFE course, which was really more about VBS.

    At this stage I'm not sure if its a setting or AutoCAD is not looking in the right place?

    I have tried resetting autocad to default which didn't work, then I reinstalled autocad, which also didn't work. Then I updated to windows 10 just to see if some setting was changed or broken. None of those steps worked.

    I had been playing around with excel,( and had improved the spreadsheet which output the csv to also put out a xlsx, for a Data Link), in the previous weeks, which gave me the possibility that I had unwittingly changed a setting somewhere. The excel spreadsheet had worked with the lisp for at least 2 weeks before the error started to occur.

    One other thing to mention is that when excel is trying to save the csv and autocad is reading it,( has it open maybe? through the manual loading of it through the lisp), it comes up with an error 1004 or something. This happened to a co-worker who tried to debug it, and we tried alternate ways of saving the csv.

    After that moment the problems started.

    We tried the original untouched excel spreadsheet, acaddoc.lsp and method like we always had done, but now the error always occurs.

    Please, are there any suggestions?

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,085

    Default

    Hi,

    Welcome to CADTutor.

    Here I am talking about AutoCAD in general and not about Map 3D and the following answer is just a work around and might not be the desired solution.

    Remove the findfile function and add the full name of the *.csv excel file to open function if your directory work is not changing from drawing to another.
    If the the above suggestion did not work and your program is not that big, you can post the codes and many users here could help as best as they can including me.

    Good luck.

  3. #3
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    631

    Default

    Hi TimG,


    Maybe your code has not changed but your excel sheet? The cell formatting , so you should check if the value passed from excel to your lsp returns the value you want.


    gr, Rlx

  4. #4
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    248

    Default

    I noticed that findfile doesnt always work as expected on the current drawing folder. (i think) its depending on the way you open the drawing (using open, double clicking or drag and drop).

    Are there methods of finding the specified file in the same directory, (as the opened drawing), other than findfile? vla-get-FoundPath perhaps?
    Yeah, you can use the variable dwgprefix, it gives the drawing path
    (strcat (getvar 'dwgprefix) TheFileName)

    Cheers
    Different goal also quite often means different path...

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,363

    Default

    Quote Originally Posted by TimG View Post
    I have been having problems loading a lisp that has previously worked, without a problem for years, but now throws a message "Error: bad argument value: string position out of range 17".
    This error typically results from evaluating the vl-string-search or vl-string-position functions with the starting index argument outside of the range of available characters, e.g.:
    Code:
    _$ (vl-string-search "a" "abc" 4)
    ; error: bad argument value: string position out of range 4
    
    _$ (vl-string-position 65 "abc" 4)
    ; error: bad argument value: string position out of range 4
    Therefore, to debug the program, I would search the code for either of these functions, or follow the first section of my tutorial here.

    I would then analyse the string argument being passed to the function, as the expression is evidently expecting a string with length greater than 18 characters.

    EDIT: I have now updated my Error Message Troubleshooter to include this error.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Apr 2016
    Posts
    8

    Default

    Hi Tharwat, Thanks for your reply.

    I copied the full path to the drawing folder and the csv name into the acaddoc.lsp, and opened one of the drawings to test if it works.

    The result was interesting, I thought, because it returned a message that the csv was "not found", that contained no back slashes "/ " and also had "Ž4" after the first folder.

    JOBSŽ4 xxxxxx xxx - xxxxxxx xx xxxxxxxxxxAutoCadDWGREG.csv not found. - THE RESULT

    J:\JOBS\6164 xxxxxx xxx - xxxxxxx xx xxxxxxxxxx\AutoCAD\DWGREG.csv - WHAT IT SHOULD BE

    [Note: I just censored the project name for company privacy.]

    Is the 616 being replaced by "Ž"?

    Why have the "\" disappeared from the name?

  7. #7
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Apr 2016
    Posts
    8

    Default

    Hi rlx,

    I know that the formatting has definitely changed throughout the trial and error coding attempts I made before I got it working.

    To get the xlxs to populate my autocad table in the font we use, I changed it to isocp. I was trying to get the data link to bring the text through the same as in the excel sheet, with underlined titles and text style.

    In that process I had changed other cells in the original workbook sheets by mistake, so I cleared all cell formatting and thought I had reset the text font back to Calibri as it was originally.
    I also coded it to clear contents and formatting of the destination sheet each time the create xlxs button was pressed.

    However, in the process of elimination, I created a new csv manually from scratch just to test the acaddoc.lsp, which still returned the error.
    Also using earlier versions of the excel spreadsheet still failed to work as before.

    Just for clarity, the xlxs populates the Drawing Index table with the titles and drawing numbers, and the DWGREG.csv fills out the Title blocks in the drawing set.

    The csv is what is problematic and it is copied and pasted out of the parent workbook without formatting changes. Although as noted, the parent workbook underwent many unintended changes before I got it to work as I envisioned it.

    It did all work for about 2 weeks before my error started to occur.

  8. #8
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Apr 2016
    Posts
    8

    Default

    Hi Jef!,

    Nice use of "!" in your name by the way. It makes it seem like everyone who replies to you is extra excited!

    Pasting your suggestion into the command line returned the desired results.

    Command: (strcat (getvar 'dwgprefix) "dwgreg.csv")

    "J:\\JOBS\\6164 xxxxxxx xxx - xxxxxxxx xx xxxxxxxxxxxx\\AutoCad\\dwgreg.csv"

    Both capitals and lowercase worked for the name and returned the same result, just to eliminate that variable for my own understanding.

    Its good to know that it can be found by that method. Thanks.

  9. #9
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Apr 2016
    Posts
    8

    Default

    Hi Lee Mac!!,

    I was hoping for your help.

    It is your Update attributes (UpdateTitleBlock.lsp) that we have been using without fail, since before I started working here, and I'm sorry to say that I broke it...

    Well, I have in no way altered it, but in any case, have somehow caused something that it doesn't like. (It may not have actually been me, I would like to think, but in light of my recent misadventures into VBA; it is more than likely.)

    This is where it breaks with the error,

    (defun LM:csv->lst ( str sep pos / s )
    (cond
    ( (not (setq pos (vl-string-search sep str pos)))
    (if (wcmatch str "\"*\"")
    (list (LM:csv-replacequotes (substr str 2 (- (strlen str) 2))))
    (list str)
    )
    )
    ( (or (wcmatch (setq s (substr str 1 pos)) "\"*[~\"]")
    (and (wcmatch s "~*[~\"]*") (= 1 (logand 1 pos)))
    )
    (LM:csv->lst str sep (+ pos 2))
    )
    ( (wcmatch s "\"*\"")
    (cons
    (LM:csv-replacequotes (substr str 2 (- pos 2)))
    (LM:csv->lst (substr str (+ pos 2)) sep 0)
    )
    )
    ( (cons s (LM:csv->lst (substr str (+ pos 2)) sep 0)))
    )
    )

    Note also, my reply above that results with the "Ž" value returned when I pasted the full file path as utb:csv instead of just the name.

    (setq utb:csv "J:\JOBS\6164 xxxxxxx xxx - xxxxxxxx xx xxxxxxxxxxxx\AutoCad\dwgreg.csv") ;; e.g. (setq utb:csv "C:/myfolder/myfile.csv") - As a test

    (setq utb:csv "dwgreg.csv") ;; e.g. (setq utb:csv "C:/myfolder/myfile.csv") - What has always previously worked, until last week.

    Do you know what causes the "Ž" to occur?

    Thanks for your contributions, I have seen a lot of your work and help on the various forums as I have been trying to learn on the job with this project of late, and you show a heavy presence.

    Note to others: I'm not down playing your help, as it is all very much appreciated.

    ***EDIT***

    I noticed that copying the path from explorer uses the single "\". Which is neither "\\" or "/" , as I understand is the correct Syntax to use in a .lsp.

    On testing,

    (setq utb:csv "J:\\JOBS\\6164 xxxxxxx xxx - xxxxxxxx xx xxxxxxxxxxxx\\AutoCad\\dwgreg.csv") ;; e.g. (setq utb:csv "C:/myfolder/myfile.csv") - As a test

    This worked as expected.


    (setq utb:csv "J:/JOBS/6164 xxxxxxx xxx - xxxxxxxx xx xxxxxxxxxxxx/AutoCAD/dwgreg.csv") ;; e.g. (setq utb:csv "C:/myfolder/myfile.csv") - As a test

    This worked as expected.


    (setq csvfile "DWGREG.csv") ;; e.g. (setq csvfile "C:/myfolder/myfile.csv") - As a test (both lower and uppercase)

    Error: bad argument value: string position out of range 17


    (setq csvfile "/DWGREG.csv") ;; e.g. (setq csvfile "C:/myfolder/myfile.csv") - As a test (both lower and uppercase)

    DWGREG.csv not found.

    (setq csvfile "\\DWGREG.csv") ;; e.g. (setq csvfile "C:/myfolder/myfile.csv") - As a test (both lower and uppercase)
    DWGREG.csv not found.

    I'm not sure if this helps, but it would partly explain where the "Ž" came from.
    Last edited by TimG; 19th Apr 2016 at 03:37 am.

  10. #10
    Forum Newbie
    Using
    Map 3D 2016
    Join Date
    Apr 2016
    Posts
    8

    Default

    Registered forum members do not see this ad.

    This is the Module attached to the Create CSV button in excel.

    I tried to add checks along the way to see what was happening.
    My goal in part was to stop the error 1004 for coming up while trying to saveas if the csv was already open.
    It does seem as though AutoCAD has it open sometimes if loaded manually through the UpdateTitleBlock.lsp with the file name as Nil.

    (setq csvfile Nil) ;; e.g. (setq csvfile "C:/myfolder/myfile.csv")

    I'm not sure how to determine what autocad does at all, or how it affects the state of the file.

    As you may see I have just copied and pasted code from the net and tried to get it to work.
    The first section is how it used to be before I started playing with it. (This was a week after the errors occurred so I don't think it caused it at all)

    Sub SaveAsCSV()
    '
    ' export Macro

    'strName = ThisWorkbook.Path & "\" & "dwgreg.csv"

    'Range("3:500").Select
    'Selection.Copy
    'Workbooks.Add
    'ActiveSheet.Paste
    'ActiveWorkbook.SaveAs filename:=strName, FileFormat:=xlCSV, CreateBackup:=False
    'Application.DisplayAlerts = False
    'ActiveWorkbook.Close
    'Application.DisplayAlerts = True

    'Application.ScreenUpdating = True

    'MsgBox "File has been Created and Saved as: " & vbCr & strName, , "Copy & Save Report"

    'end Sub
    Dim wbS As Workbook

    Dim wbS2 As Workbook, wbT2 As Workbook
    Dim wsS2 As Worksheet, wsT2 As Worksheet

    Set wbS = ThisWorkbook
    Set wbS2 = ThisWorkbook 'workbook that holds this code
    Set wsS2 = wbS2.ActiveSheet


    wsS2.Copy
    Set wbT2 = ActiveWorkbook 'assign reference asap


    Set wsT2 = wbT2.Worksheets("MRWA")
    wsT2.Name = "DRAWING REGISTER" 'rename sheet

    wsT2.Range("1:2").Select
    Selection.DELETE

    ActiveSheet.Shapes.Range(Array("Button 1")).Select
    Selection.DELETE

    Cells.Select
    Selection.ClearFormats

    'MsgBox wbS2.Path, , "PATH"


    'Test to see if the folder path existsSheets("Drawing Index").


    Dim FolderPath2 As String

    FolderPath2 = wbS2.path
    If Right(FolderPath2, 1) <> "\" Then
    FolderPath2 = FolderPath2 & "\"
    End If

    If Dir(FolderPath2, vbDirectory) <> vbNullString Then
    MsgBox "Folder exists"
    Else
    MsgBox "Folder doesn't exist"
    End If


    'test if file exists


    Dim FilePath2 As String
    Dim TestStr2 As String

    FilePath2 = wbS2.path & "\DWGREG.csv"

    'MsgBox FilePath2, , "FILE PATH"

    TestStr2 = ""
    On Error Resume Next
    TestStr2 = Dir(FilePath2)

    'MsgBox TestStr2 & "= File Name", , "Test string equals " & TestStr2

    On Error GoTo 0
    If TestStr2 = "" Then
    MsgBox "File doesn't exist", , "FILE NULL"
    Else
    MsgBox "File exists", , "TestStr2 = " & TestStr2
    End If





    'Test if file is open

    'MsgBox "Is Drawing Open?", vbOKOnly, "TEST"


    If bIsBookOpen("DWGREG.csv") Then

    MsgBox ("DWGREG.csv is open!" & vbCr + vbCr + "CLOSE THE SPREADSHEET and TRY AGAIN"), , "DRAWING REGISTER IS OPEN"

    ActiveWorkbook.Close SaveChanges:=False


    Exit Sub



    Else

    'MsgBox "The Book is not open!", , "DRAWING REGISTER IS NOT OPEN"

    End If


    Dim InputFolder As String
    Dim OutputFolder As String

    InputFolder = wbS.path

    'MsgBox InputFolder, , "input folder"

    'MsgBox ActiveWorkbook.FullName, , "Full Name"

    'MsgBox ActiveWorkbook.path, , "Path"

    'MsgBox wbS.FullName


    'save new workbook

    wbT2.SaveAs filename:=wbS.path & "\DWGREG", FileFormat:=6, CreateBackup:=False

    Application.DisplayAlerts = False

    Application.ScreenUpdating = False


    ActiveWorkbook.Close

    Application.DisplayAlerts = True

    Application.ScreenUpdating = True

    'MsgBox wbS.FullName

    'MsgBox ActiveWorkbook.Path

    strName2 = wbS2.path & "\DWGREG.csv"

    MsgBox "File has been Created and Saved as:" & vbCr & strName2, , "COPY & SAVE REPORT"
    End Sub

Similar Threads

  1. Replies: 3
    Last Post: 16th Jun 2014, 01:50 pm
  2. Error: bad argument value: string position out of range 72
    By Oliver_cook1 in forum AutoCAD Bugs, Error Messages & Quirks
    Replies: 0
    Last Post: 13th Mar 2014, 11:15 am
  3. ; error: bad argument type: VLA-OBJECT
    By Jef! in forum AutoCAD Bugs, Error Messages & Quirks
    Replies: 18
    Last Post: 22nd Oct 2010, 07:39 pm
  4. IF and COND argument as a range in lisp.
    By NYATI in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 22nd Sep 2010, 10:43 am
  5. using or within vl-string-position
    By TuFoFi in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 21st Jan 2006, 08:43 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts