明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1357|回复: 0

[源码] 求帮助修改一个框选剪切程序

[复制链接]
发表于 2013-7-3 16:48:55 | 显示全部楼层 |阅读模式
有时候线段两边不齐,一般都是做辅助线剪切点,我的想法是直接画矩形修剪掉,好不容易“拼”好了程序,从左往右剪切没有问题,但从右往左不行,容易留下一个尾巴,求完善!谢谢高手
  1. ;========== angle stuff ==============
  2. ;  Convert angle in degrees to radians
  3. (defun dtr (a) (* pi (/ a 180.0)))

  4. ; Convert value in radians to degrees
  5. (defun RTD (r)   (* 180.0 (/ r pi)))
  6. ;============================
  7. ;  MAIN ROUTINE
  8. ;============================
  9. (defun C:CLIP ( / sblip scmde
  10.       @pt1 @pt2 @pt3 @pt4 xpt1 xpt2 fp1 fp2 fp3 fp4
  11.       en ans anshelp ang sblip scmde en en1
  12.       ansclip screen ang os cclip inspoint grpcnt)
  13. ;setup
  14.   (setq sblip (getvar "blipmode"))
  15.   (setq scmde (getvar "cmdecho"))
  16.   (setvar "blipmode" 0)(princ)
  17.   (setvar "cmdecho" 0)(princ)
  18.   (command "_.osnap" "off")
  19.       (if (= grpcnt nil)(setq grpcnt 0) )
  20. ;get points
  21.   (prompt "Enter ")
  22.   (setq @pt1 (getpoint "1st Point :"))

  23.   (setq @pt2 (getcorner @pt1 "\n2nd Point :"))
  24. ;Break List of points in x y parts
  25.   (setq xpt1 (car @pt1) ypt1 (cadr @pt1))
  26.   (setq xpt2 (car @pt2) ypt2 (cadr @pt2))
  27. ;Set Trim/Fence Points inside Pline Boundary
  28.        (if (= xpt1 xpt2)(quit))
  29. ;=============================================================
  30. ;;Set PTS if lower left picked first
  31.        (cond ((and (< xpt1 xpt2)(< ypt1 ypt2))
  32.          (progn
  33.     (setq fp1 (list (+ xpt1 0.03125)(+ ypt1 0.03125)))
  34.     (setq fp2 (list (- xpt2 0.03125)(+ ypt1 0.03125)))
  35.     (setq fp3 (list (- xpt2 0.03125)(- ypt2 0.03125)))
  36.     (setq fp4 (list (+ xpt1 0.03125)(- ypt2 0.03125)))
  37. ;;;;;Set Points to draw PLINE or RECTANGLE Boundary
  38.     (setq @pt2 (list xpt2 ypt1))
  39.     (setq @pt3 (list xpt2 ypt2))
  40.     (setq @pt4 (list xpt1 ypt2))
  41. ;;;;;Set OFFSET ANGLE
  42.   (setq ang (dtr (angle @pt1 @pt3) ) )
  43.    );end progn
  44.        ));end cond1
  45. ;=============================================================
  46. ;;Set PTS if Upper left picked first
  47.        (cond ((and (< xpt1 xpt2)(> ypt1 ypt2))
  48.    (progn
  49.     (setq fp1 (list (+ xpt1 0.03125)(- ypt1 0.03125)))
  50.     (setq fp2 (list (+ xpt1 0.03125)(+ ypt2 0.03125)))
  51.     (setq fp3 (list (- xpt2 0.03125)(+ ypt2 0.03125)))
  52.     (setq fp4 (list (- xpt2 0.03125)(- ypt1 0.03125)))
  53. ;;;;;Set Points to draw PLINE or RECTANGLE Boundary
  54.     (setq @pt2 (list xpt2 ypt1))
  55.     (setq @pt3 (list xpt2 ypt2))
  56.     (setq @pt4 (list xpt1 ypt2))
  57. ;;;;;Set OFFSET ANGLE
  58.     (setq ang (dtr (* -1 (angle @pt1 @pt3) ) ) )
  59.    );end progn
  60.        ));end cond2
  61. ;=============================================================
  62. ;;Set PTS if Lower Right picked first
  63.        (cond ((and (> xpt1 xpt2)(< ypt1 ypt2))
  64.    (progn
  65.     (setq fp1 (list (- xpt1 0.03125)(+ ypt1 0.03125)))
  66.     (setq fp2 (list (- xpt1 0.03125)(- ypt2 0.03125)))
  67.     (setq fp3 (list (+ xpt2 0.03125)(- ypt2 0.03125)))
  68.     (setq fp4 (list (+ xpt2 0.03125)(+ ypt1 0.03125)))
  69. ;;;;;Set Points to draw PLINE or RECTANGLE Boundary
  70.     (setq @pt2 (list xpt2 ypt1))
  71.     (setq @pt3 (list xpt2 ypt2))
  72.     (setq @pt4 (list xpt1 ypt2))
  73. ;;;;;Set OFFSET ANGLE
  74.   (setq ang (dtr (angle @pt1 @pt3) ) )
  75.    );end progn
  76.        ));end cond3
  77. ;=============================================================
  78. ;;Set PTS if Upper Right picked first
  79.        (cond ((and (> xpt1 xpt2)(> ypt1 ypt2))
  80.    (progn
  81.     (setq fp1 (list (- xpt1 0.03125)(- ypt1 0.03125)))
  82.     (setq fp2 (list (- xpt2 0.03125)(- ypt1 0.03125)))
  83.     (setq fp3 (list (- xpt2 0.03125)(+ ypt2 0.03125)))
  84.     (setq fp4 (list (- xpt1 0.03125)(+ ypt2 0.03125)))
  85. ;;;;;Set Points to draw PLINE or RECTANGLE Boundary
  86.     (setq @pt2 (list xpt2 ypt1))
  87.     (setq @pt3 (list xpt2 ypt2))
  88.     (setq @pt4 (list xpt1 ypt2))
  89. ;;;;;Set OFFSET ANGLE
  90.   (setq ang (dtr (angle @pt1 @pt3) ) )
  91.    );end progn
  92.        ));end cond4
  93. ;=============================================================
  94. ;Draw Trim to Boundary
  95.   (command "_.rectang" @pt1 @pt3)
  96. ;Get PLINE/REC OUTSIDE Boundary to delete later
  97.   (setq en (entlast))
  98.   (command "offset" 1 en (polar '(0.0 0.0) ANG 0.001)"")
  99. ;Get PLINE/REC INSIDE Boundary to delete later
  100.   (setq en1 (entlast))
  101. ;Use TRIM with FENCE to BREAK geometry - repeat 4 times
  102.    (repeat 4
  103.   (command "_.trim" "" "F" fp3 fp4 ""
  104.            "F" fp2 fp3 ""
  105.            "F" fp1 fp2 ""
  106.            "F" fp1 fp4 "" "")
  107.    );end repeat
  108. (command "_.erase" en1 "")
  109. (command "_.erase" en "")
  110. ;==============================================================

  111. ;==============================================================
  112. ;Set UCS to WORLD
  113.   (command "_.ucs" "W")
  114.   (setvar "blipmode" sblip)(princ)
  115.   (setvar "cmdecho" scmde)(princ)
  116. (terpri)
  117. (terpri)
  118. (terpri)
  119.   (PRINC "\nCLIP")(princ)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-28 11:31 , Processed in 0.171948 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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