乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 9|回复: 5

[编程交流] error in ssget - LWPOLYLINE no

[复制链接]

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 07:27:10 | 显示全部楼层 |阅读模式
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.
 
  1. (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)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 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:
 
[highlight][noparse]
  1. [/noparse][/highlight] Your code here [highlight][noparse]
[/noparse][/highlight]
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 08:00:51 | 显示全部楼层
  1.   =)   .......
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 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 ?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 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.)
 
  1. (if (setq selpline (ssget ... ))   < do something >)
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 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
 
 
 
  1. (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)
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 04:40 , Processed in 0.392810 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表