Jump to content

error: bad argument type: stringp nil


quocphuoc

Recommended Posts

My code is a viewport generator program by selecting a frame from the model, but got the error "error: bad argument type: stringp nil". How can I fix it? Thank you everyone.

 

(defun C:taomv (/ DCL_ID) 
(if (tblsearch "layer" "khung_in")
(setvar "clayer" "khung_in")
(command "_.Layer" "_Make" "khung_in" "_Color" "25" "" "P" "N" "khung_in" "" "LType" "Continuous" "" ""))
(prompt "\nNhap ty le :")(princ)
(setq scale_1 (getreal))
(if (= nil scale_1) (setq scale_1 1))
(prompt "\nSelectframe!!!")(princ)
(setq m2 (entget (car (entsel))))
(setq m1 (cdr (assoc 0 m2)))
(if (= "LWPOLYLINE" m1)
     (setq d_s (list (assoc 0 m2) (assoc 8 m2))))
(setq s1 (ssget d_s))
(progn (sssetfirst nil nil) s1)
(setq i 0)
(setq lst1 '())
(setq lst2 '())
(setq me1 '(0 0))
(setq me2 '(0 0))
(command "LAYOUT" "s" (entlast))
(repeat (sslength s1)
        (setq e (ssname s1 i)
              obj (vlax-ename->vla-object e))         
(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 lt1 (list (+ (*(-(car cp1) (car me1)) scale_1) (car me1)) (+ (*(-(cadr cp1) (cadr me1)) scale_1) (cadr me1))))
(setq lt2 (list (+ (*(-(car cp2) (car me2)) scale_1) (car me2)) (+ (*(-(cadr cp2) (cadr me2)) scale_1) (cadr me2))))
(setq tp1 (list (/ (car lt1) scale_1) (/ (cadr lt1) scale_1)))
(setq tp2 (list (/ (car lt2) scale_1) (/ (cadr lt2) scale_1)))
(Command "mview" lt1 lt2) 
(sssetfirst nil (setq mo (ssget "W" lt1 lt2)))
(Setq k1 (cdr (assoc 69 (entget (ssname mo 0)))))
(command "mspace")(setvar "cvport" k1)
(Command "zoom" "w" tp1 tp2 "pspace")
(setq vp (vlax-ename->vla-object (ssname mo 0)))
(vla-put-CustomScale vp scale_1)
(Command "zoom" "w" lt1 lt2)
(setq i (1+ i))
(setq tp1 (cdr tp1))
(setq tp2 (cdr tp2))
(setq lt1 (cdr lt1))
(setq lt2 (cdr lt2))
)
)

 

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

error: bad argument type: stringp nil --- A function requiring a string argument has been passed an argument of incorrect data type with the value noted in the error message.

 

Did you follow the instructions in Lee Mac's article?

 

If so, what were the results?

Link to comment
Share on other sites

1 hour ago, SLW210 said:

error: bad argument type: stringp nil --- A function requiring a string argument has been passed an argument of incorrect data type with the value noted in the error message.

 

Did you follow the instructions in Lee Mac's article?

 

If so, what were the results?

It's still the same

Link to comment
Share on other sites

You should replace the function (entlast) with a layout name available into your drawing.

(command "LAYOUT" "s" (entlast))

 

Link to comment
Share on other sites

4 hours ago, Tharwat said:

You should replace the function (entlast) with a layout name available into your drawing.

(command "LAYOUT" "s" (entlast))

 

@Tharwat it occurs adding error lselsetp nil

Link to comment
Share on other sites

how far have you got with checking this? If you comment out all the lines and add them back in again one at a time - or a section at a time I am sure you'll find the problem by that, test the code and see when the problem starts.

 

 

 

 

(defun C:taomv ( / DCL_ID)
  (if (tblsearch "layer" "khung_in")
    (setvar "clayer" "khung_in")
    (command "_.Layer" "_Make" "khung_in" "_Color" "25" "" "P" "N" "khung_in" "" "LType" "Continuous" "" "")
  ) ; end if
  (prompt "\nNhap ty le / Enter a scale :")(princ) ;;Enter a scale
  (setq scale_1 (getreal))
  (if (= nil scale_1) (setq scale_1 1))
;;  (prompt "\nSelectframe!!!")(princ)
  (setq m2 (entget (car (entsel "Select a reference frame")))) ;; Reference frame?
  (setq m1 (cdr (assoc 0 m2)))
  (if (= "LWPOLYLINE" m1)
     (setq d_s (list (assoc 0 m2) (assoc 8 m2)))
  ) ; end if

(princ "\nSelect frames")
  (setq s1 (ssget d_s))
  (progn (sssetfirst nil nil) s1)
  (setq i 0)
  (setq lst1 '())
  (setq lst2 '())
  (setq me1 '(0 0))
  (setq me2 '(0 0))
  (command "LAYOUT" "s" (entlast))
  (repeat (sslength s1)
    (setq e (ssname s1 i)
          obj (vlax-ename->vla-object e)
    ) ; end setq
    (if obj
      (progn
        (vla-getboundingbox obj 'point1 'point2)
        (setq point1 (vlax-safearray->list point1))
        (setq point2 (vlax-safearray->list point2))
    )) ; end if end progn
    (setq cp1 (list (car point1) (cadr point1)))
    (setq cp2 (list (car point2) (cadr point2)))
    (setq lt1 (list (+ (*(-(car cp1) (car me1)) scale_1) (car me1)) (+ (*(-(cadr cp1) (cadr me1)) scale_1) (cadr me1))))
    (setq lt2 (list (+ (*(-(car cp2) (car me2)) scale_1) (car me2)) (+ (*(-(cadr cp2) (cadr me2)) scale_1) (cadr me2))))
    (setq tp1 (list (/ (car lt1) scale_1) (/ (cadr lt1) scale_1)))
    (setq tp2 (list (/ (car lt2) scale_1) (/ (cadr lt2) scale_1)))
    (Command "mview" lt1 lt2)
    (sssetfirst nil (setq mo (ssget "W" lt1 lt2)))
    (Setq k1 (cdr (assoc 69 (entget (ssname mo 0)))))
    (command "mspace")(setvar "cvport" k1)
    (Command "zoom" "w" tp1 tp2 "pspace")
    (setq vp (vlax-ename->vla-object (ssname mo 0)))
    (vla-put-CustomScale vp scale_1)
;;    (Command "zoom" "w" lt1 lt2)
    (setq i (1+ i))
    (setq tp1 (cdr tp1))
    (setq tp2 (cdr tp2))
    (setq lt1 (cdr lt1))
    (setq lt2 (cdr lt2))

    (Command "zoom" "w" lt1 lt2)

  ) ; end repeat
  (princ)
)

 

Link to comment
Share on other sites

38 minutes ago, Steven P said:

how far have you got with checking this? If you comment out all the lines and add them back in again one at a time - or a section at a time I am sure you'll find the problem by that, test the code and see when the problem starts.

 

 

 

 

(defun C:taomv ( / DCL_ID)
  (if (tblsearch "layer" "khung_in")
    (setvar "clayer" "khung_in")
    (command "_.Layer" "_Make" "khung_in" "_Color" "25" "" "P" "N" "khung_in" "" "LType" "Continuous" "" "")
  ) ; end if
  (prompt "\nNhap ty le / Enter a scale :")(princ) ;;Enter a scale
  (setq scale_1 (getreal))
  (if (= nil scale_1) (setq scale_1 1))
;;  (prompt "\nSelectframe!!!")(princ)
  (setq m2 (entget (car (entsel "Select a reference frame")))) ;; Reference frame?
  (setq m1 (cdr (assoc 0 m2)))
  (if (= "LWPOLYLINE" m1)
     (setq d_s (list (assoc 0 m2) (assoc 8 m2)))
  ) ; end if

(princ "\nSelect frames")
  (setq s1 (ssget d_s))
  (progn (sssetfirst nil nil) s1)
  (setq i 0)
  (setq lst1 '())
  (setq lst2 '())
  (setq me1 '(0 0))
  (setq me2 '(0 0))
  (command "LAYOUT" "s" (entlast))
  (repeat (sslength s1)
    (setq e (ssname s1 i)
          obj (vlax-ename->vla-object e)
    ) ; end setq
    (if obj
      (progn
        (vla-getboundingbox obj 'point1 'point2)
        (setq point1 (vlax-safearray->list point1))
        (setq point2 (vlax-safearray->list point2))
    )) ; end if end progn
    (setq cp1 (list (car point1) (cadr point1)))
    (setq cp2 (list (car point2) (cadr point2)))
    (setq lt1 (list (+ (*(-(car cp1) (car me1)) scale_1) (car me1)) (+ (*(-(cadr cp1) (cadr me1)) scale_1) (cadr me1))))
    (setq lt2 (list (+ (*(-(car cp2) (car me2)) scale_1) (car me2)) (+ (*(-(cadr cp2) (cadr me2)) scale_1) (cadr me2))))
    (setq tp1 (list (/ (car lt1) scale_1) (/ (cadr lt1) scale_1)))
    (setq tp2 (list (/ (car lt2) scale_1) (/ (cadr lt2) scale_1)))
    (Command "mview" lt1 lt2)
    (sssetfirst nil (setq mo (ssget "W" lt1 lt2)))
    (Setq k1 (cdr (assoc 69 (entget (ssname mo 0)))))
    (command "mspace")(setvar "cvport" k1)
    (Command "zoom" "w" tp1 tp2 "pspace")
    (setq vp (vlax-ename->vla-object (ssname mo 0)))
    (vla-put-CustomScale vp scale_1)
;;    (Command "zoom" "w" lt1 lt2)
    (setq i (1+ i))
    (setq tp1 (cdr tp1))
    (setq tp2 (cdr tp2))
    (setq lt1 (cdr lt1))
    (setq lt2 (cdr lt2))

    (Command "zoom" "w" lt1 lt2)

  ) ; end repeat
  (princ)
)

 

when I check each line the error doesn't appear, but when I run the program it appears again.

  • Like 1
Link to comment
Share on other sites

Try commenting out this line like this

 

;;    (Command "zoom" "w" lt1 lt2)

 

Edited by Steven P
Link to comment
Share on other sites

12 hours ago, Steven P said:

Try commenting out this line like this

 

;;    (Command "zoom" "w" lt1 lt2)

 

i tried but it still doesn't work, 😑

Link to comment
Share on other sites

Ahh, try moving that line earlier in the code maybe?

 

If you comment out all the lines and work down the code adding the lines back in again (remembering to add in end brackets as necessary), then there will be a bit of the code where it all stops working.... and that is where your error is.

 

A man once said "Note that graphical ssget selection modes (e.g. Window / Crossing / Polygon) will only select objects that are visible on screen at the time of selection." by way of a hint (Thanks Lee Mac, I was searching just to confirm this and your words are as good as mine)

Link to comment
Share on other sites

On 1/25/2024 at 7:36 AM, quocphuoc said:

My code is a viewport generator program by selecting a frame from the model, but got the error "error: bad argument type: stringp nil". How can I fix it? Thank you everyone.

 

@quocphuoc This code has a multitude of problems and honestly does not make much sense when I tried to break it down. For Example: you are experiencing your first error with the LAYOUT command.

(command "LAYOUT" "s" (entlast))

you need to have a STRING here representing a layout name to set:

(command "LAYOUT" "s" "MyLayoutName")

 

There are some viewport creation routines out there for Free that will do what you want. This code will not get you what you want, and will not even run without many errors.

 

Try this one revised by Roy_043:

https://www.theswamp.org/index.php?topic=47145.msg523226#msg523226

 

Another from Lee Mac:

Here is one for Free from the App Store:

https://apps.autodesk.com/ACD/en/Detail/Index?id=2430986909281925511&appLang=en&os=Win32_64

Edited by pkenewell
  • Like 1
Link to comment
Share on other sites

The (command "layout" "s" (entlast) ) needs to be changed but isn't a terminal error in the routine - on my system - it will keep going for me.

 

I think the error that the OP has starts at the (ssget "w".... ) line, if the zoom isn't showing the window nothing is selected.

 

 

(waiting for the OP to come back and show what they have worked out or to ask for more guidance)

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
On 1/30/2024 at 11:21 PM, Steven P said:

The (command "layout" "s" (entlast) ) needs to be changed but isn't a terminal error in the routine - on my system - it will keep going for me.

 

I think the error that the OP has starts at the (ssget "w".... ) line, if the zoom isn't showing the window nothing is selected.

 

 

(waiting for the OP to come back and show what they have worked out or to ask for more guidance)

I tried this but an error occurred "lselsetp nil"

Link to comment
Share on other sites

On 1/25/2024 at 11:55 AM, quocphuoc said:

It's still the same

If you would follow the troubleshooting instructions posted, you would never get a result "still the same".

 

Why don't you try actually troubleshooting the program yourself?

 

At least post the actual results from the troubleshooting.

 

If you don't want to fix the code you have, then use one of the alternatives posted here.

Link to comment
Share on other sites

OK I guess you did a search on what the error message means? ( see: https://lee-mac.com/errormessages.html if you didn't)

 

 

".... This is usually a result of passing the sslength or ssnamex function a null selection set argument.... " - that essentially means you are trying to do something with a selection set that is empty. Work out why it is empty, fix that and it should work (3 weeks later I can't remember what the solution is now)

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...