rodrigo_sjc_sp Posted October 5, 2012 Posted October 5, 2012 (edited) I have this code : (setq cod "FIRSTPL") (setq cod (setq selpline (ssget "_x" (list '(0 . "LWPOLYLINE")(cons 8 cod)))) If Polyline not exist in DWG , the AutoLisp return "Command: ; error: bad argument type: lselsetp nil" And broke the program. I need help , to polyline not exists , continue the program Thanks Rodrigo COMPLETE CODE : This routine goes through all the polylines, and scours all items within this polyline. The problem is that if I pass the name of a polyline that does not exist in dwg it returns the error above. (defun acha_sub(param_s) (bd_sql) (vlax-put-property cmd "CommandText" (strcat "select * from Floor ")) (setq rs nil) (setq rs (vlax-create-object "ADODB.Recordset")) (vlax-invoke-method rs "OPEN" cmd nil nil nil nil) (setq campos (vlax-get-property rs "Fields")) (setq cod nil) (setq lista_temp nil) (while (not (equal :vlax-true (vlax-get-property rs "EOF"))) (if (not (equal :vlax-true (vlax-get-property rs "EOF"))) (progn (setq item0 (vlax-get-property campos "item" 1)) (setq cod (vlax-variant-value (vlax-get-property item0 "value"))) ) ) (setq pl param_s) (command "_zoom" "_e") (command "_zoom" "0.8x") (setq region cod) (setq selpline (ssget "_x" (list '(0 . "LWPOLYLINE")(cons 8 cod)))) (setq i 0) (repeat (sslength selpline) (setq pline_ent (ssname selpline i)) (setq lis_ent (entget pline_ent)) (setq j 0) (setq b 0) (setq achou "N") (setq lis_coords '()) (repeat (length lis_ent) (if (= (car (nth j lis_ent)) 10) (setq lis_coords (append lis_coords (list (cdr (nth j lis_ent))))) ) (setq j (+ j 1)) ) (setq selec (ssget "wp" lis_coords ) ) (repeat (sslength selec) (setq entblk (ssname selec b)) (setq nomeblk (cdr(assoc 8 (entget entblk)))) (if ( eq nomeblk pl) (progn (setq local region) ) ) (setq b (+ b 1)) ) (setq i (+ i 1)) ) (vlax-invoke-method rs "movenext") ) (bd_fim) local ) Edited October 5, 2012 by rodrigo_sjc_sp Quote
Lee Mac Posted October 5, 2012 Posted October 5, 2012 Use an if statement to test for the existence of the selection set before using selection set functions (such as sslength, ssname etc.) Also, please edit your post and enclose your code in code tags: [highlight][noparse] [/noparse][/highlight] Your code here [highlight][noparse] [/noparse][/highlight] Quote
rodrigo_sjc_sp Posted October 5, 2012 Author Posted October 5, 2012 (edited) The error inside in (repeat (sslength selpline) If the polyline not exist ou inside is empty , the error is bad argument type: lselsetp nil How run (repeat) without error ? Edited October 5, 2012 by rodrigo_sjc_sp Quote
Lee Mac Posted October 5, 2012 Posted October 5, 2012 As I've already said, use an if statement to test for the existence of the selection set before using selection set functions (such as sslength, ssname etc.) (if (setq selpline (ssget ... )) < do something > ) Quote
rodrigo_sjc_sp Posted October 5, 2012 Author Posted October 5, 2012 Thanks lee , the code now is ok! The code below does a search within a sequence of Polylines to find a polyline associated with a particular layer (param_s) To get other information from polyline, just change the following line (if (setq selpline (ssget "_x" (list '(0. "LWPOLYLINE") (cons 8 cod)))) The variable that stores the value of the inner layer of each polyline is nomeblk (defun acha_sub(param_s) (bd_sql) (vlax-put-property cmd "CommandText" (strcat "select * from Floor")) (setq rs nil) (setq rs (vlax-create-object "ADODB.Recordset")) (vlax-invoke-method rs "OPEN" cmd nil nil nil nil) (setq campos (vlax-get-property rs "Fields")) (setq cod nil) (setq lista_temp nil) (while (not (equal :vlax-true (vlax-get-property rs "EOF"))) (if (not (equal :vlax-true (vlax-get-property rs "EOF"))) (progn (setq item0 (vlax-get-property campos "item" 1)) (setq cod (vlax-variant-value (vlax-get-property item0 "value"))) ) ) (setq pl param_s) (command "_zoom" "_e") (command "_zoom" "0.8x") (setq region cod) (if (setq selpline (ssget "_x" (list '(0 . "LWPOLYLINE")(cons 8 cod)))) (progn (setq i 0) (repeat (sslength selpline) (setq pline_ent (ssname selpline i)) (setq lis_ent (entget pline_ent)) (setq j 0) (setq b 0) (setq achou "N") (setq lis_coords '()) (repeat (length lis_ent) (if (= (car (nth j lis_ent)) 10) (setq lis_coords (append lis_coords (list (cdr (nth j lis_ent))))) ) (setq j (+ j 1)) ) (if (setq selec (ssget "wp" lis_coords ) ) (repeat (sslength selec) (setq entblk (ssname selec b)) (setq nomeblk (cdr(assoc 8 (entget entblk)))) (if ( eq nomeblk pl) (progn (setq local region) ) ) (setq b (+ b 1)) ) ) (setq i (+ i 1)) ) )) (vlax-invoke-method rs "movenext") ) (bd_fim) local ) 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.