Jump to content

error in ssget - LWPOLYLINE not found


Recommended Posts

Posted (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 by rodrigo_sjc_sp
Posted

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]

Posted (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 by rodrigo_sjc_sp
Posted

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

Posted

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
)

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