Message 1 of 5
Script not working with accreconsole

Not applicable
02-09-2021
10:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I want to create automated layer change based on block attributes which works from accreconsole. However this is my first time working with AutoCAD scripts so it is not going too well..
Currently I have a simple script that I want to launch from accreconsole:
(load "D:/scripts/load.lsp")
(c:run)
The loaded lisp-file looks like this:
(defun c:run ()
(VL-VBALOAD "D:/scripts/Colorify.dvb")
(command "vbarun" "Colorify")
(command "save")
(princ)
)
The launched VBA code looks like this:
Public Sub Colorify()
Dim ent As AcadEntity
Dim blk As AcadBlockReference
Dim atts As Variant
Dim att As AcadAttributeReference
Dim i As Integer
For Each ent In ThisDrawing.ModelSpace
If TypeOf ent Is AcadBlockReference Then
Set blk = ent
atts = blk.GetAttributes()
For i = 0 To UBound(atts)
Set att = atts(i)
tag = att.TagString
If tag = "EA" Then
text = att.TextString
If text = "0" Then
blk.Layer = "L1"
End If
If text = "1" Then
blk.Layer = "L2"
End If
If text = "2" Then
blk.Layer = "L3"
End If
If text = "3" Then
blk.Layer = "L4"
End If
End If
Next
End If
Next
End Sub
When I start the first script inside AutoCAD using the SCRIPT-command everything works fine, but when I try to set up a batch job to run the script via accreconsole nothing happens, does anyone know what I am doing wrong?
Here is my batch job:
FOR %%f IN ("%~dp0*.dwg") DO "C:\Program Files\Autodesk\AutoCAD 2017\accoreconsole.exe" /i "%%f" /s "%~dp0scripts\load.scr" /l en-US
del /s /q /f %~dp0*.bak