明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 333|回复: 7

[提问] 求解(ssget)与(entsel)

[复制链接]
发表于 2024-4-27 17:39 | 显示全部楼层 |阅读模式
本帖最后由 suiran 于 2024-4-27 18:06 编辑

以下是对图形进行X、Y方向比例缩放的程序,但是这个程序是对多个图形缩放,我想改为只能对一个图形缩放,就是点选(entsel)的方式,奈何学艺不精,改了一晚上都没有成功,求坛友们指点迷津!
[size=9.5475pt]
  • (defun C:SF(/ bp ss xscal yscal entL)
  •    (defun errexit (s)
  •      (princ "\nError:  ")
  •      (princ s)
  •      (restore)
  •    )
  •    (defun restore ()
  •      (setvar "CMDECHO" (car oldvar))
  •      (setq *error* olderr)
  •      (princ)
  •    )
  • (defun MAKEUNBLOCK (ss ip / tmp errexit mbx BLAYER)
  •    (setq T (not nil))
  •    (setq olderr  *error*
  •          *error* errexit
  •    )
  •    (setq oldvar
  •      (list
  •        (getvar "CMDECHO")
  •      )
  •    )
  •    (setvar "CMDECHO" 0)
  •    (terpri)
  •    (if BLAYER
  •      (command "._LAYER"
  •        (if (tblsearch "LAYER" BLAYER) "_S" "_M")
  •        BLAYER
  •        ""
  •      )
  •    )
  •    (if (and ip ss)
  •      (progn
  •        (entmake (list
  •          (cons '0 "BLOCK")
  •          (cons '2 "*U")
  •          (cons '70 1)
  •          (cons '10 ip)
  •        ))
  •        (setq cnt (sslength ss))
  •        (while (>= (setq cnt (1- cnt)) 0)
  •          (setq tmp (ssname ss cnt))
  •          (entmake (setq el (entget tmp)))
  •          (if (> (cdr (assoc 66 el)) 0)
  •            (while
  •              (/= "SEQEND"
  •                (cdr
  •                  (assoc 0
  •                    (entmake (setq el (entget (entnext (cdr (assoc -1 el))))))
  •                  )
  •                )
  •              )
  •            )
  •          )
  •          (entdel tmp)
  •        )
  •        (setq tmp (entmake (list (cons '0 "ENDBLK"))))
  •        (entmake (list
  •          (cons '0 "INSERT")
  •          (cons '2 tmp)
  •          (cons '10 ip)
  •        ))
  •      )
  •    )
  •    (restore)
  • )
  •    (setq ss (ssget))    ;;; 选择缩放实体
  •   (if ss
  •      (progn
  •        (setvar "cmdecho" 0)
  •        (setq bp (getpoint "缩放基准点 (<0,0,0>): "))
  •        (if (not bp) (setq bp (list 0 0 0)))
  •        (setq xscal (getreal "X向比例因子 <1>: "))
  •        (if (not xscal) (setq xscal 1))
  •        (setq yscal (getreal "Y向比例因子 <1>: "))
  •        (if (not yscal) (setq yscal 1))
  •        (MAKEUNBLOCK ss bp)
  •        (setq entL (entget (entLast))
  •            entL (subst (cons 41 xscal) (assoc 41 entL) entL)
  •            entL (subst (cons 42 yscal) (assoc 42 entL) entL)
  •        )
  •        (entmod entL)
  •        (command "_explode" "l" "")
  •      )
  •    )
  •    (princ)
  • )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2024-4-27 17:53 | 显示全部楼层
粘贴带有行号的代码,一般人不愿意帮你调试,vlide界面的代码是没有行号的
 楼主| 发表于 2024-4-27 18:07 | 显示全部楼层
dcl1214 发表于 2024-4-27 17:53
粘贴带有行号的代码,一般人不愿意帮你调试,vlide界面的代码是没有行号的

那我传个lsp文件吧。别的也不会
发表于 2024-4-27 19:34 | 显示全部楼层
  1. (defun C:SF(/ bp entl makeunblock ty xscal yscal)
  2.         (defun MAKEUNBLOCK (ty ip / tmp errexit mbx BLAYER)
  3.                 (setvar "CMDECHO" 0)
  4.                 (if (and ip ty)
  5.                         (progn
  6.                                 (entmake (list
  7.                                                                          (cons '0 "BLOCK")
  8.                                                                          (cons '2 "*U")
  9.                                                                          (cons '70 1)
  10.                                                                          (cons '10 ip)
  11.                                                                  )
  12.                                 )
  13.                                 (entmake (setq el (entget ty)))
  14.                                 (if (> (cdr (assoc 66 el)) 0)
  15.                                         (while
  16.                                                 (/= "SEQEND"
  17.                                                         (cdr
  18.                                                                 (assoc 0
  19.                                                                         (entmake (setq el (entget (entnext (cdr (assoc -1 el))))))
  20.                                                                 )
  21.                                                         )
  22.                                                 )
  23.                                         )
  24.                                 )
  25.                                 (entdel ty)
  26.                                 (setq tmp (entmake (list (cons '0 "ENDBLK"))))
  27.                                 (entmake (list
  28.                                                                          (cons '0 "INSERT")
  29.                                                                          (cons '2 tmp)
  30.                                                                          (cons '10 ip)
  31.                                                                  ))
  32.                         )
  33.                 )
  34.         )
  35.         (if (setq ty (car(entsel "\n选择缩放图元:")))
  36.                 (progn
  37.                         (setvar "cmdecho" 0)
  38.                         (setq bp (getpoint "缩放基准点 (<0,0,0>): "))
  39.                         (if (not bp) (setq bp (list 0 0 0)))
  40.                         (setq xscal (getreal "X向比例因子 <1>: "))
  41.                         (if (not xscal) (setq xscal 1))
  42.                         (setq yscal (getreal "Y向比例因子 <1>: "))
  43.                         (if (not yscal) (setq yscal 1))
  44.                         (MAKEUNBLOCK ty bp)
  45.                         (setq
  46.                                 entL (entget (entLast))
  47.                                 entL (subst (cons 41 xscal) (assoc 41 entL) entL)
  48.                                 entL (subst (cons 42 yscal) (assoc 42 entL) entL)
  49.                         )
  50.                         (entmod entL)
  51.                         (command "_explode" "l" "")
  52.                 )
  53.         )
  54.         (princ)
  55. )

评分

参与人数 1明经币 +1 收起 理由
zhoupeng220 + 1 很给力!

查看全部评分

发表于 2024-4-27 20:10 | 显示全部楼层
 楼主| 发表于 2024-4-27 21:26 | 显示全部楼层

感谢大神的再次帮助!已经帮了我好几次了
我好好研究一下,感谢。
发表于 2024-4-28 08:34 | 显示全部楼层
设选择实体为多段线,提取多段线坐标,以起点为基点,把起点坐标调整为(0 0)坐标,则多段线坐标转换为(list(list 0 0)(list 1 1)(list 1 2)),Y方向放大2倍,下一步就得到(list(list0 0)(list1 2)(list1 4))   ,其实就已经完成了坐标计算的搭建。接下来就需要把坐标返回,或者给定标注坐标,生成新的多段线。
 楼主| 发表于 2024-5-5 10:11 | 显示全部楼层
JUN1 发表于 2024-4-28 08:34
设选择实体为多段线,提取多段线坐标,以起点为基点,把起点坐标调整为(0 0)坐标,则多段线坐标转换为(l ...

感谢兄台细心的答复。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-10 00:31 , Processed in 0.182416 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表