明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5127|回复: 16

[已解答] PL直线偏移联动,圆角的值不变,如何实现?

  [复制链接]
发表于 2014-5-12 10:11 | 显示全部楼层 |阅读模式
本帖最后由 chang1622 于 2014-5-12 10:14 编辑

PL直线偏移联动,圆角的值不变,如何实现?

简单说就是可以偏移其中任何一条直线,但圆角是固定的,能实现吗?

本帖子中包含更多资源

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

x
发表于 2014-5-13 10:12 | 显示全部楼层
凸度不变,改变两个点 ,比黄总那个要求弧长的好弄点,我的方法比较取巧。
  1. ;;;LWPOLYLINE线单边移动函数
  2. ;;;by edata @mjtd
  3. ;;;2014-5-13
  4. (defun sk_offset_single(/ ANG1 ANG2 CPT ENT ENT1 INDEXMAX INDEXMAX1+ INDEXMAX2 INDEXMIN INDEXMIN1 INDEXMIN1- IPT1 IPT1_A IPT1_B
  5.             IPT2 IPT2_A IPT2_B IS_CLOSED NEW1 NEW2 NEW3 NEW4 OBJ  OF_DIST1 P0 P1 P11 P11BULGE P11MIN- P2 P21
  6.             P21BULGE P21MAX+ PPX PX SK_COORDS VB_NEW1 VB_NEW2 VB_NEW3 VB_NEW4)
  7.   ;;;组码值提取(sk_dxf 图元名 组码)
  8. (defun sk_dxf(en code)
  9.     (if(and(=(type en) 'ENAME)(= (type code) 'INT))
  10.       (cdr(assoc code (entget en))))
  11.   )
  12. ;;;计算cp到p1 p2的垂足点
  13. (defun PerToLine  (cp p1 p2 / norm)
  14.   (setq        norm (mapcar '- p2 p1)
  15.         p1   (trans p1 0 norm)
  16.         cp   (trans cp 0 norm)
  17.         )
  18.   (trans (list (car p1) (cadr p1) (caddr cp)) norm 0)
  19.   )
  20.   (defun *error*_New (msg)
  21.   (and *error*_Old(setq *error* *error*_Old))
  22.   (if (wcmatch (strcase msg t) "*break,*cancel*,*exit*,*取消*")
  23.     (if        (= (getvar "LOCALE") "CHS")
  24.       (princ "\n用户按了<Esc>强制退出")
  25.       (princ "\nYou cancelled The operation!")
  26.     )
  27.     (princ (strcat "\n" msg))
  28.   )
  29.   (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  30.   (setvar "cmdecho" 0)
  31.   (command "undo" "e")
  32.   (setvar "cmdecho" 1)
  33.   (princ)
  34. )
  35.   (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  36.   (setq *error*_Old *error*)                ;保存出错处理函数
  37.   (setq *error* *error*_New)
  38.   ;;;;;主程序
  39.   (vl-load-com)
  40.   (if(setq of_dist1(getdist (strcat "\n输入偏移距离["(if of_dist (rtos of_dist) "0")"]:")))(setq of_dist of_dist1))
  41.   (while(and of_dist (/= of_dist 0)
  42.           (and(setq ent1(entsel "\n选择线:"))(or (= (sk_dxf (car ent1) 0 ) "LWPOLYLINE")(= (sk_dxf (car ent1) 0 ) "LINE")))
  43.           (car (list t(redraw (car ent1) 3)))
  44.     (setq p0(getpoint "\n指定偏移方向:")))
  45.     (if(= (sk_dxf (car ent1) 0 ) "LWPOLYLINE")
  46.     (progn
  47.       (setq ent(car ent1)
  48.             px(cadr ent1)
  49.             obj(vlax-ename->vla-object (car ent1)))
  50.       (setq is_closed (sk_dxf ent 70)
  51.             sk_Coords (sk_dxf ent 90))      
  52.       (setq ppx(vlax-curve-getClosestPointTo obj px)
  53.             indexmin1(fix (vlax-curve-getParamAtPoint obj ppx))
  54.             indexmax2(1+ indexmin1)
  55.             indexmin(min indexmin1 indexmax2)
  56.             indexmax(max indexmin1 indexmax2)
  57.             )
  58.       
  59.       (if(and (= indexmin (1- sk_Coords))(= indexmax sk_Coords))
  60.         (setq indexmin1- (1- indexmin )             
  61.               indexmax 0             
  62.               indexmax1+ 1)
  63.         (if (and (= indexmin 0)(/= indexmax (1- sk_Coords)))
  64.           (setq indexmin1- (1- sk_Coords)
  65.                 indexmax1+ (1+ indexmax ))
  66.           (if (= indexmax (1- sk_Coords))
  67.             (setq indexmax1+  0 indexmin1- (1- indexmin))
  68.             (setq indexmin1- (1- indexmin)
  69.                   indexmax1+ (1+ indexmax )))))
  70.       (setq p1(vlax-safearray->list(vlax-variant-value(vla-get-Coordinate obj indexmin)))
  71.             p2(vlax-safearray->list(vlax-variant-value(vla-get-Coordinate obj indexmax)))
  72.             p11(vlax-safearray->list(vlax-variant-value(vla-get-Coordinate obj indexmin1-)))
  73.             p21(vlax-safearray->list(vlax-variant-value(vla-get-Coordinate obj indexmax1+)))
  74.             p11bulge(vla-getbulge obj indexmin1-)
  75.             p21bulge(vla-getbulge obj indexmax))
  76.       (if(not(equal p21bulge 0.0 1e-8))(setq p21max+(vlax-safearray->list(vlax-variant-value(vla-get-Coordinate obj (1+ indexmax1+))))))
  77.       (if(not(equal p11bulge 0.0 1e-8))
  78.         (progn          
  79.         (setq p11min-(vlax-safearray->list(vlax-variant-value(vla-get-Coordinate obj (if (zerop indexmin1-) (1- sk_Coords)(1- indexmin1-))))))       
  80.         )
  81.         )      
  82.       (setq cpt (PerToLine p0 p1 p2)
  83.             ang1(angle cpt p0)
  84.             ang2(angle p1 p2)
  85.             new1(polar p1 ang1 of_dist)
  86.             new2(polar p2 ang1 of_dist)
  87.             ipt1(inters new1 new2 p1 p11 nil)
  88.             ipt2(inters new1 new2 p2 p21 nil)   
  89.             )
  90.       (if(and (= is_closed 0) (= indexmin 0) )
  91.         (setq ipt1 new1))
  92.       (if(and (= is_closed 0) (= indexmax (1- sk_Coords)) )
  93.         (setq ipt2 new2))      
  94.       (if p11min- (setq ipt1_a(inters p1 p2 p11 p11min- nil)
  95.                         ipt1_b(inters new1 new2 p11 p11min- nil)
  96.                         ipt1(polar ipt1_b (angle p1 p2)(distance ipt1_a p1))
  97.                         new3(polar ipt1_b (angle p11 p11min-)(distance ipt1_a p11))                       
  98.                         vb_new3(vlax-safearray-fill(vlax-make-safearray vlax-vbdouble '(0 . 1)) (list(car new3)(cadr new3)))))
  99.       (if p21max+ (setq ipt2_a(inters p1 p2 p21 p21max+ nil)
  100.                         ipt2_b(inters new1 new2 p21 p21max+ nil)
  101.                         ipt2(polar ipt2_b (angle p2 p1)(distance ipt2_a p2))
  102.                         new4(polar ipt2_b (angle p21 p21max+)(distance ipt2_a p21))                       
  103.                         vb_new4(vlax-safearray-fill(vlax-make-safearray vlax-vbdouble '(0 . 1)) (list(car new4)(cadr new4)))))
  104.       (setq vb_new1(vlax-safearray-fill(vlax-make-safearray vlax-vbdouble '(0 . 1)) (list(car ipt1)(cadr ipt1)))            
  105.             vb_new2(vlax-safearray-fill(vlax-make-safearray vlax-vbdouble '(0 . 1)) (list(car ipt2)(cadr ipt2)))
  106.             )
  107.       (if vb_new3 (progn
  108.                     (vla-put-Coordinate obj indexmin1- vb_new3)
  109.                     (vla-put-Coordinate obj indexmin  vb_new1))
  110.         (vla-put-Coordinate obj indexmin  vb_new1)
  111.         )
  112.       (if vb_new4 (progn
  113.                     (vla-put-Coordinate obj indexmax1+ vb_new4)
  114.                     (vla-put-Coordinate obj indexmax  vb_new2))
  115.         (vla-put-Coordinate obj indexmax  vb_new2)
  116.         )
  117.       (progn
  118.         (setq p11min- nil
  119.               p21max+ nil
  120.               vb_new1 nil
  121.               vb_new2 nil
  122.               vb_new3 nil
  123.               vb_new4 nil
  124.         ))
  125.       (vla-update obj)
  126.       )     
  127.       )   
  128.     )
  129. (if ent1 (redraw (car ent1) 4))
  130.   (and *error*_Old(setq *error* *error*_Old))
  131.   (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  132.   (princ)
  133.   )
  134. (defun c:tt nil
  135.   (sk_offset_single)
  136.   (princ)
  137.   )
  138. (prompt "轻多段线(LWPOLYLINE)单边边偏移命令 TT")
  139. (princ)

评分

参与人数 4明经币 +4 金钱 +60 收起 理由
chang1622 + 1 + 10 很给力!
zctao1966 + 1 很给力!
ll_j + 1 + 50 我也先留一个
lucas_3333 + 1 谢谢E大的无私贡献

查看全部评分

回复 支持 1 反对 0

使用道具 举报

发表于 2020-3-25 08:35 | 显示全部楼层
edata 发表于 2014-5-13 10:12
凸度不变,改变两个点 ,比黄总那个要求弧长的好弄点,我的方法比较取巧。

E大这个源码能做到全部偏移圆角不变吗?图中的是单向偏移
发表于 2020-3-25 09:44 | 显示全部楼层
ga619091 发表于 2020-3-25 08:35
E大这个源码能做到全部偏移圆角不变吗?图中的是单向偏移

这个是单根线偏移,如果你是直接偏移,代码应该比这个还简单...
发表于 2014-5-12 18:34 | 显示全部楼层

本帖子中包含更多资源

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

x
发表于 2014-5-12 20:50 | 显示全部楼层
edata 发表于 2014-5-12 18:34

E大威武,支持!
发表于 2014-5-12 22:48 | 显示全部楼层
请教ED,支持!
 楼主| 发表于 2014-5-13 08:44 | 显示全部楼层
E大辛苦了!正需要这效果,能提供程序吗?
发表于 2014-5-13 08:47 | 显示全部楼层
多段线好整,偏移后修改凸度就行了。
发表于 2014-5-13 09:03 | 显示全部楼层
本帖最后由 llsheng_73 于 2014-5-13 09:46 编辑
自贡黄明儒 发表于 2014-5-13 08:47
多段线好整,偏移后修改凸度就行了。

好象楼主这个需要修改的是端点而凸度要保持不变?
并且它是偏移指定边出去,意思得根据整体偏移后的对应边来修改原来的点取边,把偏移出去的删除掉来达到目的?

不然就得计算被指定边偏移后的结果来修改原来的线,人个习惯用这一种办法
但是始终有个问题,有可能偏移后有的顶点将不存在

发表于 2014-5-13 10:33 | 显示全部楼层
厉害!厉害!厉害!厉害!
 楼主| 发表于 2014-5-13 11:29 | 显示全部楼层
非常感谢edata无私奉献!厉害!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-14 01:24 , Processed in 0.177740 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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