jim78b Posted 20 hours ago Posted 20 hours ago i have this code, but give me syntax error. i put all the files in the same dir. ;;----------------------------------------------------------------------;; ;; SNB_Select.lsp ;; ;; ;; ;; Interactively select and highlight nested blocks from a dialog. ;; ;; ;; ;; Depends on the updated `nestedblocks.dcl` file. ;; ;; ;; ;; To Run: APPLOAD -> Load File -> Type "SNB_SELECT" in the command. ;; ;;----------------------------------------------------------------------;; ;; This global list will store the clean names for selection (defun-q *block_name_list*) ;; Recursive function to populate the dialog list and our background list (defun FindAndListNestedBlocks (blkname level visited) (if (not (member blkname visited)) (if (tblsearch "BLOCK" blkname) (progn (setq visited (cons blkname visited)) ; Add current block to visited list (setq ent (tblobjname "BLOCK" blkname)) (setq ent (entnext ent)) (while ent (setq edata (entget ent)) (if (= "INSERT" (cdr (assoc 0 edata))) (progn (setq nested_blkname (cdr (assoc 2 edata))) (setq indent (make_string (* level 2) 32)) ;; Add the formatted name to the visible list box (add_list (strcat indent "|-- " nested_blkname)) ;; Add the clean name to our background list (setq *block_name_list* (append *block_name_list* (list nested_blkname))) ;; Recurse for the next level (FindAndListNestedBlocks nested_blkname (+ level 1) visited) ) ) (setq ent (entnext ent)) ) ) ) ) ) ;; Main command function (defun c:SNB_SELECT (/ sel edata blkname dcl_id selected_index ss) (princ "\n--- Interactive Nested Block Viewer ---") (setq sel (entsel "\nSelect a parent block to inspect: ")) (if sel (progn (setq dcl_id (load_dialog "nestedblocks.dcl")) (if (not (new_dialog "NestedBlockViewer" dcl_id)) (exit) ) (setq edata (entget (car sel))) (setq blkname (cdr (assoc 2 edata))) ;; Initialize the background list with the top-level block (setq *block_name_list* (list blkname)) ;; Populate the visible list in the dialog (start_list "block_tree") (add_list blkname) (FindAndListNestedBlocks blkname 1 nil) (end_list) ;; --- Define Actions for Dialog Buttons --- ;; Action for the "Highlight Selection" button (action_tile "highlight" "(progn (setq selected_index (atoi (get_tile \"block_tree\"))) (setq selected_block (nth selected_index *block_name_list*)) (princ (strcat \"\nHighlighting all instances of: \" selected_block)) (sssetfirst nil nil) ; Clear any previous selection grips (setq ss (ssget \"_X\" (list (cons 0 \"INSERT\") (cons 2 selected_block) (cons 410 (getvar 'ctab))))) (if ss (sssetfirst nil ss)) ; Highlight all found instances in current space )" ) ;; Action for the OK button (and double-clicking a list item) (action_tile "accept" "(done_dialog)") ;; Display the dialog and wait for user action (start_dialog) (sssetfirst nil nil) ; Clear selection grips on exit (unload_dialog dcl_id) ) (princ "\nNo object selected.") ) (princ) ) (princ "\nLISP loaded. Type SNB_SELECT to run.") (princ) here dcl file // nestedblocks.dcl // Defines the dialog box for the Interactive Nested Block Viewer NestedBlockViewer : dialog { label = "Interactive Nested Block Viewer"; // The window title // The list of blocks : list_box { key = "block_tree"; // An identifier for this list width = 60; height = 20; allow_accept = true; } // A row to hold our buttons : row { // New button to trigger the highlighting action : button { key = "highlight"; label = "Highlight Selection"; width = 20; fixed_width = true; } // Spacer to push the OK button to the right : spacer { width = 1; } // Standard OK button to close the dialog : ok_button { is_default = true; } } } Quote
jim78b Posted 16 hours ago Author Posted 16 hours ago 2 hours ago, SLW210 said: Where did you get the LISP? sorry why? Quote
pkenewell Posted 13 hours ago Posted 13 hours ago 3 hours ago, jim78b said: sorry why? Because no credit was given to the Author in the code or your post. Quote
jim78b Posted 12 hours ago Author Posted 12 hours ago 1 hour ago, pkenewell said: Because no credit was given to the Author in the code or your post. Ai Quote
pkenewell Posted 11 hours ago Posted 11 hours ago 19 minutes ago, jim78b said: Ai @jim78b Then you should've just said that. Anyway - I think the problem is that you can't have a multi-line string like in your action tile statement, when there are parenthesis and other embedded code. Do this instead: ;; Action for the "Highlight Selection" button (action_tile "highlight" (strcat "(progn" " (setq selected_index (atoi (get_tile \"block_tree\")))" " (setq selected_block (nth selected_index *block_name_list*))" " (princ (strcat \"\nHighlighting all instances of: \" selected_block))" " (sssetfirst nil nil) ; Clear any previous selection grips" " (setq ss (ssget \"_X\" (list (cons 0 \"INSERT\") (cons 2 selected_block) (cons 410 (getvar 'ctab)))))" " (if ss (sssetfirst nil ss)) ; Highlight all found instances in current space" ")" ) ) 1 Quote
jim78b Posted 8 hours ago Author Posted 8 hours ago 3 hours ago, pkenewell said: @jim78b Then you should've just said that. Anyway - I think the problem is that you can't have a multi-line string like in your action tile statement, when there are parenthesis and other embedded code. Do this instead: ;; Action for the "Highlight Selection" button (action_tile "highlight" (strcat "(progn" " (setq selected_index (atoi (get_tile \"block_tree\")))" " (setq selected_block (nth selected_index *block_name_list*))" " (princ (strcat \"\nHighlighting all instances of: \" selected_block))" " (sssetfirst nil nil) ; Clear any previous selection grips" " (setq ss (ssget \"_X\" (list (cons 0 \"INSERT\") (cons 2 selected_block) (cons 410 (getvar 'ctab)))))" " (if ss (sssetfirst nil ss)) ; Highlight all found instances in current space" ")" ) ) So i Will Copy your code in my lisp ? Quote
jim78b Posted 8 hours ago Author Posted 8 hours ago 3 hours ago, pkenewell said: @jim78b Then you should've just said that. Anyway - I think the problem is that you can't have a multi-line string like in your action tile statement, when there are parenthesis and other embedded code. Do this instead: ;; Action for the "Highlight Selection" button (action_tile "highlight" (strcat "(progn" " (setq selected_index (atoi (get_tile \"block_tree\")))" " (setq selected_block (nth selected_index *block_name_list*))" " (princ (strcat \"\nHighlighting all instances of: \" selected_block))" " (sssetfirst nil nil) ; Clear any previous selection grips" " (setq ss (ssget \"_X\" (list (cons 0 \"INSERT\") (cons 2 selected_block) (cons 410 (getvar 'ctab)))))" " (if ss (sssetfirst nil ss)) ; Highlight all found instances in current space" ")" ) ) But the dcl and lisp files must be in the same directory ? Quote
pkenewell Posted 8 hours ago Posted 8 hours ago 11 minutes ago, jim78b said: So i Will Copy your code in my lisp ? Yes - replace the following section of your code with my replacement. REPLACE THIS (action_tile "highlight" "(progn (setq selected_index (atoi (get_tile \"block_tree\"))) (setq selected_block (nth selected_index *block_name_list*)) (princ (strcat \"\nHighlighting all instances of: \" selected_block)) (sssetfirst nil nil) ; Clear any previous selection grips (setq ss (ssget \"_X\" (list (cons 0 \"INSERT\") (cons 2 selected_block) (cons 410 (getvar 'ctab))))) (if ss (sssetfirst nil ss)) ; Highlight all found instances in current space )" ) WITH THIS (action_tile "highlight" (strcat "(progn" " (setq selected_index (atoi (get_tile \"block_tree\")))" " (setq selected_block (nth selected_index *block_name_list*))" " (princ (strcat \"\nHighlighting all instances of: \" selected_block))" " (sssetfirst nil nil) ; Clear any previous selection grips" " (setq ss (ssget \"_X\" (list (cons 0 \"INSERT\") (cons 2 selected_block) (cons 410 (getvar 'ctab)))))" " (if ss (sssetfirst nil ss)) ; Highlight all found instances in current space" ")" ) ) 12 minutes ago, jim78b said: But the dcl and lisp files must be in the same directory ? The DCL and the LISP file must both be in an AutoCAD support path. 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.