乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 11|回复: 11

[编程交流] Error: bad argument value: str

[复制链接]

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 17:47:39 | 显示全部楼层 |阅读模式
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] (#)
[2.12] (# "(vl-bt)" T #)
: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?
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 17:55:18 | 显示全部楼层
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.
回复

使用道具 举报

rlx

21

主题

1505

帖子

1551

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
81
发表于 2022-7-5 18:02:55 | 显示全部楼层
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
回复

使用道具 举报

28

主题

317

帖子

292

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 18:08:23 | 显示全部楼层
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).
 
Yeah, you can use the variable dwgprefix, it gives the drawing path
(strcat (getvar 'dwgprefix) TheFileName)
 
Cheers
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:14:01 | 显示全部楼层
 
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.:
  1. _$ (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.
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:17:39 | 显示全部楼层
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?
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:21:12 | 显示全部楼层
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.
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:30:01 | 显示全部楼层
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.
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:35:25 | 显示全部楼层
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.
回复

使用道具 举报

1

主题

8

帖子

7

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:37:01 | 显示全部楼层
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
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 00:03 , Processed in 0.971950 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表