Charpzy Posted November 1, 2022 Posted November 1, 2022 iI'm trying to cerate a dialog box which has a list of all .dwg files in a folder (want to be able to add future notes to the folder and it auto update) and the ability to select the item then insert at a specific point I've created a .lsp file and a .dcl file a few things together but not sure how to piece it together. I'd also like to be able to show a preview of the block with a .sld in the graphics boxed column any help/ direction would be appreciated .lsp: (defun c:notes (/ p MSpace) (vlax-for file (vl-directory-files "C:\\BricsCAD Scripts\\MACROS\\DWG" "*.dwg" 1) (princ file) ) (setq p (Getpoint "\nInsertion point") MSpace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ) (vla-insertblock MSpace p (strcat "C:\\BricsCAD Scripts\\MACROS\\DWG\\" file_name)) ;note file pulled from dialog selection 1 1 1 0 ) ) .dcl: NOTES :dialog { label = "Select a Note"; : row { : boxed_column { label = "Notes"; : list_box { height = 10; width = 25; key = "note_lt"; multiple_select = true ; } } : boxed_column { label = "Preview"; : image { key = "imageP"; color = graphics_background; width = 35; height = 15; } } } spacer; ok_only; } Quote
mhupp Posted November 1, 2022 Posted November 1, 2022 This should do the trick. Edit the headers to what you want. Need to edit the dcl to have an all button. Example (setq lst (vl-directory-files "C:\\BricsCAD Scripts\\MACROS\\DWG" "*.dwg" 1)) (if (setq Blklst (AT:ListSelect (strcat (itoa (length lst)) " Block(s) in Folder") "Pick Block(s) to Insert Into Drawing" 30 60 "true" lst)) ;; List Select Dialog (Temp DCL list box selection, based on provided list) ;; title - list box title ;; label - label for list box ;; height - height of box ;; width - width of box ;; multi - selection method ["true": multiple, "false": single] ;; lst - list of strings to place in list box ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) (defun AT:ListSelect (title label height width multi lst / fn fo d f) (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w")) (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;") (strcat ": list_box { label = \"" label "\";" "key = \"lst\";") (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";") (strcat "width = " (vl-princ-to-string width) ";") (strcat "multiple_select = " multi "; } spacer; ok_cancel; }") ) (write-line x fo) ) (close fo) (new_dialog "list_select" (setq d (load_dialog fn))) (start_list "lst") (mapcar (function add_list) lst) (end_list) (setq item (set_tile "lst" "0")) (action_tile "lst" "(setq item $value)") (setq f (start_dialog)) (unload_dialog d) (vl-file-delete fn) (if (= f 1) ((lambda (s / i s l) (while (setq i (vl-string-search " " s)) (setq l (cons (nth (atoi (substr s 1 i)) lst) l)) (setq s (substr s (+ 2 i))) ) (reverse (cons (nth (atoi s) lst) l)) ) item ) ) ) Quote
Charpzy Posted November 1, 2022 Author Posted November 1, 2022 (edited) I forgot to update on where i got to, my current status on code is: (defun c:notess (/ p MSpace) (defun NInster(ent) (print ent) (setq p (Getpoint "\nInsertion point") MSpace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ) (vla-insertblock MSpace p (strcat "C:\\BricsCAD Scripts\\MACROS\\DWG\\NOTES\\" ent) ;note file pulled from dialog selection 1 1 1 0 ) ) (setq folderList (vl-directory-files "C:\\BricsCAD Scripts\\MACROS\\DWG\\NOTES" "*.dwg" 1)) (setq dcl_id (load_dialog "C:\\BricsCAD Scripts\\MACROS\\DIALOGS\\NOTES.dcl")) (if (not (new_dialog "NOTES" dcl_id)) (exit)) (start_list "folderlist") (mapcar 'add_list folderList) (end_list) (action_tile "folderlist" "(NInster (nth (atof $value) folderList))(done_dialog)") (start_dialog) (princ) ) This opens the dialog box with the list of items in the folder, but keep getting this error: "; error : Automation Error E_INVALIDARG; [IAcadModelSpace] invalid argument for [INSERTBLOCK] method. The parameter is incorrect." it prints out the correct file name so I know its doing something right, i just seem to having issues choosing a point to place it into Edited November 1, 2022 by Charpzy Quote
mhupp Posted November 1, 2022 Posted November 1, 2022 Add right before the insert (princ (strcat "C:\\BricsCAD Scripts\\MACROS\\DWG\\NOTES\\" ent)) And see if the path is right Quote
Charpzy Posted November 1, 2022 Author Posted November 1, 2022 1 hour ago, mhupp said: Add right before the insert (princ (strcat "C:\\BricsCAD Scripts\\MACROS\\DWG\\NOTES\\" ent)) And see if the path is right just tried that, it returns the following path "C:\BricsCAD Scripts\MACROS\DWG\NOTES\ADDITIONAL TM.dwg" Quote
mhupp Posted November 1, 2022 Posted November 1, 2022 See if this works. (defun c:notess (/ Path FolderList dcl_id ent pt MSpace) (setq Path "C:\\BricsCAD Scripts\\MACROS\\DWG\\NOTES\\") (setq FolderList (vl-directory-files Path "*.dwg" 1)) (setq dcl_id (load_dialog "C:\\BricsCAD Scripts\\MACROS\\DIALOGS\\NOTES.dcl")) (if (not (new_dialog "NOTES" dcl_id)) (exit) ) (start_list "folderlist") (mapcar 'add_list folderList) (end_list) (action_tile "lst" "(setq item $value)") (action_tile "folderlist" "(setq ent (nth (atof $value) folderList))(done_dialog)") (start_dialog) (setq pt (Getpoint "\nInsertion point") MSpace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ) (vla-insertblock MSpace pt (strcat Path ent) 1 1 1 0) (princ) ) Quote
Charpzy Posted November 1, 2022 Author Posted November 1, 2022 worked perfect! only thing I've just noticed, where I used: (mapcar 'add_list folderList) It shows the items with the extensions for examples 'NOTE.dwg' how could I retrieve the list without the extension previously I was using vl-filename-base along with a foreach loop but not too sure how to implement it into this with the mapcar func 54 minutes ago, mhupp said: See if this works. (defun c:notess (/ Path FolderList dcl_id ent pt MSpace) (setq Path "C:\\BricsCAD Scripts\\MACROS\\DWG\\NOTES\\") (setq FolderList (vl-directory-files Path "*.dwg" 1)) (setq dcl_id (load_dialog "C:\\BricsCAD Scripts\\MACROS\\DIALOGS\\NOTES.dcl")) (if (not (new_dialog "NOTES" dcl_id)) (exit) ) (start_list "folderlist") (mapcar 'add_list folderList) (end_list) (action_tile "lst" "(setq item $value)") (action_tile "folderlist" "(setq ent (nth (atof $value) folderList))(done_dialog)") (start_dialog) (setq pt (Getpoint "\nInsertion point") MSpace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) ) (vla-insertblock MSpace pt (strcat Path ent) 1 1 1 0) (princ) ) Quote
BIGAL Posted November 2, 2022 Posted November 2, 2022 (edited) I have like 500 dwg's as blocks so 2 answers. Tool palettes I dont use but lots do. 2nd is menu options grouping my blocks yes have made slides, can be scripted to make 100+ in one go. It has the advantage of Next is called automatically when list exceeds 20 items. Did do a step further make slides and write menu code at same time. Edited November 2, 2022 by BIGAL Quote
Charpzy Posted November 2, 2022 Author Posted November 2, 2022 Im just having an issues grabbing the file name without the extension to list into my dialog, manage to get everything fine just looks a little messy when displaying the .dwg at the end Quote
BIGAL Posted November 3, 2022 Posted November 3, 2022 Use substr remove the last 4 characters will strip the say .dwg (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) Quote
ronjonp Posted November 3, 2022 Posted November 3, 2022 This too: (vl-filename-base (getvar 'dwgname)) Quote
asos2000 Posted November 3, 2022 Posted November 3, 2022 On 11/2/2022 at 2:45 AM, BIGAL said: ... Did do a step further make slides and write menu code at same time. How is this? Is there a sample? Quote
Charpzy Posted November 3, 2022 Author Posted November 3, 2022 I.ve tried using them but I'm grabbing the files for the list directly from the folder (setq FolderList (vl-directory-files Path "*.dwg" 1)) (mapcar 'add_list folderList) how would I implement either of these into this without having to break the list down to make a new list if possible? 50 minutes ago, ronjonp said: This too: (vl-filename-base (getvar 'dwgname)) 9 hours ago, BIGAL said: Use substr remove the last 4 characters will strip the say .dwg (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4)) Quote
Charpzy Posted November 3, 2022 Author Posted November 3, 2022 I've tried looking how to automate making the slides/ make them all in one go because I have a load of items which need slides making to display On 02/11/2022 at 00:45, BIGAL said: I have like 500 dwg's as blocks so 2 answers. Tool palettes I dont use but lots do. 2nd is menu options grouping my blocks yes have made slides, can be scripted to make 100+ in one go. It has the advantage of Next is called automatically when list exceeds 20 items. Did do a step further make slides and write menu code at same time. Quote
ronjonp Posted November 3, 2022 Posted November 3, 2022 Try this: (mapcar 'add_list (mapcar 'vl-filename-base folderList)) Quote
Charpzy Posted November 3, 2022 Author Posted November 3, 2022 thank you, this worked 1 hour ago, ronjonp said: Try this: (mapcar 'add_list (mapcar 'vl-filename-base folderList)) Quote
BIGAL Posted November 3, 2022 Posted November 3, 2022 Re making like 100 slides use a script open dwg, mslide, sldname, close, do next dwg. You have started another post would be better if you continue here only. Ask Admin to join. Quote
BIGAL Posted November 3, 2022 Posted November 3, 2022 (edited) Asos2000 I just looked at what the mnu code was for a *Icon section, so used the dwg/block names to write the code to a dummy file then cut and pasted into the master mnu. The slides were made using a script based on the same file names. ***icon **12D [12D] [dr_pav_bend]^c^cINSERT dr_pav_bend drag \1;;DRAG [dr_pav_pipe_con]^c^cINSERT dr_pav_pipe_con DRAG \1;;DRAG [dr_pav_slot]^c^cINSERT dr_pav_slot DRAG \1;;DRAG [dr_pav_pit_offset]^c^cINSERT dr_pav_pit_offset DRAG \1;;DRAG I am trying to find the code, for the last effort just started with a list of block names in a txt file and used that to make a script and make the mnu. The blocks were grouped into common theme so ran like 6 times with different files. Edited November 3, 2022 by BIGAL Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.