直线段和多段线。
求教有了多段线的存在,直线段存在的意义为何?就这么简单的问题。
因为简单而存在。 本帖最后由 1291500406 于 2019-3-31 13:50 编辑
直线只能是直线,而多段线可以是直线与曲线,例如弧线的联合体。 直线的线宽是一样的,但是多段线的线宽可以一样,也可以不一样,可以调整开始线宽和末尾线宽使多段线的粗细不一致。 多段线闭合之后可以拉伸建立为三维实体,直线即使闭合也不可以拉伸。直线画出来都是单一的个体多段线一次性画出来的都是一个整体用直线功能不能画出多段线,用直线画出连续的线段后可以组合成多段线,也可以分解功能将多段线分解成单一的直线
多段线转成直线 x命令即可
圆弧转成多段线(defun c:bb(/ bb) (command "pedit" "M" (ssget '((0 . "ARC"))) "" "Y" "")(princ)) x命令却变成了 圆弧
直线转成多段线(defun c:bb (/ b)(setvar "peditaccept"1)(command "pedit" "m"(ssget '((0 . "LINE"))) "" "j""0" "" )(setvar "peditaccept"0)(princ))
椭圆转化为样条曲线(defun C:bb(/ E E1 E2 O)(setq E (car (entsel "\n必强提示选择椭圆转化为样条曲线: ")))(setq O (vlax-ename->vla-object E))(vla-offset O 0.1)
(setq E1 (entlast))(vla-offset (vlax-ename->vla-object E1) -0.1)(setq E2 (entlast))(entdel E)(entdel E1)(princ))
;;;椭圆转化为多段线
(defun c:bb (/ ss n)(setq n 0)(if (setq ss (ssget '((0 . "ELLIPSE"))))(progn(command "_.undo" "_begin")(repeat (sslength ss)(ellipse->polyline (ssname ss n))(setq n (1+ n)))(command "_.undo" "_end")))(princ (strcat "\n\t" (itoa n) " ellipse(s) convertie(s) en polyligne(s)."))(princ))
;;;绘制多段线椭圆
(defun c:bb (/ *error* ec pe old ent)
(defun *error* (msg)(if (= msg "Fonction annulée")(princ)(princ (strcat "\nErreur: " msg)))(setvar "cmdecho" ec)(setvar "pellipse" pe)(princ))(setq ec(getvar "cmdecho")pe(getvar "pellipse")old (entlast))(setvar "cmdecho" 1)(setvar "pellipse" 0)(command "_.ellipse")(while (/= 0 (getvar "cmdactive"))(command pause))(if (not (eq old (setq ent (entlast))))(ellipse->polyline ent))(setvar "cmdecho" ec)(setvar "pellipse" pe)(princ))
(defun ellipse->polyline (ent / elst ucs os ec pe cen ext pa1 pa2 grd prd ang pt1 pt2 mat line ed)(setq elst (entget ent))(or(equal (trans '(0 0 1) 1 0 T) (cdr (assoc 210 elst)) 1e-9)(and(setq ucs T)
(command "_.ucs" "_zaxis" '(0 0 0) (trans (cdr (assoc 210 elst)) ent 1 T))))(setq ec (getvar "cmdecho") pe (getvar "pellipse")elst (entget ent) cen(cdr (assoc 10 elst))elv(caddr (trans cen 0 (cdr (assoc 210 elst)))) ext(trans (mapcar '+ cen (cdr (assoc 11 elst))) 0 1) cen(trans cen 0 1)pa1(cdr (assoc 41 elst)) pa2(cdr (assoc 42 elst)) grd(distance cen ext) prd(* grd (cdr (assoc 40 elst))) ang(angle cen ext))(entdel ent)(setvar "cmdecho" 0)(setvar "pellipse" 1)(command "_.ellipse" "_c" "_non" cen "_non" (polar cen ang grd) prd)(if (or (/= pa1 0.0) (/= pa2 (* 2 pi)))(progn (setq ent (entlast)pt1 (list (* grd (cos pa1)) (* prd (sin pa1))) pt2 (list (* grd (cos pa2)) (* prd (sin pa2))) mat (list (list (cos ang) (- (sin ang)) 0) (list (sin ang) (cos ang) 0)'(0 0 1)) pt1 (mapcar '+ cen (mxv mat pt1)) pt2 (mapcar '+ cen (mxv mat pt2)))
(command "_.line" "_non" pt1 "_non" pt2 "") (setq line (entlast))(cond ((equal ext pt2 1e-9)(command "_.break" ent "_non" pt1 "_non" pt1)(entdel (entnext line))) ((equal ext pt1 1e-9) (command "_.break" ent "_non" pt2 "_non" pt2)(entdel (entlast))) ((< (atof (angtos pa2)) (atof (angtos pa1)))(setq ed (getvar "EDGEMODE")) (setvar "EDGEMODE" 1)(command "_.trim" line "" (polar cen (+ ang pi) grd) "")(setvar "EDGEMODE" ed)(command "_.pedit" (entlast) "_j" (entnext line) "" ""))(T(setq ed (getvar "EDGEMODE"))(setvar "EDGEMODE" 1)(command "_.trim" line "" ext "")(setvar "EDGEMODE" ed)))(entdel line)))(command "_.convert" "_p" "_s" (entlast) "")(and ucs (command "_.ucs" "_previous"))(setvar "cmdecho" ec)(setvar "pellipse" pe))
(defun mxv (m v)(mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)) x命令也变成 了圆弧
;;;圆转化为多段线
(defun gps->Circle-2plinelst (pt r n / ang nang pt1 ptlst)(setq nang (/ (* 2 pi) n) ang 0)(repeat n(setq pt1 (polar pt ang r))(setq ang (+ angnang))(setq ptlst (append ptlst (list pt1)))))
(defun gps->entmake-pline(pt_lst lay clsd)(entmakex (append(list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")(cons 8 lay)(cons 90 (length pt_lst))(cons 70 clsd))
(mapcar '(lambda (pt) (cons 10 pt)) pt_lst))))
(defun gps->ss-2lst (ss / lst n)(if (= (type ss) 'PICKSET)(repeat (setq n (sslength ss))(setq lst (cons (ssname ss (setq n (1- n))) lst))))lst)
(defun c:bb(if (null $fs)(setq $fs 10)) (setq tmp 360) (if tmp (setq $fs tmp))(foreach n (gps->ss-2lst (ssget '((0 . "Circle"))))
(setq ptlst (entget n) lay (cdr (assoc 8 ptlst))pt (cdr (assoc 10 ptlst)) r (cdr (assoc 40 ptlst)))(gps->entmake-pline (gps->Circle-2plinelst pt r $fs) lay 1)(entdel n))(princ))
;;;将所有图元转化为直线
(defun c:bb(/ dist dist_pd i leng name name_line name_next osmode p2 p2_over p3 p3_over pp_cen pp_lst pp_lst_all pp_lst_over ss x_big x_sort y_big y_sort)
(setvar "mirrtext" 1)(setvar "cmdecho" 0)(setq osmode (getvar "osmode"))(setq ss (ssget))(SETQ LENG (sslength ss))(setq i -1 pp_lst_all '())(repeat leng (setq i (1+ i))
(setq name (ssname ss i))(setq pp_lst (by-get-insert-box name))(setq pp_lst_all (append pp_lst_all pp_lst)))(setq x_sort (car(car(vl-sort pp_lst_all (function(lambda(e1 e2)(< (car e1)(car e2))))))))
(setq x_big (car(car(vl-sort pp_lst_all (function(lambda(e1 e2)(> (car e1)(car e2))))))))(setq y_sort (cadr(car(vl-sort pp_lst_all (function(lambda(e1 e2)(< (cadr e1)(cadr e2))))))))
(setq y_big (cadr(car(vl-sort pp_lst_all (function(lambda(e1 e2)(> (cadr e1)(cadr e2))))))))(setq p3(list x_sort y_sort))(setq p2(list x_big y_big))(command "_.zoom" "w" p2 p3)(setq dist (distance p2 p3))
(setq pp_cen (polar p2 (angle p2 p3) (/ (distance p2 p3) 2.0)))(setq name_line (entmakex (list '(0 . "LINE")'(100 . "AcDbEntity")'(62 . 250)'(100 . "AcDbLine") (cons 10 p3) (cons 11 p2) '(210 0.0 0.0 1.0))))
(ssadd name_line ss)(setvar "osmode" 0)(command "_.mirror" ss "" pp_cen (list (+ (car pp_cen) 100) (cadr pp_cen)) "y")(command "_.wmfout" "d://bbx.wmf" ss "")(command "_.erase" ss "")
(command "_.wmfin" "d:/bbx"'(0 0 0) "1" "1" "0")(command "_.mirror" (entlast) "" '(0 0 0) '(100 0 0) "y")(setq pp_lst_over (by-get-insert-box (entlast)))(setq p2_over (nth 1 pp_lst_over))
(setq p3_over (nth 2 pp_lst_over))(setq dist_pd (distance p2_over p3_over))(command "_.scale" (entlast) "" p2_over (/ dist dist_pd))(command "_.move" (entlast) "" p2_over p2)
(setq name_next (entlast))(command "_.explode" (entlast) "")(entdel (entlast))(command "_.zoom" "p")(setvar "mirrtext" 0)(setvar "cmdecho" 1)(setvar "osmode" osmode)(princ))
(defun by-get-insert-box(name / *bbacad* ang dist midpt objname p1 p2 p3 p4 pp_max pp_min pt1 pt2)(setq objname (vlax-ename->vla-object name))(setq *bbacad*(vlax-get-acad-object))
(vla-GetBoundingBox objname 'pp_min 'pp_max)(setq p3 (vlax-safearray->list pp_min)p2 (vlax-safearray->list pp_max)p1 (list (car p3) (cadr p2))p4 (list (car p2) (cadr p3)))(list p1 p2 p3 p4))
本帖最后由 cheefeel 于 2019-3-31 18:19 编辑
1291500406 发表于 2019-3-31 10:49
直线只能是直线,而多段线可以是直线与曲线,例如弧线的联合体。 直线的线宽是一样的,但是多段线的线宽 ...
非常感谢详细的介绍,一些超级实用的工具代码。补充一些CAD自带的系统变量:
★4 控制所绘制椭圆类型 真正椭圆 或圆弧拟合
PELLIPSE
★5 控制多段线拟合类型 连接的多段线 或 连接的圆弧
PLINECONVERTMODE
此拟合类型远比不上ET工具的FLATTEN将样条曲线转换为连接的圆弧,自行测试体会。所以这个系统变量也没啥用!
页:
[1]