quocphuoc Posted January 25 Share Posted January 25 (edited) 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 January 25 by SLW210 Added Code Tags! Quote Link to comment Share on other sites More sharing options...
SLW210 Posted January 25 Share Posted January 25 Please use Code Tags in the future. (The <> in the editor toolbar) Quote Link to comment Share on other sites More sharing options...
SLW210 Posted January 25 Share Posted January 25 Did you do a search on the error? Error Message Troubleshooter To trouble shoot see LEE MAC'S ARTICLE. Quote Link to comment Share on other sites More sharing options...
quocphuoc Posted January 25 Author Share Posted January 25 28 minutes ago, SLW210 said: Did you do a search on the error? Error Message Troubleshooter To trouble shoot see LEE MAC'S ARTICLE. Code only works 50%, the remaining 50% doesn't work Quote Link to comment Share on other sites More sharing options...
SLW210 Posted January 25 Share Posted January 25 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? Quote Link to comment Share on other sites More sharing options...
quocphuoc Posted January 25 Author Share Posted January 25 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 25 Share Posted January 25 You should replace the function (entlast) with a layout name available into your drawing. (command "LAYOUT" "s" (entlast)) Quote Link to comment Share on other sites More sharing options...
quocphuoc Posted January 26 Author Share Posted January 26 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 Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 26 Share Posted January 26 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) ) Quote Link to comment Share on other sites More sharing options...
quocphuoc Posted January 26 Author Share Posted January 26 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. 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 26 Share Posted January 26 (edited) Try commenting out this line like this ;; (Command "zoom" "w" lt1 lt2) Edited January 26 by Steven P Quote Link to comment Share on other sites More sharing options...
quocphuoc Posted January 27 Author Share Posted January 27 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, Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 27 Share Posted January 27 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) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 29 Share Posted January 29 I have add rectangs then make layouts. 2 versions a grid style and a walk along a pline. Draw rectangs.mp4 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 30 Share Posted January 30 (edited) 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 January 30 by pkenewell 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted January 30 Share Posted January 30 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) 1 Quote Link to comment Share on other sites More sharing options...
quocphuoc Posted February 17 Author Share Posted February 17 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" Quote Link to comment Share on other sites More sharing options...
SLW210 Posted February 18 Share Posted February 18 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. Quote Link to comment Share on other sites More sharing options...
Steven P Posted February 18 Share Posted February 18 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) Quote Link to comment Share on other sites More sharing options...
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.