pkenewell Posted Wednesday at 02:29 PM Posted Wednesday at 02:29 PM (edited) On 3/26/2025 at 10:42 AM, jim78b said: Command: MLB Select object in paper space,select start point of MLeader,exit with esc'._MSPACE Command: ._PSPACE Command: Cannot invoke (command) from *error* without prior call to (*push-error-using-command*). Converting (command) calls to (command-s) is recommended. Expand @jim78b The Error you got tells you what to do; change the (command) statement in the error handler to (command-s). I.E. (defun trap1 (errmsg) (command-s "._PSPACE") ;<--- HERE (SETVAR "OSMODE" osnp) (princ) ) Edited Wednesday at 02:30 PM by pkenewell Quote
jim78b Posted Wednesday at 02:40 PM Author Posted Wednesday at 02:40 PM SO what code should i use? however ALWAYS the code reset my osnap!! is possible? Quote
jim78b Posted Wednesday at 02:45 PM Author Posted Wednesday at 02:45 PM THE PROBLEM NOW IS that my osnaps every time reset! Quote
aridzv Posted Wednesday at 04:03 PM Posted Wednesday at 04:03 PM (edited) use this (defun c:MLeaderWBlname( / *error* trap1 osnp tm tagname ptms ss ensel obj obj1 nam) (setq temperr *error*);store *error* (setq *error* trap1);re-assign *error* (setq osnp (getvar "OSMODE")) (setvar "OSMODE" 0) (setq tm (getvar "TILEMODE")) (princ "Select object in paper space,select start point of MLeader,exit with esc'") (while (getpoint) ;;get point in paper space on the target object (if (= tm 0);if in paper space (progn (command "._MSPACE") (setq ptms (cadr (grread t)));;get the point where the cursor is on the target object in model space (setq ss (ssget ptms));;selction set of the object crossing the ptms point (setq obj(ssname ss 0)) (command "._PSPACE") );progn (progn ;in model space (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy (setq obj (car ensel)) ;set the block object to varaible );progn );if (setq obj1 (vlax-ename->vla-object obj)) (setq nam (vlax-get-property obj1 (if (vlax-property-available-p obj1 'effectivename) 'effectivename 'name ) ) ) (command "_mleader" "H" pause pause nam) );end while (command "._PSPACE") (SETVAR "OSMODE" osnp) (princ) ) (defun trap1 (errmsg) (command-s "._PSPACE") ;<--- HERE (SETVAR "OSMODE" osnp) (princ) ) other way (the one I use) is this version: (defun c:MLeaderWBlname( / *error* osnp tm tagname ptms ss ensel obj obj1 nam) (defun *error* ( msg ) (command "._PSPACE") (setvar "OSMODE" osnp) (princ) ) (setq osnp (getvar "OSMODE")) (setvar "OSMODE" 0) (setq tm (getvar "TILEMODE")) (princ "Select object in paper space,select start point of MLeader,exit with esc'") (while (getpoint) ;;get point in paper space on the target object (if (= tm 0);if in paper space (progn (command "._MSPACE") (setq ptms (cadr (grread t)));;get the point where the cursor is on the target object in model space (setq ss (ssget ptms));;selction set of the object crossing the ptms point (setq obj(ssname ss 0)) (command "._PSPACE") );progn (progn ;in model space (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy (setq obj (car ensel)) ;set the block object to varaible );progn );if (setq obj1 (vlax-ename->vla-object obj)) (setq nam (vlax-get-property obj1 (if (vlax-property-available-p obj1 'effectivename) 'effectivename 'name ) ) ) (command "_mleader" "H" pause pause nam) );end while (command "._PSPACE") (SETVAR "OSMODE" osnp) (princ) ) damm lisp error traping... Edited Wednesday at 04:09 PM by aridzv Quote
jim78b Posted Wednesday at 04:05 PM Author Posted Wednesday at 04:05 PM SORRY THIS RESET MY OSNAPS!! AFTER I END TO USE THE CODE! Quote
aridzv Posted Wednesday at 04:15 PM Posted Wednesday at 04:15 PM (edited) try this code. it is with out error trap - it looks for errors by checking the selection set and the object properties: (defun c:MLeaderWBlname( / osnp tm tagname ptms ss ensel obj obj1 ifobj nam) (setq osnp (getvar "OSMODE")) (setvar "OSMODE" 0) (setq tm (getvar "TILEMODE")) (setq ifobj 0) (princ "Select object in paper space,select start point of MLeader,exit with esc'") (while (getpoint) ;;get point in paper space on the target object (if (= tm 0);if in paper space (progn (command "._MSPACE") (setq ptms (cadr (grread t)));;get the point where the cursor is on the target object in model space (if (=(setq ss (ssget ptms)) nil) ;;selction set of the object crossing the ptms point (progn (alert "There is no selection set please run again") (setq ifobj 0) (command "._PSPACE") );progn (progn (command "._PSPACE") (setq obj(ssname ss 0)) (setq ifobj 1) );progn );if );progn (progn ;in model space (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy (setq obj (car ensel)) ;set the block object to varaible (setq ifobj 1) );progn );if (if (= ifobj 1) ;; check if there is a selection set (progn (if (= (cdr (assoc 0 (entget obj))) "INSERT");; check if selected object is block (progn (setq obj1 (vlax-ename->vla-object obj)) (setq nam (vlax-get-property obj1 (if (vlax-property-available-p obj1 'effectivename) 'effectivename 'name ) ) ) (command "_mleader" "H" pause pause nam) (setq ifobj 0) );progn (progn (alert "Not a Block") );progn );if );progn (alert "Not a Block") );end if );end while (command "._PSPACE") (SETVAR "OSMODE" osnp) (princ) ) Edited Wednesday at 04:20 PM by aridzv Quote
aridzv Posted Wednesday at 04:23 PM Posted Wednesday at 04:23 PM On 3/26/2025 at 4:19 PM, jim78b said: Expand you select an empty space 1 Quote
jim78b Posted Wednesday at 04:23 PM Author Posted Wednesday at 04:23 PM now work after restart autocad but sometimes the osnap reset all my settings Quote
aridzv Posted Wednesday at 04:33 PM Posted Wednesday at 04:33 PM see attached code and video. EXIT WITH ENTER TO RESTORE OSNAP. (defun c:MLeaderWBlname( / osnp tm tagname ptms ss ensel obj obj1 ifobj nam) (setq osnp (getvar "OSMODE")) (setvar "OSMODE" 0) (setq tm (getvar "TILEMODE")) (setq ifobj 0) (princ "Select object in paper space,select start point of MLeader,exit with ENTER") (while (getpoint) ;;get point in paper space on the target object (if (= tm 0);if in paper space (progn (command "._MSPACE") (setq ptms (cadr (grread t)));;get the point where the cursor is on the target object in model space (if (=(setq ss (ssget ptms)) nil) ;;selction set of the object crossing the ptms point (progn (alert "There is no selection set please run again") (setq ifobj 0) (command "._PSPACE") );progn (progn (command "._PSPACE") (setq obj(ssname ss 0)) (setq ifobj 1) );progn );if );progn (progn ;in model space (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy (setq obj (car ensel)) ;set the block object to varaible (setq ifobj 1) );progn );if (if (= ifobj 1) ;; check if there is a selection set (progn (if (= (cdr (assoc 0 (entget obj))) "INSERT");; check if selected object is block (progn (setq obj1 (vlax-ename->vla-object obj)) (setq nam (vlax-get-property obj1 (if (vlax-property-available-p obj1 'effectivename) 'effectivename 'name ) ) ) (command "_mleader" "H" pause pause nam) (setq ifobj 0) );progn (alert "Not a Block") );if );progn (alert "Not a Block") );end if );end while (command "._PSPACE") (SETVAR "OSMODE" osnp) (princ) ) Screen Recording 2025-03-26 183108.mp4 Quote
aridzv Posted Wednesday at 04:34 PM Posted Wednesday at 04:34 PM On 3/26/2025 at 4:23 PM, jim78b said: now work after restart autocad but sometimes the osnap reset all my settings Expand yap. with the code above you must use ENTER to exit the lisp and get OSNAP restored back... Quote
jim78b Posted Wednesday at 04:34 PM Author Posted Wednesday at 04:34 PM Ok thanks very much. But it happened i think during command running. If i turn off the osnap with f3. Quote
aridzv Posted Wednesday at 04:36 PM Posted Wednesday at 04:36 PM (edited) On 3/26/2025 at 4:34 PM, jim78b said: Ok thanks very much. But it happened i think during command running. If i turn off the osnap with f3. Expand try the last code and finish the command with ENTER, not escape or right click. only ENTER. Edited Wednesday at 04:55 PM by aridzv 1 Quote
aridzv Posted Wednesday at 04:40 PM Posted Wednesday at 04:40 PM @jim78b for some reason when I finish with right click it dose restore the OSNAP. try restart autocad, open the drawing and load the lisp again. Quote
aridzv Posted Wednesday at 04:44 PM Posted Wednesday at 04:44 PM (edited) On 3/26/2025 at 4:34 PM, jim78b said: Ok thanks very much. But it happened i think during command running. If i turn off the osnap with f3. Expand Of course it happens in the lisp, that's the idea. see at the start of the code (setq osnp (getvar "OSMODE")) (setvar "OSMODE" 0) and at the end of the code restore the OSNAP mode: (command "._PSPACE") (SETVAR "OSMODE" osnp) (princ) Try selecting the block with the cursor trying to snap at every entity around... Edited Wednesday at 04:53 PM by aridzv 1 Quote
jim78b Posted Wednesday at 05:07 PM Author Posted Wednesday at 05:07 PM Ok for now i appreciate your help. I will work better tomorrow . I think is a good job. Quote
BIGAL Posted Thursday at 10:30 PM Posted Thursday at 10:30 PM 4 suggestions, (getpoint "\nSelect object in paper space,select start point of MLeader,exit with ENTER") (setq ifobj 0) (setvar 'osmode osnp) (command "._PSPACE") Create a Error check so if Esc is pressed the osnap is reset. I use a simple defun to reset my osnaps if lost. Just set your osnaps to what you like to use and then type osmode a number will appear use that number for the osmode, i just made the defun name a number, it is autoloaded on start up. (defun c:47 ( / )(setvar 'osmode 47)) Quote
aridzv Posted Friday at 11:42 AM Posted Friday at 11:42 AM (edited) here is the code with proper error handling and @BIGAL revised getpoint: (defun c:MLeaderWBlname( / trap1 olderr osnp tm tagname ptms ss ensel obj obj1 ifobj nam) (defun trap1 ( msg );define error trap (setq *error* olderr);restore *error* symbol (SETVAR "OSMODE" osnp);reset OSMODE (princ) ) (setq olderr *error*); assign current function defintion held by the *error* symbol to a local variable - olderr (setq *error* trap1); pointing the *error* symbol to new function definition - trap1 (setq osnp (getvar "OSMODE")) (setvar "OSMODE" 0) (setq tm (getvar "TILEMODE")) (setq ifobj 0) (while (getpoint "\nSelect object in paper space,select start point of MLeader,exit with ENTER/ESC/Right Click") ;;get point in paper space on the target object (if (= tm 0);if in paper space (progn (command "._MSPACE") (setq ptms (cadr (grread t)));;get the point where the cursor is on the target object in model space (if (=(setq ss (ssget ptms)) nil) ;;selction set of the object crossing the ptms point (progn (alert "There is no selection set please run again") (setq ifobj 0) (command "._PSPACE") );progn (progn (command "._PSPACE") (setq obj(ssname ss 0)) (setq ifobj 1) );progn );if );progn (progn ;in model space (setq ensel (entsel "\nSelect Block: ")) ;select the block object to copy (setq obj (car ensel)) ;set the block object to varaible (setq ifobj 1) );progn );if (if (= ifobj 1) ;; check if there is a selection set (progn (if (= (cdr (assoc 0 (entget obj))) "INSERT");; check if selected object is block (progn (setq obj1 (vlax-ename->vla-object obj)) (setq nam (vlax-get-property obj1 (if (vlax-property-available-p obj1 'effectivename) 'effectivename 'name ) ) ) (command "_mleader" "H" pause pause nam) (setq ifobj 0) );progn (alert "Not a Block") );if );progn (alert "Not a Block") );end if );end while (setq *error* olderr); restore *error* symbol (command "._PSPACE") (SETVAR "OSMODE" osnp) (princ) ) Edited Friday at 11:44 AM by aridzv 1 Quote
jim78b Posted 20 hours ago Author Posted 20 hours ago so is this lisp correct? yhanks very much 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.