I'm using AutoCAD 2015. I've tried using this with the unnamed profile, but I still have the issue. Below is the DCL and lsp. I apologize if this isn't the formal way to post code in here. I've found help from some of lee mac's code and other Users on this forum. The idea is to eventually run a script on the list of files built off a user selection. I was in the testing phase to ensure a command would run when the user chose a script. I can't get a command to run because of the error, but I can get it to display the script name with the (princ... part. The first item in the list "0" is blank to ensure the user has chosen a script to run. Any info would be helpful. Thanks.
;;; DCL key information
;;;
;;; key = udir (edit box)
;;; key = browse (browse button)
;;; key = subdirs (list box left)
;;; key = dwgs (list box right)
;;; key = afiles (add files button)
;;; key = rfiles (remove files button)
;;; key = script (popup list)
;;; key = run (run button)
;;; key = cancel (cancel button)
;;;
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
;;; ;;;
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun c:batchtest ()
(vl-load-com)
(setq selectionlist nil)
(setq dfiles nil)
(setq scr nil)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(setq dcl_id (load_dialog "batchtest.dcl")) ; Load the DCL File
(if (not (new_dialog "batchtest" dcl_id)) ; Load the dialogue box
(exit) ; If not loaded exit
);end if
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(setq dfiles nil)
(setq sname (list "" "scriptname1" "scriptname2" "scriptname3" "scriptname4" "scriptname5" "scriptname6"))
(start_list "script" 3)
(mapcar 'add_list sname)
(end_list)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(setq userfilepath nil)
(setq userfilepath (getvar "dwgprefix"))
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(set_tile "udir" userfilepath)
(mode_tile "udir" 1)
(setq dfiles nil)
(setq dfiles (vl-sort (vl-directory-files userfilepath "*.dwg")'<))
(start_list "subdirs")
(mapcar 'add_list dfiles)
(end_list)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(action_tile "afiles"
(strcat
"(setq selectionlist (AddRemoveItems dfiles(getSelctedIndexList (get_tile \"subdirs\")) T))"
"(start_list \"dwgs\")"
"(mapcar 'add_list selectionlist)"
"(end_list)"
);strcat
);action_tile
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(action_tile "rfiles"
(strcat
"(setq selectionlist (AddRemoveItems selectionlist(getSelctedIndexList (get_tile \"dwgs\")) F))"
"(start_list \"dwgs\")"
"(mapcar 'add_list selectionlist)"
"(end_list)"
);strcat
);action_tile
(action_tile "sfiles" "(select_all_from)")
(action_tile "rafiles" "(remove_all)")
(action_tile "browse" "(setq userfilepath (getdwgs))")
(action_tile "run" "(err1)")
(action_tile "cancel" "(done_dialog 1)")
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(setq ddiag (start_dialog))
(unload_dialog dcl_id)
(princ)
); defun
(princ)
;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
;;Returns the List of selected indexes of a listbox
;; Arguments:
;; sellist - string of selected items in a listbox (eg: "0 2 3")
(defun getSelctedIndexList(sellist / count item retlist)
(setq count 1)
(while (setq item (read sellist))
(setq retlist (cons item retlist))
(while (and
(/= " " (substr sellist count 1))
(/= "" (substr sellist count 1))
)
(setq count (1+ count))
)
(setq sellist (substr sellist count))
)
(reverse retlist)
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
;;Returns the List based on the User Selection
;; Arguments:
;; source - list of all the items
;; selctn - list of selected index (use getSelctedIndexList function to get this)
;; add? - boolean , T to add and F to remove
(defun AddRemoveItems(source selctn add? / addlist removelist)
(mapcar '(lambda (x) (if(member(vl-position x source) selctn)
(setq addlist(cons x addlist))
(setq removelist(cons x removelist))
))source)
(if add? (reverse addlist) (reverse removelist))
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun remove_all ()
(setq selectionlist nil)
(set_tile "dwgs" "")
(start_list "dwgs")
(mapcar 'add_list selectionlist)
(end_list)
(princ)
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun select_all_from ()
(setq index 0)
(repeat (length dfiles)
(set_tile "subdirs" (itoa index))
(setq index (1+ index))
)
(princ)
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun getdwgs ()
(setq userfilepath (dwgdirr "Select Folder Location:" "" 512))
;(if (/= nil userfilepath)
(set_tile "udir" userfilepath)
(setq dfiles (vl-sort (vl-directory-files userfilepath "*.dwg")'<))
(start_list "subdirs")
(mapcar 'add_list dfiles)
(end_list)
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun dwgdirr ( msg dir bit / err fld pth shl slf )
(setq err
(vl-catch-all-apply
(function
(lambda ( / app hwd )
(if (setq app (vlax-get-acad-object)
shl (vla-getinterfaceobject app "shell.application")
hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
)
(setq slf (vlax-get-property fld 'self)
pth (vlax-get-property slf 'path)
pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
)
)
)
)
)
)
(if slf (vlax-release-object slf))
(if fld (vlax-release-object fld))
(if shl (vlax-release-object shl))
(if (vl-catch-all-error-p err)
(prompt (vl-catch-all-error-message err))
pth
)
;(princ pth)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
;;; end ;;;
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun err1 ()
(if (= nil dfiles)
(progn
(alert "\nNo drawings in current directory...")
);progn
(err2)
);if
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun err2 ()
(if (= nil selectionlist)
(progn
(alert "\nNo drawings to process...")
);progn
(err3)
);if
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun err3 ()
(if (and (setq scr1 "0")
(setq scr2 (get_tile "script"))
(eq scr1 scr2)
);and
(progn
(alert "\nPlease choose a script...")
);progn
(batch_processor)
);if
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun batch_processor ()
(progn
(setq scr (get_tile "script"))
(setq userscript (nth (atoi scr) sname))
(done_dialog 2)
)
(if (= ddiag 1)
(princ "\n Batch Processor Cancled...")
);if
(progn
(if (= ddiag 2)
(cond
((= scr "1") (uscript1))
((= scr "2") (uscript2))
((= scr "3") (uscript3))
((= scr "4") (uscript4))
((= scr "5") (uscript5))
((= scr "6") (uscript6))
);end cond
);if
);progn
(setq selectionlist nil)
(setq dfiles nil)
;(setq scr nil)
(princ)
);defun
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun uscript1 ()
(princ (strcat "\n You chose " userscript " from the first popup list box."))
;(command-s "._circle")
;(command "line")
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun uscript2 ()
;(command "line")
(princ (strcat "\n You chose " userscript " from the first popup list box."))
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun uscript3 ()
;(command "line")
(princ (strcat "\n You chose " userscript " from the first popup list box."))
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun uscript4 ()
;(command "line")
(princ (strcat "\n You chose " userscript " from the first popup list box."))
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun uscript5 ()
;(command "line")
(princ (strcat "\n You chose " userscript " from the first popup list box."))
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun uscript6 ()
;(command "line")
(princ (strcat "\n You chose " userscript " from the first popup list box."))
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
DCL
// BatchProcess multiple drawings
batchtest : dialog { // Drawing files
label = "Batch Processor";
: boxed_column {
label = "Drawings to Process:";
:row {
: text {
width = 32;
label = "Folder:";
} // text
} // row
: row {
: edit_box {
width = 50;
fixed_height = true;
key = "udir";
} // edit_box
: button {
label = "Browse";
key = "browse";
width = 12;
mnemonic = "0";
is_default = false;
mnemonic = "B";
} // button
: spacer { width = 1; }
} //row
: spacer { width = 1; }
: row {
: list_box {
key = "subdirs";
width = 40;
height = 10;
multiple_select = true;
value = "";
} // list_box
} // row
: spacer { width = 1; }
: row {
: button {
label = "Add Files";
key = "afiles";
width = 5;
fixed_width = false;
is_default = true;
mnemonic = "A";
alignment = centered;
} // button
: button {
label = "Select All";
key = "sfiles";
width = 5;
fixed_width = false;
is_default = false;
mnemonic = "S";
alignment = centered;
} // button
} // row
: spacer { width = 1; }
: row {
: list_box {
key = "dwgs";
width = 40;
height = 10;
multiple_select = true;
value = "";
} // list_box
} // row
: spacer { width = 1; }
: row {
: button {
label = "Remove Files";
key = "rfiles";
width = 5;
fixed_width = false;
is_default = false;
mnemonic = "F";
alignment = centered;
} // button
: button {
label = "Remove All";
key = "rafiles";
width = 5;
fixed_width = false;
is_default = false;
mnemonic = "R";
alignment = centered;
} // button
} // row
} // column
: row {
: text {
width = 32;
label = "Script Type:";
} // text
} // row
: row {
: popup_list {
key = "script";
width = 40;
fixed_width = true;
value = "";
} // popup_list
: button {
label = "Run";
key = "run";
width = 12;
fixed_width = true;
mnemonic = "0";
is_default = true;
mnemonic = "R";
} // button
: button {
label = "Cancel";
key = "Cancel";
width = 12;
fixed_width = false;
mnemonic = "C";
is_cancel = true;
} // button
} //row
: spacer { width = 2; }
:row {
: errtile {
width = 32;
}
} // row
: row {
: text {
width = 32;
label = "Future text";
} // text
} //row
} // batchtest