明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: Gu_xl

[【Gu_xl】] 【局部放大】源码公布

    [复制链接]
 楼主| 发表于 2013-7-26 14:05:41 | 显示全部楼层
flytoday 发表于 2013-7-26 13:45
相应的标注。。。与字没有放大~~~~~~~~~~~~~~~~

注释掉如下代码即可放大文字和标注线型等:
(gxl-setOverride (vlax-vla-object->ename unblk) scale)

评分

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

查看全部评分

回复 支持 1 反对 0

使用道具 举报

发表于 2013-7-26 14:23:20 | 显示全部楼层
哈哈,终于出来了哈,哈哈
发表于 2013-7-26 15:06:48 | 显示全部楼层
本帖最后由 自贡黄明儒 于 2013-7-26 15:31 编辑

终于盼来了G版的源码,是各位给图员的福气
响应G版号召,贴出我改编的源码
  1. ;;*************************************************************************放大主程序
  2. ;;全局JBFD_GetScalStri放大倍数(字符),JBFD_BaseNumber标识(数字),JBFD_ZoomStri视口
  3. (defun C:FD (/              BASESYMBOL        BLI1         CLA1          CMD1           CP
  4.              DCLID    DIM1     ENT        ENTCICL         ENTTEXT  FN           FNAME
  5.              GETZOOM  LAY      LIN        NEWBLOCK NEWP          NEWSS           OSM1
  6.              P1              P2       PL        RETURN#         SCALREAL SS           TEXTHEIGH
  7.              X
  8.             )
  9.   ;;1 错误处理
  10.   (defun *error* (s)
  11.     (while (not (equal (getvar "cmdnames") "")) (command nil))
  12.     (if        entText
  13.       (command "_.erase" entText "")
  14.     )
  15.     (if        lay
  16.       (setvar "clayer" lay)
  17.     )
  18.     (setvar "blipmode" bli1)
  19.     (setvar "cmdecho" cmd1)
  20.     (setvar "DIMASSOC" DIM1)
  21.     (setvar "osmode" osm1)
  22.     (princ s)
  23.     (princ "出错啦!")
  24.     (princ)
  25.   )
  26.   ;;2 对象是否在锁定层上
  27.   (defun onlocked (ename / entlst)
  28.     (setq entlst (tblsearch "LAYER" (cdr (assoc 8 (entget ename)))))
  29.     (= 4 (logand 4 (cdr (assoc 70 entlst))))
  30.   )
  31.   ;;3  构成新的选择集,EntCicl不加入
  32.   (defun ss=>NewSS (SS EntCicl / E N NEWSS)
  33.     (setq NewSS (ssadd))
  34.     (repeat (setq n (sslength ss))
  35.       (setq e (ssname ss (setq n (1- n))))
  36.       (if (or (equal e EntCicl) (onlocked e))
  37.         nil
  38.         (progn
  39.           (command "_.copy" e "" (list 0 0 0) (list 0 0 0))
  40.           (setq NewSS (ssadd (entlast) NewSS))
  41.         )
  42.       )
  43.     )
  44.     NewSS
  45.   )
  46.   ;;4 0层上生成块
  47.   (defun NONAME_BLK (SS PCircl / A lay)
  48.     (setq lay (getvar "clayer"))
  49.     (setvar "clayer" "0")
  50.     (setq A (rtos (* (getvar "CDATE") 1E8)))
  51.     (if        (and SS PCircl)
  52.       (progn
  53.         (command "_.BLOCK" A PCircl SS "")
  54.         (command "_.INSERT" A "@" "" "" "")
  55.       )
  56.     )
  57.     (setvar "clayer" lay)
  58.     (entlast)
  59.   )
  60.   ;;5 画引线
  61.   (defun HdrawLeader (EntCicl BaseSymbol      Textheigh              CP      /
  62.                       A              AA      B              BB      C              CC      D
  63.                       DD      EE      ENTTEXT FF      I              TEXTLIS
  64.                      )
  65.     (command "_.text" CP Textheigh "" BaseSymbol)
  66.     (setq entText (entlast))

  67.     (setq TextLis (entget entText))
  68.     (setq i T)
  69.     (while i
  70.       (setq a (grread T 4 0)
  71.             b (car a)
  72.             c (cadr a)
  73.       )
  74.       ;;b=5移动,b=3左键,c=0右键,;;c=13回车,c=32空格
  75.       (cond ((= b 5)
  76.              (redraw)
  77.              (setq a (trans (cadr a) 1 0))
  78.              (setq d (vlax-curve-getclosestpointto EntCicl a))
  79.              (setq aa (car a)
  80.                    bb (cadr a)
  81.                    cc (caddr a)
  82.              )
  83.              (setq dd (car d)
  84.                    ee (cadr d)
  85.                    ff (caddr d)
  86.              )
  87.              (if (<= aa dd)
  88.                (progn (setq TextLis (subst (cons 72 2) (assoc 72 TextLis) TextLis))
  89.                       (setq TextLis (subst (cons 11 a) (assoc 11 TextLis) TextLis))
  90.                )
  91.                (progn (setq TextLis (subst (cons 72 0) (assoc 72 TextLis) TextLis))
  92.                       (setq TextLis (subst (cons 10 a) (assoc 10 TextLis) TextLis))
  93.                )
  94.              )
  95.              (entmod TextLis)
  96.              (grdraw a d 1)
  97.             )
  98.             ((= b 3) (setq i nil))
  99.       )
  100.     )

  101.     (redraw)
  102.     (entdel entText)
  103.     (if        (VL-CATCH-ALL-ERROR-P
  104.           (VL-CATCH-ALL-APPLY 'setvar (list "DIMLDRBLK" "DotSmall"))
  105.         )
  106.       (VL-CATCH-ALL-APPLY 'setvar (list "DIMLDRBLK" "小点"))
  107.     )
  108.     (vl-cmdf "_.layer" "make" "DIM" "Color" 3 "" "")
  109.     (command "_.leader" d (cadr a) "" BaseSymbol "")
  110.   )

  111.   ;;6 返回多义线顶点点列表,有圆弧则用一定角度分割圆弧,闭合多义线点表不含闭合点坐标
  112.   ;;(setq pl (gxl-pL ent 0.017))
  113.   (defun gxl-pL        (en        fgx    /      BJ     BUGLE  D           D0          D1         D2
  114.                  ENT        K      N      OBJ    OBJNAME           PARAM  PLIST         PT
  115.                  SECDEV        VERTEXSNUM
  116.                 )
  117.     ;;gxl-get_poly_ptList 返回多义线顶点点列表不含圆弧段内容,闭合多义线点表不含闭合点坐标
  118.     ;;(gxl-get_poly_ptList (car (entsel)))
  119.     (defun gxl-get_poly_ptList (e / _pl n k)
  120.       (if (= 'ename (type e))
  121.         (setq e (vlax-ename->vla-object e))
  122.       )
  123.       (cond ((= "AcDbCircle" (vla-get-ObjectName e))
  124.              (list (vlax-curve-getPointAtParam e 0)
  125.                    (vlax-curve-getPointAtParam e (* pi 0.5))
  126.                    (vlax-curve-getPointAtParam e pi)
  127.                    (vlax-curve-getPointAtParam e (* 1.5 pi))
  128.              )
  129.             )
  130.             ((= "AcDbArc" (vla-get-ObjectName e))
  131.              (list (vlax-curve-getStartPoint e)
  132.                    (vlax-curve-getendPoint e)
  133.              )
  134.             )
  135.             (t
  136.              (setq n (1+ (fix (vlax-curve-getEndParam e)))
  137.                    k -1
  138.              )
  139.              (if (vlax-curve-isClosed e)
  140.                (setq n (1- n))
  141.              )
  142.              (repeat n
  143.                (setq k (1+ k))
  144.                (if (vlax-curve-getSecondDeriv e k)
  145.                  (setq
  146.                    _pl (append _pl (list (vlax-curve-getPointAtParam e k)))
  147.                  )
  148.                )
  149.              )
  150.             )
  151.       )
  152.       _pl
  153.     )

  154.     (if        (= 'ENAME (type en))
  155.       (setq obj        (vlax-ename->vla-object en)
  156.             ent        en
  157.       )
  158.       (setq obj        en
  159.             ent        (vlax-vla-object->ename en)
  160.       )
  161.     )
  162.     (setq vertexsNum
  163.            (fix (vlax-curve-getEndParam ent))
  164.           n 0
  165.     )
  166.     (setq objName (vla-get-ObjectName obj))
  167.     (cond ((= "AcDbCircle" objName)
  168.            (if (equal fgx 0 1e-6)
  169.              (setq fgx (* pi 0.5))
  170.            )
  171.            (setq vertexsNum
  172.                   (fix (/ (* pi 2) fgx))
  173.                  n 0
  174.            )
  175.            (repeat vertexsNum
  176.              (setq pt (vlax-curve-getPointAtParam obj (* n fgx)))
  177.              (setq plist (cons pt plist)
  178.                    n         (1+ n)
  179.              )
  180.            )
  181.            (reverse plist)
  182.           )
  183.           (t
  184.            (if (= "AcDb2dPolyline" objName)
  185.              (progn
  186.                (repeat vertexsNum
  187.                  (setq pt (vlax-curve-getPointAtParam ent n))
  188.                  (setq plist (cons pt plist))
  189.                  (setq pt (vlax-curve-getPointAtParam ent (+ 0.25 n)))
  190.                  (setq plist (cons pt plist))
  191.                  (setq pt (vlax-curve-getPointAtParam ent (+ 0.5 n)))
  192.                  (setq plist (cons pt plist))
  193.                  (setq pt (vlax-curve-getPointAtParam ent (+ 0.75 n)))
  194.                  (setq plist (cons pt plist))
  195.                  (setq n (1+ n))
  196.                )
  197.                (if (not (vlax-curve-isClosed ent))
  198.                  (setq plist (cons (vlax-curve-getEndPoint ent) plist))
  199.                )
  200.                (reverse plist)
  201.              )
  202.              (if (equal fgx 0 1e-6)
  203.                (setq plist (GXL-GET_POLY_PTLIST en))
  204.                (progn
  205.                  (repeat vertexsNum
  206.                    (if (setq secdev (vlax-curve-getSecondDeriv ent n))
  207.                      (progn
  208.                        (setq pt           (vlax-curve-getPointAtParam ent n)
  209.                              bugle (vla-GetBulge obj n)
  210.                        )
  211.                        (setq plist (cons pt plist))
  212.                        (if (/= bugle 0.0)
  213.                          (progn
  214.                            (setq bj (* (atan (abs bugle)) 4))
  215.                            (setq d1    (vlax-curve-getdistAtParam ent n)
  216.                                  d2    (vlax-curve-getdistAtParam ent (1+ n))
  217.                                  d     (- d2 d1)
  218.                                  k     (fix (/ bj fgx))
  219.                                  d0    (/ 1.0 (1+ k))
  220.                                  param n
  221.                            )
  222.                            (if (equal d0 1.0 0.001)
  223.                              (setq plist (cons (vlax-curve-getPointAtParam
  224.                                                  ent
  225.                                                  (+ 0.5 param)
  226.                                                )
  227.                                                plist
  228.                                          )
  229.                              )
  230.                              (repeat k
  231.                                (setq
  232.                                  plist (cons (vlax-curve-getPointAtParam
  233.                                                ent
  234.                                                (setq param (+ param d0))
  235.                                              )
  236.                                              plist
  237.                                        )
  238.                                )
  239.                              )
  240.                            )
  241.                          )
  242.                        )
  243.                      )
  244.                    )
  245.                    (setq n (1+ n))
  246.                  )
  247.                  (if (not (vlax-curve-isClosed ent))
  248.                    (setq plist (cons (vlax-curve-getEndPoint ent) plist))
  249.                  )
  250.                  (reverse plist)
  251.                )
  252.              )
  253.            )
  254.           )
  255.     )
  256.     plist
  257.   )
  258.   ;;7 对话框上用户选择
  259.   (defun getdata ()
  260.     (setq BaseSymbol (get_tile "Fuhao"))
  261.     (setq JBFD_GetScalStri (get_tile "Scal"))
  262.     (setq JBFD_ZoomStri (get_tile "Zoom1"))
  263.   )
  264.   ;;8 对话框
  265.   (defun FDdcl ()
  266.     (setq fname (vl-filename-mktemp nil nil ".dcl"))
  267.     (setq fn (open fname "w"))
  268.     (write-line "Fddcl : dialog{" fn)
  269.     (write-line "label=\"*黄明儒*局部放大 命令:FD\";" fn)
  270.     (write-line ":column{        " fn)
  271.     (write-line
  272.       "        :edit_box{label=\"放大标识(F)\";key=\"Fuhao\";value=\"B\";mnemonic=\"F\";}"
  273.       fn
  274.     )
  275.     (write-line
  276.       "        :edit_box{label=\"放大倍数(S)\";key=\"Scal\";value=\"2.0\";mnemonic=\"S\";} "
  277.       fn
  278.     )
  279.     (write-line
  280.       "        :edit_box{label=\"视口选择(Z)\";key=\"Zoom1\";value=\"0\";mnemonic=\"Z\";} "
  281.       fn
  282.     )
  283.     (write-line
  284.       "        :text{key=\"Scaltext\";value=\"圆0,已知封闭曲线1,椭圆2,其余多边形\";}"
  285.       fn
  286.     )
  287.     (write-line "       }" fn)
  288.     (write-line "       ok_only;" fn)
  289.     (write-line "}" fn)

  290.     (close fn)
  291.     (setq fn (open fname "r"))
  292.     (setq dclid (load_dialog fname))
  293.     (while
  294.       (or (eq (substr (setq lin        (vl-string-right-trim
  295.                                   "\" fn)"
  296.                                   (vl-string-left-trim "(write-line \"" (read-line fn))
  297.                                 )
  298.                       )
  299.                       1
  300.                       2
  301.               )
  302.               "//"
  303.           )
  304.           (eq (substr lin 1 (vl-string-search " " lin)) "")
  305.           (not (eq (substr lin (+ (vl-string-search " " lin) 1) 9)
  306.                    " : dialog"
  307.                )
  308.           )
  309.       )
  310.     )
  311.     (new_dialog (substr lin 1 (vl-string-search " " lin)) dclid)
  312.     (set_tile "Fuhao" BaseSymbol)
  313.     (set_tile "Scal" JBFD_GetScalStri)
  314.     (set_tile "Zoom1" JBFD_ZoomStri)
  315.     (mode_tile "Scal" 2)
  316.     (Action_Tile "Fuhao" "(Setq BaseSymbol $Value)")
  317.     (Action_Tile "Scal" "(Setq JBFD_GetScalStri $Value)")
  318.     (Action_Tile "Zoom1" "(Setq JBFD_ZoomStri $Value)")
  319.     (action_tile "accept" "(getdata)(done_dialog)")
  320.     (setq return# (start_dialog))
  321.     (unload_dialog dclid)
  322.     (close fn)
  323.     (vl-file-delete fname)
  324.   )

  325.   ;;9 本程序主程序
  326.   (VL-LOAD-COM)
  327.   (setq bli1 (getvar "blipmode"))
  328.   (setq cmd1 (getvar "cmdecho"))
  329.   (setq DIM1 (getvar "DIMASSOC"))
  330.   (setq CLA1 (getvar "CLAYER"))
  331.   (setq osm1 (getvar "osmode"))
  332.   (setvar "blipmode" 0)
  333.   (setvar "cmdecho" 0)
  334.   (setvar "DIMASSOC" 1)
  335.   (setvar "osmode" 0)
  336.   (vl-cmdf "layer" "make" "DIM" "Color" 3 "" "")
  337.   (if (= JBFD_BaseNumber nil)
  338.     (setq JBFD_BaseNumber 65)
  339.     (setq JBFD_BaseNumber (1+ JBFD_BaseNumber))
  340.   )
  341.   (SETQ BaseSymbol (chr JBFD_BaseNumber))
  342.   (if (= JBFD_GetScalStri nil)
  343.     (setq JBFD_GetScalStri "2.5")
  344.   )
  345.   (if (= JBFD_ZoomStri nil)
  346.     (setq JBFD_ZoomStri "0")
  347.   )
  348.   (FDdcl)
  349.   (setq JBFD_BaseNumber (ascii BaseSymbol))
  350.   (SETQ Scalreal (atof JBFD_GetScalStri))
  351.   (SETQ getZoom (abs (atoi JBFD_ZoomStri)))

  352.   (if (/= 1 getZoom)
  353.     (SETQ CP (GETPOINT "\n 局部放大中心点: "))
  354.   )
  355.   (cond        ((= 0 getZoom) (command "_.CIRCLE" CP pause))
  356.         ((= 1 getZoom)
  357.          (while
  358.            (not
  359.              (and
  360.                (setq ent (car (entsel "\n 拾取封闭曲线:")))
  361.                (setq p1 (cdr (assoc 0 (entget ent))))
  362.                (member p1
  363.                        '("SPLINE" "LWPOLYLINE" "POLYLINE" "CIRCLE" "ELLIPSE")
  364.                )
  365.                (if (member p1 '("SPLINE" "LWPOLYLINE" "POLYLINE"))
  366.                  (= (vlax-get-property (vlax-ename->vla-object ent) 'Closed)
  367.                     :vlax-true
  368.                  )
  369.                  T
  370.                )
  371.              )
  372.            )
  373.          )
  374.         )
  375.         ((= 2 getZoom) (command "_.ellipse" CP pause pause))
  376.         (T (command "_.polygon" getZoom CP "_I" pause))
  377.   )
  378.   (SETQ EntCicl (entlast))
  379.   ;;(ayEntSSHighLight EntCicl)
  380.   (if (= 1 getZoom)
  381.     (SETQ EntCicl ent)
  382.   )

  383.   (vla-getboundingbox
  384.     (vlax-ename->vla-object EntCicl)
  385.     'p1
  386.     'p2
  387.   )
  388.   (setq p1 (vlax-safearray->list p1))
  389.   (setq p2 (vlax-safearray->list p2))
  390.   (setq CP (mapcar '(lambda (X) (/ x 2.0)) (mapcar '+ p1 p2))) ;中心点  
  391.   (setq pl (gxl-pL EntCicl 0.017))                  ;取点
  392.   (setq ss (ssget "cp" pl))                          ;选择对象
  393.   (setq newSS (ss=>NewSS SS EntCicl))                  ;原地拷贝
  394.   (setq Newblock (NONAME_BLK newSS CP))                  ;制作成块  
  395.   ;;遮盖
  396.   (command "_.xclip" Newblock "" "n" "p")
  397.   (foreach a pl (command a))
  398.   (command "")
  399.   (while (not (equal (getvar "cmdnames") "")) (command nil))

  400.   (command "_.copy" EntCicl "" (list 0 0 0) (list 0 0 0))
  401.   (setq EntCicl (entlast))

  402.   (SETQ Textheigh (* (GETVAR "DIMTXT") (GETVAR "DIMSCALE"))) ;字度Textheigh
  403.   (HdrawLeader EntCicl BaseSymbol Textheigh CP)          ;画引线
  404.   (setq        NewP (mapcar '+
  405.                      (list 0 (+ (* Scalreal (- (cadr p2) (cadr CP))) Textheigh))
  406.                      CP
  407.              )
  408.   )
  409.   (command "_.text"
  410.            "J"
  411.            "C"
  412.            NewP
  413.            Textheigh
  414.            ""
  415.            (strcat BaseSymbol " 放大 " JBFD_GetScalStri "X")
  416.   )

  417.   (command "_.scale" Newblock EntCicl "" CP Scalreal)
  418.   (command "_.move" Newblock (entlast) EntCicl "" CP pause)

  419.   (setvar "blipmode" bli1)
  420.   (setvar "cmdecho" cmd1)
  421.   (setvar "DIMASSOC" DIM1)
  422.   (setvar "osmode" osm1)
  423.   (gc)
  424.   (princ)
  425. )
  426. ;;*************************************************************************放大主程序

本帖子中包含更多资源

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

x

点评

很不错,  发表于 2015-9-18 16:41

评分

参与人数 1明经币 +3 收起 理由
Gu_xl + 3 赞一个!

查看全部评分

回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2013-7-26 15:11:55 | 显示全部楼层
自贡黄明儒 发表于 2013-7-26 15:06
终于盼来了G版的源码,是各位给图员的福气
响应G版号召,贴出我改编的源码

最好贴出效果图来或动画演示来!

点评

好的  发表于 2013-7-26 15:13
发表于 2013-7-26 16:10:45 | 显示全部楼层
谢谢二位大师分享实用源码。

点评

这个实用!  发表于 2013-10-17 16:31
G版才是大师哈,我只不过用他的改改  发表于 2013-7-26 17:44
发表于 2013-7-26 17:04:17 | 显示全部楼层
两位高手来个优化版的~~~~~~~~~~~~~~~~~~~·
发表于 2013-7-26 17:14:11 | 显示全部楼层
支持G版的好程序
发表于 2013-7-26 18:14:54 | 显示全部楼层
麻烦请问默认放大倍数为1改哪几个地方啊,实在是不懂LSP啊
发表于 2013-7-26 19:56:12 | 显示全部楼层
论坛上有个小笨的局部放大,有对话框,如果有对话框窗体会跟好,
发表于 2013-7-26 20:51:40 | 显示全部楼层
对于标注箭头是块的话,放大后也跟着放大,最好放大后再还原回到原来那样,另外,放大后的块最好是有名块。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-2-21 03:38 , Processed in 0.239727 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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