乐筑天下

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

[编程交流] Help - Select lines and overla

[复制链接]

57

主题

243

帖子

190

银币

后起之秀

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

铜币
285
发表于 2022-7-5 16:20:25 | 显示全部楼层 |阅读模式
In the attached file, two lines are represented, apparently overlapping. In fact there is one out of the way between 0.0001.
Someone  will be able to achieve a routine that makes it possible to select the  lines, overlapping them with the same y-coordinate. Of course, also for distant lines with other values.
This is an example for horizontal lines but needed equally for vertical lines.
 
Thanks!
 
test_lines.dwg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:48:53 | 显示全部楼层
Not likely to be quick, but should work:
  1. (defun c:linedupes ( / a f i l r s x )   (setq f 1e-3) ;; Fuzz   (if (setq s (ssget "_X" (list '(0 . "LINE") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))       (progn           (repeat (setq i (sslength s))               (setq x (entget (ssname s (setq i (1- i))))                     l (cons (list (cdr (assoc 10 x)) (cdr (assoc 11 x)) (cdr (assoc -1 x))) l)               )           )           (setq r (ssadd))           (while (setq a (car l))               (foreach b (setq l (cdr l))                   (if (or (and (equal (car  a) (car  b) f)                                (equal (cadr a) (cadr b) f)                           )                           (and (equal (cadr a) (car  b) f)                                (equal (car  a) (cadr b) f)                           )                       )                       (progn (ssadd (last a) r) (ssadd (last b) r))                   )               )           )           (if (< 0 (setq n (sslength r)))               (progn                   (princ (strcat "\n" (itoa n) " duplicate line" (if (= 1 n) "" "s") " found."))                   (sssetfirst nil r)               )               (princ "\nNo duplicate lines found.")           )       )   )   (princ))
回复

使用道具 举报

57

主题

243

帖子

190

银币

后起之秀

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

铜币
285
发表于 2022-7-5 16:57:05 | 显示全部楼层
Lee,
Thanks for the attention. Always with fantastic solutions.
 
It works on the part of the selection. Furthermore, in a second step, I intend that once detected, the lines will be moved to overlap each other.
In summary, I want to detect the offset difference between the lines, overlap them and maintain, even if duplicated.
 
Thanks!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 17:12:38 | 显示全部楼层
Assuming I've understood correctly, try the following:
  1. (defun c:linedupes ( / a b f i l m p r s x )      (setq f 1e-3) ;; Fuzz      (if (setq s (ssget "_X" (list '(0 . "LINE") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))       (progn           (repeat (setq i (sslength s))               (setq x (entget (ssname s (setq i (1- i))))                     l (cons (list (cdr (assoc 10 x)) (cdr (assoc 11 x)) (assoc -1 x)) l)               )           )           (while (setq a (car l))               (foreach b (setq l (cdr l))                   (cond                       (   (and (equal (car  a) (car  b) f)                                (equal (cadr a) (cadr b) f)                           )                           (setq m (cons b m))                       )                       (   (and (equal (cadr a) (car  b) f)                                (equal (car  a) (cadr b) f)                           )                           (setq m (cons (list (cadr b) (car b) (last b)) m))                       )                   )               )               (if m (setq r (cons (cons a m) r) m nil))           )           (foreach x r               (setq p                   (mapcar                      '(lambda ( a b ) (cons a (avgpt b)))                      '(10 11)                       (list (mapcar 'car x) (mapcar 'cadr x))                   )               )               (foreach y x (entmod (cons (last y) p)))           )       )   )   (princ))(defun avgpt ( l )   (mapcar '(lambda ( x ) (/ x (length l))) (apply 'mapcar (cons '+ l))))(princ)
回复

使用道具 举报

57

主题

243

帖子

190

银币

后起之秀

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

铜币
285
发表于 2022-7-5 17:23:45 | 显示全部楼层
Lee,
You really are the best. Thanks!
That's exactly it. To be even perfect for what I intend, I should also consider lines of different lengths. But it will already be wanting a lot.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-13 23:04 , Processed in 0.428066 second(s), 62 queries .

© 2020-2025 乐筑天下

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