rodrigo_sjc_sp 发表于 2022-7-6 07:27:10

error in ssget - LWPOLYLINE no

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 ( eqnomeblk pl)    (progn                           (setq local region)    )    )         (setq b (+ b 1))      )   (setq i (+ i 1)))   (vlax-invoke-method rs "movenext")   ) (bd_fim) local)

Lee Mac 发表于 2022-7-6 07:49:13

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:
 

Your code here

rodrigo_sjc_sp 发表于 2022-7-6 08:00:51

=)   .......

rodrigo_sjc_sp 发表于 2022-7-6 08:14:19

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 ?

Lee Mac 发表于 2022-7-6 08:17:11

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 >)

rodrigo_sjc_sp 发表于 2022-7-6 08:34:09

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 ( eqnomeblk pl)   (progn                            (setq local region)   )   )          (setq b (+ b 1)) )      )   (setq i (+ i 1)))))      (vlax-invoke-method rs "movenext")   ) (bd_fim) local)
页: [1]
查看完整版本: error in ssget - LWPOLYLINE no