Script not working with accreconsole

Script not working with accreconsole

Anonymous
Not applicable
741 Views
4 Replies
Message 1 of 5

Script not working with accreconsole

Anonymous
Not applicable

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

 

0 Likes
742 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

1st question is does Aeccorconsole support VBA ? Could not find anything quickly. Have you tested.

 

You may have to resort to using normal script function ie "OPEN" yes time will become a factor as you Open update and save.

 

Should your script just be 

(VL-VBALOAD "D:/scripts/Colorify.dvb")
	(command "vbarun" "Colorify")
	(command "save")

 

Message 3 of 5

Anonymous
Not applicable

Solved problem by switching from accreconsole to Script pro 2.0!

0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

What was the answer re running VBA in aeccoreconsole ?

0 Likes
Message 5 of 5

Anonymous
Not applicable

The VBA load row returns no errors, but doesn't seem to work. Might be there is incorrect formatting on the path on my command.

 

If I only run the load row and save command the VBA file is not included to the drawing when I open it on AutoCAD after run (When the same command is run in AutoCAD the VBA file can be found when the VBA editor is opened)

 

I tried all run VBA commands I found and they all returned unknown command error, so running VBA from accreconsole doesn't seem to work for me at least

 

0 Likes