Author Topic: LISP working individually but not through "accoreconsole.exe"  (Read 2954 times)

0 Members and 1 Guest are viewing this topic.

MasterMiner

  • Mosquito
  • Posts: 6
  • Mining Engineer - English/Français
LISP working individually but not through "accoreconsole.exe"
« on: September 25, 2019, 09:52:25 AM »
Hello everybody,

I recently stumbled upon a post "SON OF A BATCH! AUTOCAD CORE CONSOLE THROUGH LISP" about applying lisp scripts to many .dwg files without needing to open a full AutoCAD instance. It fit our needs perfectly.

After a bit of testing I was able to write a quick program to open all of the .dwg files I wanted to run the script in, in accoreconsole windows.

Code: [Select]
(defun modifyNameInEachDWG ( / )

;;remplacer tous les \ par les / pour le faire fonctionner
(setq chemin "C:/Users/XX/Desktop/XX-Copy")
 
(setq files (vl-directory-files chemin "*.dwg"))

  (foreach file files

    ;; don't forget the spaces at the end!
  (command "start" (strcat "accoreconsole.exe "
   "/i \"" chemin "/" file "\" "
           "/s \"M:/Ingenierie/Ingenieur/Code/renommer des calques.scr\" "
   "/l en-US"))
  );_foreach
           
   
 
)



This works great, launching the roughly 20 accoreconsole.exe windows I would expect for each .dwg.  The problem is the code I'm running

Quote
"Renommer des calques.scr"

doesn't seem to apply the layer name change. This is puzzling as it does do the save operation correctly, and the layer name change works great when used one at a time on designs.

Code: [Select]
(vl-load-com)
(vlax-for lyr (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (setq table (cons (vla-get-name lyr) table)));_vlax-for
(foreach layer table (if (vl-string-search "CT_NOTES" layer) (vl-cmdf "-Rename" "LAYER" layer (vl-string-subst "CT_DEVIS" "CT_NOTES" layer))));_foreach
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(vla-Save doc)

Does anybody have an idea why the layer name change is not applied while the save is, in the batch run version, while both work in the single run version?

Thank you in advance for any suggestions.

MasterMiner
« Last Edit: September 25, 2019, 10:06:02 AM by MasterMiner »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: LISP working individually but not through "accoreconsole.exe"
« Reply #1 on: September 25, 2019, 11:03:21 AM »
You have to stay with old school dxf coding when using accoreconsole as activex functions are not supported, so instead of:

(vlax-for lyr (vla-get-layers  ...

You have to do something like:

(while (setq layer (tblnext "layer" (null layer))) ...

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MasterMiner

  • Mosquito
  • Posts: 6
  • Mining Engineer - English/Français
Re: LISP working individually but not through "accoreconsole.exe"
« Reply #2 on: September 25, 2019, 11:17:46 AM »
MP,

Thanks for the quick reply. That sounds about right. I'll ge to work on rewriting it (more verbosely  :cry:).

Best,

MM

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: LISP working individually but not through "accoreconsole.exe"
« Reply #3 on: September 25, 2019, 11:58:21 AM »
You're welcome. On writing "verbosely" these quick & dirty functions may help:

Code: [Select]
(defun _get-layers ( / data result )
    (while (setq data (tblnext "layer" (null data)))
        (setq result (cons (cdr (assoc 2 data)) result))
    )
    (reverse result)
)

Code: [Select]
(defun _get-unique-name ( tbl candidate / suffix i result )
    (setq
        suffix ""
        i      1
    )   
    (while (tblsearch tbl (setq result (strcat candidate suffix)))
        (setq suffix (itoa (setq i (1+ i))))
    )
    result
)

Code: [Select]
(defun _tame ( text / result )
    (foreach x (mapcar 'chr (reverse (vl-string->list (strcat (setq result "") text))))
        (setq result
            (strcat
                (if (member x '("#" "@" "." "*" "?" "~" "-" "," "`" "[" "]"))
                    "`"
                    ""
                )
                x
                result
            )
        )
    )
    result
)

Code: [Select]
(defun _layers_subst ( new-str old-str / pattern data )
    (setq
        old-str (strcase old-str)
        new-str (strcase new-str)
        pattern (strcat "*" (_tame old-str) "*")
    )
    (foreach layer (_get-layers)
        (if (wcmatch (setq layer (strcase layer)) pattern)
            (entmod
                (subst
                    (cons 2
                        (_get-unique-name
                            "layer"
                            (vl-string-subst new-str old-str layer)
                        )
                    )
                    (assoc 2 (setq data (entget (tblobjname "layer" layer))))       
                    data
                )
            )
        )
    )
)

Example using the above:

(_layers_subst "CT_DEVIS" "CT_NOTES")

Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MasterMiner

  • Mosquito
  • Posts: 6
  • Mining Engineer - English/Français
Re: LISP working individually but not through "accoreconsole.exe"
« Reply #4 on: September 26, 2019, 08:33:31 AM »
MP that was very kind of you to put those all together for me. Thank you very much!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: LISP working individually but not through "accoreconsole.exe"
« Reply #5 on: September 26, 2019, 09:27:28 AM »
You're most welcome MM — hopefully they work — didn't have time to test them. :lol:

An aside — if all you're doing is opening the drawings to abuse the layers collection you could do same fast & quietly with ObjectDBX — just off to work so no time to code but it's trivial — search the swamp — examples abound — cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst