明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 44700|回复: 362

[源码] 超级SuperMeasure(更新到2014年2月12日)

  [复制链接]
发表于 2013-5-7 11:32 | 显示全部楼层 |阅读模式
本帖最后由 自贡黄明儒 于 2015-3-24 13:08 编辑

Me是我工作中常用的一个工具,但使用起来很麻烦,于是动手.....自贡黄明儒 2013年5月7日
以前写过这个程序,经不断实战,现在觉得完善了,所以重发
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;超级SuperMeasure
  2. (defun C:SM (/ A AN AN0 BASEPT BETWEEN BOOL CURVEBLOCK CURVELENGTH DISTANC EN FIRSTPOINT LASTB LASTBLIST LASTBLOCK N PP PT PT0 SSADD1 STRIN TRIN VT)
  3.   ;;0 错误处理
  4.   (defun *error* (msg)
  5.     (vl-bt)
  6.     (if *DOC*
  7.       (_EndUndo *DOC*)      ;块内图元增减
  8.     )
  9.     (while (not (equal (getvar "cmdnames") "")) (command nil))
  10.     (princ "\n 出错啦!")
  11.     (princ)
  12.   )
  13.   ;;3  pt0离起点近,返回T
  14.   (defun stratpointT (en pt0 / CURVELENGTH L1)
  15.     (setq CurveLength
  16.     (vlax-curve-getDistAtParam
  17.       en
  18.       (vlax-curve-getEndParam en)
  19.     )
  20.     )
  21.     (setq L1 (vlax-curve-getDistAtPoint en pt0))
  22.     (< L1 (- CurveLength L1))
  23.   )
  24.   ;;4  产生块
  25.   (defun NAME_BLK (CurveLength / A Y)
  26.     (setq A (rtos (* (getvar "CDATE") 1E8)))
  27.     (setq Y (/ CurveLength 5.0))
  28.     (entmake (list '(0 . "LINE")
  29.      (cons 10 (list 0 0 0))
  30.      (cons 11 (list 0 y 0))
  31.       )
  32.     )
  33.     (command "_.BLOCK"
  34.       A
  35.       "non"
  36.       (list 0 (/ y 2.0) 0)
  37.       (entlast)
  38.       ""
  39.     )
  40.     A
  41.   )
  42.   ;;5 块中有属性,增加值为n
  43.   (defun MyAttAdd (en n / ELIST N1 N3 NEND QIANZ STREND TEXT)
  44.     (setq elist (entget (entnext en)))
  45.     (setq text (cdr (assoc 1 elist)))
  46.     (setq n3 (strlen text))     ;字符串总长
  47.     (setq strEND (getNumberS text))    ;最后的数字
  48.     (setq Nend (nth (1- (length strEND)) strEND))
  49.     (setq n1 (strlen Nend))     ;最后一位数字符串总长
  50.     (setq qianZ (substr text 1 (- n3 n1)))   ;前缀
  51.     (setq strEND (+ (atof (car strEND)) n))   ;未尾数字加n
  52.     (setq strEND (strcat qianZ (rtos strEND 2 3)))
  53.     (entmod (subst (cons 1 strEND) (assoc 1 elist) elist))
  54.     (entupd en)
  55.     ;;(BURST-ONE1 en);爆破属性块
  56.   )
  57.   ;;6 Text,增加值为n
  58.   (defun MyTextAdd (en n / ELIST N1 N3 NEND QIANZ STREND TEXT)
  59.     (setq elist (entget en))
  60.     (setq text (cdr (assoc 1 elist)))
  61.     (setq n3 (strlen text))     ;字符串总长
  62.     (setq strEND (getNumberS text))    ;最后的数字
  63.     (setq Nend (nth (1- (length strEND)) strEND))
  64.     (setq n1 (strlen Nend))     ;最后一位数字符串总长
  65.     (setq qianZ (substr text 1 (- n3 n1)))   ;前缀
  66.     (setq strEND (+ (atof (car strEND)) n))   ;未尾数字加n
  67.     (setq strEND (strcat qianZ (rtos strEND 2 3)))
  68.     (entmod (subst (cons 1 strEND) (assoc 1 elist) elist))
  69.   )
  70.   ;;7  主程序
  71.   (vl-load-com)
  72.   (or *DOC*
  73.       (setq *DOC* (vla-get-ActiveDocument (vlax-get-acad-object)))
  74.   )
  75.   (_StartUndo *DOC*)
  76.   (setvar "nomutt" 1)
  77.   (princ "\n >拾取曲线")
  78.   (while (not
  79.     (and (setq en (ssget ":E:S" '((0 . "*LINE,ARC,ELLIPSE"))))
  80.   (setq en (ssname en 0))
  81.     )
  82.   )
  83.     (princ "\n >重新拾取曲线")
  84.   )
  85.   (setvar "nomutt" 0)
  86.   (setq pt0 (vlax-curve-getClosestPointTo en (cadr (grread T 8))))
  87.   ;;曲线长度
  88.   (setq CurveLength
  89.   (vlax-curve-getDistAtParam
  90.     en
  91.     (vlax-curve-getEndParam en)
  92.   )
  93.   )
  94.   (setq curveBlock
  95.   (car (ENTSEL "\n ..>>拾取沿线布置的对象:"))
  96.   )
  97.   (if curveBlock
  98.     nil
  99.     (progn (setq A (NAME_BLK CurveLength))
  100.     (command "_.INSERT" A "@" "" "" "")
  101.     (setq lastblock (entlast))
  102.     (setq curveBlock lastblock)
  103.     )
  104.   )
  105.   (setq an0 (entget curveBlock))   ;转角
  106.   (setq basePt (cdr (assoc 10 an0)))
  107.   (setq an0 (cdr (assoc 50 an0)))   ;转角
  108.   ;; 输入块间距  
  109.   (setq bool T)
  110.   (setq strin (strcat "\n ...>>>曲线长度为"
  111.         (rtos CurveLength 2 3)
  112.         ",输入布置间距: "
  113.        )
  114.   )
  115.   (while bool
  116.     (initget 7)
  117.     (setq between (getreal strin))
  118.     (if (> between CurveLength)
  119.       (progn (setq bool T) (alert "对象间距必须小于曲线长度!!!"))
  120.       (setq bool nil)
  121.     )
  122.   )
  123.   (initget 4)
  124.   (setq strin (rtos (/ (rem CurveLength between) 2.0) 2 3))
  125.   (setq
  126.     distanc (getreal
  127.        (strcat "\n ....>>>>第一个对象与曲线端点之距离<" strin ">:")
  128.      )
  129.   )
  130.   (if distanc
  131.     nil
  132.     (setq distanc (/ (rem CurveLength between) 2.0))
  133.   )
  134.   ;;插入块的数量
  135.   (setq n (fix (/ (- CurveLength distanc) between)))
  136.   (if (stratpointT en pt0)
  137.     (setq firstPoint distanc)
  138.     (setq firstPoint (rem (- CurveLength distanc) between))
  139.   )
  140.   (setq ssadd1 (ssadd))
  141.   (repeat (setq n (1+ n))
  142.     (setq pt (vlax-curve-getPointAtDist en firstPoint)
  143.    pp (vlax-curve-getParamAtPoint en Pt)   ;得到这点参数
  144.    vt (vlax-curve-getFirstDeriv en pp)   ;得到切线
  145.    an (angle '(0 0 0) vt)    ;切线角
  146.     )
  147.     (command "._copy" curveBlock "" "non" basePt "non" PT)
  148.     (setq LastB (entlast))
  149.     (setq LastBList (entget LastB))
  150.     (cond ((assoc 66 LastBList) (MyAttAdd LastB (setq n (1- n))))
  151.    ((equal (cdr (assoc 0 LastBList)) "TEXT")
  152.     (MyTextAdd LastB (setq n (1- n)))
  153.    )
  154.     )
  155.     ;;(entmod (subst (cons 50 an) (assoc 50 LastBList) LastBList))
  156.     (command "_.rotate" LastB "" "non" pt (/ (* 180 (- an an0)) pi))
  157.     (setq ssadd1 (ssadd LastB ssadd1))
  158.     (setq firstPoint (+ firstPoint between))
  159.   )
  160.   (if lastblock
  161.     (command "._erase" lastblock "")
  162.     (progn (initget "R  ")
  163.     (setq trin
  164.     (getstring "\n要使块旋转180度,输入R<回车>")
  165.     )
  166.     (if (or (equal trin "R") (equal trin "r"))
  167.       (repeat (setq n (sslength ssadd1))
  168.         (setq LastB (ssname ssadd1 (setq n (1- n))))
  169.         (setq LastBList (entget LastB))
  170.         (setq an (cdr (assoc 50 LastBList)))
  171.         (setq an (+ an pi))
  172.         (entmod (subst (cons 50 an) (assoc 50 LastBList) LastBList))
  173.       )
  174.     )
  175.     )
  176.   )
  177.   (_EndUndo *DOC*)
  178.   (princ)
  179. )

;;编组开始;(command "_.undo" "be")
(defun _StartUndo (*DOC*)
  (_EndUndo *DOC*)
  (vla-StartUndoMark *DOC*)
)
;;结束编组;(if (= 8 (logand (getvar "undoctl") 8)) (command "_.undo" "_e"))
(defun _EndUndo (*DOC*)
  (if (= 8 (logand 8 (getvar 'UNDOCTL)))
    (vla-EndUndoMark *DOC*)
  )
)

由于点这个的比较多,故更新到文件2014年2月

本帖子中包含更多资源

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

x

点评

请问黄大师,这个跟http://bbs.mjtd.com/thread-108715-1-1.html 功能是否一样?  发表于 2014-3-12 22:08
黄大师,能否上传一个演示?  发表于 2014-3-1 10:26
"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

发表于 2019-12-26 13:29 | 显示全部楼层
命令: ARR 反向跟踪:
[0.51] (VL-BT)
[1.47] (*ERROR* "no function definition: _STARTUNDO")
[2.42] (_call-err-hook #<SUBR @00000000422d17c8 *ERROR*> "no function definition: _STARTUNDO")
[3.36] (sys-error "no function definition: _STARTUNDO")
:ERROR-BREAK.31 nil
[4.28] (#<SUBR @00000000360d8bb0 null-fun-hk> #<VLA-OBJECT IAcadDocument 000000002c780fc8>)
[5.24] (_STARTUNDO #<VLA-OBJECT IAcadDocument 000000002c780fc8>)
[6.19] (C:ARR)
[7.15] (#<SUBR @00000000422d1cc8 -rts_top->)
[8.12] (#<SUBR @00000000360d8700 veval-str-body> "(C:ARR)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
无函数定义: _ENDUNDO
发表于 2023-11-19 16:50 | 显示全部楼层
大师,这个[R]旋转可以自定义角度吗
发表于 2019-9-14 16:28 | 显示全部楼层
这个和ME有什么不同,超级再哪里?
发表于 2013-5-7 11:49 | 显示全部楼层
不错,顶一个。
发表于 2013-5-7 13:47 | 显示全部楼层
黄大侠的又一力作,我顶黄大侠
发表于 2013-5-7 15:26 | 显示全部楼层
no function definition: MC:ENTSEL1

点评

MC:ENTSEL1是C版的程序,你可用entsel代替之  发表于 2013-5-7 15:31
发表于 2013-5-7 15:41 | 显示全部楼层
呵呵!用用试试看!
发表于 2013-5-7 15:46 | 显示全部楼层
no function definition: MC:ENTSEL1

点评

MC:ENTSEL1是C版的程序,你可用entsel代替之  发表于 2013-5-7 16:01
发表于 2013-7-23 16:24 | 显示全部楼层
发表于 2013-9-11 17:38 | 显示全部楼层
不错,收藏了
发表于 2013-9-12 10:00 | 显示全部楼层
不错,顶一个
发表于 2013-9-12 17:03 | 显示全部楼层
让我学习一下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-20 19:54 , Processed in 0.215839 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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