error: bad argument type: numberp: nil

error: bad argument type: numberp: nil

taitrongsong
Enthusiast Enthusiast
375 Views
5 Replies
Message 1 of 6

error: bad argument type: numberp: nil

taitrongsong
Enthusiast
Enthusiast

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.

(if (tblsearch "layer" "frame_print")
(setvar "clayer" "khung_in")
(command "_.Layer" "_Make" "frame_prin" "_Color" "220" "" "P" "N" "frame_prin" "" "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")
)
0 Likes
376 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

Maybe not the only issue, but should this:

(setq lst1 (cons ks1 ls1))

be this:

(setq lst1 (cons ks1 lst1))

instead?  There's no ls1 anywhere else.

Also:

(if (/= "LWPOLYLINE" m1)
     prompt "\nSelectFrame!!!")

is missing some parentheses:

(if (/= "LWPOLYLINE" m1)
     (prompt "\nSelectFrame!!!"))

And should there not be more to it than that?  Not just scolding the User, but including a function for them to select again?  A (while) loop may be appropriate, but I haven't analyzed deeply what's happening.

Kent Cooper, AIA
0 Likes
Message 3 of 6

paullimapa
Mentor
Mentor

curious on the following perhaps a typo on layer name? should layer be "frame_print" or "frame_prin"

(if (tblsearch "layer" "frame_print")
(setvar "clayer" "khung_in")
(command "_.Layer" "_Make" "frame_prin" "_Color" "220" "" "P" "N" "frame_prin" "" "LType" "Continuous" "" ""))

Also there would be an error if layer "khung_in" does not exist.

So instead of this:

(setvar "clayer" "khung_in")

Use this:

(command "_.Layer" "_Make" "khung_in" "")

There also seems to be some extra returns "" in this layer command:

(command "_.Layer" "_Make" "frame_prin" "_Color" "220" "" "P" "N" "frame_prin" "" "LType" "Continuous" "" ""))

Should be:

(command "_.Layer" "_Make" "frame_print" "_Color" "220" "" "_P" "_N" "frame_print" "_LType" "Continuous" "" ""))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 6

ec-cad
Collaborator
Collaborator

This line will fail IF s1 is nil.

(repeat (sslength s1)

And, these lines will fail if 'nothing' is selected with the (entsel..

Maybe prompt as to what you want OP to 'select'.

(setq m2 (entget (car (entsel))))
(setq m1 (cdr (assoc 0 m2)))

 I don't see an end brace for this (if (progn  ... loop.

(if obj
    (progn
      (vla-getboundingbox obj 'point1 'point2)
      (setq point1 (vlax-safearray->list point1))
      (setq point2 (vlax-safearray->list point2))))

 

ECCAD

0 Likes
Message 5 of 6

john.uhden
Mentor
Mentor

I do.

It's at the end of the last line.

John F. Uhden

Message 6 of 6

Sea-Haven
Mentor
Mentor

There are a few of us here that have done what you want, it may be worthwhile doing a google. I have 3 different methods of making rectangs and layouts from them.

 

Compare that to the number of problems in your coding. The other code examples may have more features.

 

0 Likes