Greenland Posted Monday at 08:21 AM Posted Monday at 08:21 AM I wrote a program to create a viewport in the layout by selecting a rectangle in the model, however, during the program's execution, an error occurred: bad argument type: numberp: nil. Please help me find a solution to this problem. Thank you everyone. Below is the code. (defun C:frm (/ DCL_ID) (if (tblsearch "layer" "frame_print") (setvar "clayer" "frame_print") (command "_.Layer" "_Make" "frame_print" "_Color" "220" "" "P" "N" "frame_print" "" "LType" "Continuous" "" "")) (prompt "\nEnter Scale <1> :")(princ) (setq scale_1 (getreal)) (if (= nil scale_1) (setq scale_1 1)) (setq m2 (entget (car (entsel)))) (setq m1 (cdr (assoc 0 m2))) (if (= "LWPOLYLINE" m1) (setq d_s (list (assoc 0 m2) (assoc 8 m2)))) (if (/= "LWPOLYLINE" m1) prompt "\nSelectFrame!!!") (setq s1 (ssget d_s)) (progn (sssetfirst nil nil) s1) (setq i 0) (setq lst1 '()) (setq lst2 '()) (repeat (sslength s1) (setq e (ssname s1 i) obj (vlax-ename->vla-object e) i (1+ i)) (if obj (progn (vla-getboundingbox obj 'point1 'point2) (setq point1 (vlax-safearray->list point1)) (setq point2 (vlax-safearray->list point2)))) (setq cp1 (list (car point1) (cadr point1))) (setq cp2 (list (car point2) (cadr point2))) (setq ks1 (list (car cp1) (cadr cp1) (car cp2) (cadr cp2))) (setq lst1 (cons ks1 ls1)) ) (setq me1 '(0 0)) (setq me2 '(0 0)) (command "LAYOUT" "s" (entlast)) (repeat (sslength s1) (setq lt1 '(0 0)) (setq lt2 '(0 0)) (setq lt1 (list (car (car lst1)) (cadr (car lst1)))) (setq lt2 (list (caddr (car lst1)) (cadddr (car lst1)))) (setq mk1 (list (+ (*(- (car lt1) (car me1)) scale_1) (car me1)) (+ (*(- (cadr lt1) (cadr me1)) scale_1) (cadr me1)))) (setq mk2 (list (+ (*(- (car lt2) (car me2)) scale_1) (car me2)) (+ (*(- (cadr lt2) (cadr me2)) scale_1) (cadr me2)))) (Command "mview" mk1 mk2) (Command "zoom" "w" mk1 mk2) (setq s (cdr (sssetfirst nil (ssget "L")))) (vla-put-mspace (vla-get-ActiveDocument (vlax-get-acad-object)) :vlax-true) (Command "zoom" "w" lt1 lt2 "pspace") (setq vp (vlax-ename->vla-object (entlast))) (vla-put-CustomScale vp scale_1) (vla-put-DisplayLocked vp :vlax-true) (setq lst1 (cdr lst1)) (command "REGENALL") ) ) Quote
GLAVCVS Posted Monday at 01:03 PM Posted Monday at 01:03 PM On 3/31/2025 at 8:21 AM, Greenland said: I wrote a program to create a viewport in the layout by selecting a rectangle in the model, however, during the program's execution, an error occurred: bad argument type: numberp: nil. Please help me find a solution to this problem. Thank you everyone. Below is the code. (defun C:frm (/ DCL_ID) (if (tblsearch "layer" "frame_print") (setvar "clayer" "frame_print") (command "_.Layer" "_Make" "frame_print" "_Color" "220" "" "P" "N" "frame_print" "" "LType" "Continuous" "" "")) (prompt "\nEnter Scale <1> :")(princ) (setq scale_1 (getreal)) (if (= nil scale_1) (setq scale_1 1)) (setq m2 (entget (car (entsel)))) (setq m1 (cdr (assoc 0 m2))) (if (= "LWPOLYLINE" m1) (setq d_s (list (assoc 0 m2) (assoc 8 m2)))) (if (/= "LWPOLYLINE" m1) prompt "\nSelectFrame!!!") (setq s1 (ssget d_s)) (progn (sssetfirst nil nil) s1) (setq i 0) (setq lst1 '()) (setq lst2 '()) (repeat (sslength s1) (setq e (ssname s1 i) obj (vlax-ename->vla-object e) i (1+ i)) (if obj (progn (vla-getboundingbox obj 'point1 'point2) (setq point1 (vlax-safearray->list point1)) (setq point2 (vlax-safearray->list point2)))) (setq cp1 (list (car point1) (cadr point1))) (setq cp2 (list (car point2) (cadr point2))) (setq ks1 (list (car cp1) (cadr cp1) (car cp2) (cadr cp2))) (setq lst1 (cons ks1 ls1)) ) (setq me1 '(0 0)) (setq me2 '(0 0)) (command "LAYOUT" "s" (entlast)) (repeat (sslength s1) (setq lt1 '(0 0)) (setq lt2 '(0 0)) (setq lt1 (list (car (car lst1)) (cadr (car lst1)))) (setq lt2 (list (caddr (car lst1)) (cadddr (car lst1)))) (setq mk1 (list (+ (*(- (car lt1) (car me1)) scale_1) (car me1)) (+ (*(- (cadr lt1) (cadr me1)) scale_1) (cadr me1)))) (setq mk2 (list (+ (*(- (car lt2) (car me2)) scale_1) (car me2)) (+ (*(- (cadr lt2) (cadr me2)) scale_1) (cadr me2)))) (Command "mview" mk1 mk2) (Command "zoom" "w" mk1 mk2) (setq s (cdr (sssetfirst nil (ssget "L")))) (vla-put-mspace (vla-get-ActiveDocument (vlax-get-acad-object)) :vlax-true) (Command "zoom" "w" lt1 lt2 "pspace") (setq vp (vlax-ename->vla-object (entlast))) (vla-put-CustomScale vp scale_1) (vla-put-DisplayLocked vp :vlax-true) (setq lst1 (cdr lst1)) (command "REGENALL") ) ) Expand Hi @Greenland Maybe you should just change the 'ls1' shown in the image to 'lst1' 1 Quote
GLAVCVS Posted Monday at 01:10 PM Posted Monday at 01:10 PM In any case, there are some syntax errors you should check: some missing parentheses (before 'prompt', for example) Quote
Greenland Posted Monday at 01:14 PM Author Posted Monday at 01:14 PM On 3/31/2025 at 1:03 PM, GLAVCVS said: Hi @Greenland Maybe you should just change the 'ls1' shown in the image to 'lst1' Expand Tks GLAVCVS, It well done! Quote
GLAVCVS Posted Monday at 01:17 PM Posted Monday at 01:17 PM Although I think that when you solve all of that and successfully run your code, the result won't be what you expect. Or maybe it will be? Quote
CyberAngel Posted Monday at 03:31 PM Posted Monday at 03:31 PM Welcome to the forum! I know it doesn't seem important when you start programming, but indenting will help you find errors. One missing parenthesis can throw off your whole function. 1 Quote
Steven P Posted Monday at 03:41 PM Posted Monday at 03:41 PM I'd also add in what each closing bracket is for and to have only 1 opening bracket / closing bracket on a line... unless that line is the complete line of course Example from Cyberangels suggestion (defun C:frm (/ DCL_ID) (if (tblsearch "layer" "frame_print") (setvar "clayer" "frame_print") (command "_.Layer" "_Make" "frame_print" "_Color" "220" "" "P" "N" "frame_print" "" "LType" "Continuous" "" "") ) ; end if (prompt "\nEnter Scale <1> :")(princ) (setq scale_1 (getreal)) (if (= nil scale_1) (setq scale_1 1)) (setq m2 (entget (car (entsel)))) (setq m1 (cdr (assoc 0 m2))) (if (= "LWPOLYLINE" m1) (setq d_s (list (assoc 0 m2) (assoc 8 m2))) ) ; end if (if (/= "LWPOLYLINE" m1) prompt "\nSelectFrame!!!");; ERROR HERE? (setq s1 (ssget d_s) ) ; end if (progn (sssetfirst nil nil) s1) (setq i 0) (setq lst1 '()) (setq lst2 '()) (repeat (sslength s1) (setq e (ssname s1 i) obj (vlax-ename->vla-object e) i (1+ i) ) ; end setq (if obj (progn (vla-getboundingbox obj 'point1 'point2) (setq point1 (vlax-safearray->list point1)) (setq point2 (vlax-safearray->list point2)) ) ; end progn ) ; end if (setq cp1 (list (car point1) (cadr point1))) (setq cp2 (list (car point2) (cadr point2))) (setq ks1 (list (car cp1) (cadr cp1) (car cp2) (cadr cp2))) (setq lst1 (cons ks1 ls1)) ) ; end repeat (setq me1 '(0 0)) (setq me2 '(0 0)) (command "LAYOUT" "s" (entlast)) (repeat (sslength s1) (setq lt1 '(0 0)) (setq lt2 '(0 0)) (setq lt1 (list (car (car lst1)) (cadr (car lst1)))) (setq lt2 (list (caddr (car lst1)) (cadddr (car lst1)))) (setq mk1 (list (+ (*(- (car lt1) (car me1)) scale_1) (car me1)) (+ (*(- (cadr lt1) (cadr me1)) scale_1) (cadr me1)))) (setq mk2 (list (+ (*(- (car lt2) (car me2)) scale_1) (car me2)) (+ (*(- (cadr lt2) (cadr me2)) scale_1) (cadr me2)))) (Command "mview" mk1 mk2) (Command "zoom" "w" mk1 mk2) (setq s (cdr (sssetfirst nil (ssget "L")))) (vla-put-mspace (vla-get-ActiveDocument (vlax-get-acad-object)) :vlax-true) (Command "zoom" "w" lt1 lt2 "pspace") (setq vp (vlax-ename->vla-object (entlast))) (vla-put-CustomScale vp scale_1) (vla-put-DisplayLocked vp :vlax-true) (setq lst1 (cdr lst1)) (command "REGENALL") ) ; end repeat ) ; end defun Quote
GLAVCVS Posted Monday at 04:56 PM Posted Monday at 04:56 PM (edited) This is your code ready to work. Check if the result is what you expect. (defun C:frm (/ DCL_ID scale_1 m1 m2 d_s i lst1 lst2 e obj e point1 point2 cp1 cp2 ks1 me1 me2 s mk1 mk2 lt1 lt2 vp) (if (tblsearch "layer" "frame_print") (setvar "clayer" "frame_print") (command "_.Layer" "_Make" "frame_print" "_Color" "220" "" "P" "N" "frame_print" "" "LType" "Continuous" "" "") ) (prompt "\nEnter Scale <1> :") (princ) (setq scale_1 (getreal)) (if (= nil scale_1) (setq scale_1 1)) (setq m2 (entget (car (entsel "\nSelect frame... ")))) (setq m1 (cdr (assoc 0 m2))) (if (= "LWPOLYLINE" m1) (setq d_s (list (assoc 0 m2) (assoc 8 m2))) ) (if (/= "LWPOLYLINE" m1) (prompt "\nSelectFrame!!!") ) (princ "\nSelect objects... ") (setq s1 (ssget d_s)) (progn (sssetfirst nil nil) s1) (setq i 0) (setq lst1 '()) (setq lst2 '()) (repeat (sslength s1) (setq e (ssname s1 i) obj (vlax-ename->vla-object e) i (1+ i) ) (if obj (progn (vla-getboundingbox obj 'point1 'point2) (setq point1 (vlax-safearray->list point1)) (setq point2 (vlax-safearray->list point2)) ) ) (setq cp1 (list (car point1) (cadr point1))) (setq cp2 (list (car point2) (cadr point2))) (setq ks1 (list (car cp1) (cadr cp1) (car cp2) (cadr cp2))) (setq lst1 (cons ks1 lst1)) ) (setq me1 '(0 0)) (setq me2 '(0 0)) (command "_LAYOUT" "_s" (entlast)) (repeat (sslength s1) (setq lt1 '(0 0)) (setq lt2 '(0 0)) (setq lt1 (list (car (car lst1)) (cadr (car lst1)))) (setq lt2 (list (caddr (car lst1)) (cadddr (car lst1)))) (setq mk1 (list (+ (*(- (car lt1) (car me1)) scale_1) (car me1)) (+ (*(- (cadr lt1) (cadr me1)) scale_1) (cadr me1)))) (setq mk2 (list (+ (*(- (car lt2) (car me2)) scale_1) (car me2)) (+ (*(- (cadr lt2) (cadr me2)) scale_1) (cadr me2)))) (Command "_mview" mk1 mk2) (Command "_zoom" "_w" mk1 mk2) (setq s (cdr (sssetfirst nil (ssget "L")))) (vla-put-mspace (vla-get-ActiveDocument (vlax-get-acad-object)) :vlax-true) (Command "_zoom" "_w" lt1 lt2 "_pspace") (setq vp (vlax-ename->vla-object (entlast))) (vla-put-CustomScale vp scale_1) (vla-put-DisplayLocked vp :vlax-true) (setq lst1 (cdr lst1)) (command "_REGENALL") ) ) Edited Monday at 04:57 PM by GLAVCVS Quote
BIGAL Posted Monday at 10:59 PM Posted Monday at 10:59 PM (edited) If you use Vlide it will do bracket checking, I use Notepad++ it has a bracket check function also. just a comment I have 3 make layouts from rectangle, pick a point, walk along pline, horizontal aligned, the make layouts part supports rotated rectangle. Happy to discuss more. Edited Monday at 11:03 PM by BIGAL 2 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.