Chuyển đến nội dung
Diễn đàn CADViet
hatrongquan88

Nhờ chỉnh sửa lisp

Các bài được khuyến nghị

Mình có sưu tầm được trên diễn đàn lisp dim pl cạnh xiên DimPolySeq (Dim PL canh xien).lsp khi chạy lisp thì lisp hiện số thứ đoạn dim 

 

11.PNG.ee9e7d6753103728cc57d3b846a084b3.PNG

 

Nhờ các bạn sửa lại giúp mình lược bỏ bớt phần hiển thị số đoạn trước chiều dài đoạn dim, để dim chỉ hiển thị chiều dài dim. Rất mong các bạn giúp đỡ, mình xin cảm ơn.

 

 

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Sửa một cách nhanh nhất đây. Dư hay thừa gì  trong code thì kệ, kết quả như ý bạn là được.

;;  DimPolySeq.lsp [command names: DPI, DPO]
;;  To dimension the lengths of all segments of a Polyline on the Inboard or Outboard
;;    side, adding a sequencing number and colon as prefix.  For self-intersecting or open
;;    Polyline without a clear "inside" and "outside," will determine a side -- if not as
;;    desired, undo and run other command.
;;  Dimensions along arc segments will be angular Dimensions, showing length of arc
;;    as text override, not included angle native to angular Dimensions.  They will not
;;    update if Polyline is stretched, as Dimensions along line segments will.
;;  Uses current Dimension and Units settings; dimension line location distance from
;;    Polyline segment = 1.5 x dimension text height for stacked fractions to clear [but
;;    see suggestion below if you don't use stacked fractions].
;;  Sequencing number + colon & space are in text override; number is stored in non-
;;    localized variable *DPseq.  Remembers that, and continues sequence on subsequent
;;    usage within same editing session of same drawing, whether using all DPI or all
;;    DPO or a mixture of the two commands.
;;  Accepts LW and 2D "heavy" Polylines, but not 3D Polylines or meshes.
;;  Kent Cooper, 29 August 2016

(vl-load-com)

(defun DP (side / *error* clay cmde styht plsel pl cw inc pt1 pt2 pt3 pt4)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar 'clayer clay)
    (setvar 'osmode osm)
    (command-s "_.undo" "_end")
    (setvar 'cmdecho cmde)
    (princ)
  ); defun -- *error*

  (setq clay (getvar 'clayer) osm (getvar 'osmode) cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)
  (if (not *DPseq) (setq *DPseq 1))
  (command
    "_.undo" "_begin"
    "_.layer" "_make" "A-ANNO-DIMS" "_color" 2 "" "" ;; <---EDIT if desired
  ); command
  (setq styht (cdr (assoc 40 (tblsearch "style" (getvar 'dimtxsty))))); height of text style in current dimension style
  (if (= styht 0.0) (setq styht (* (getvar 'dimtxt) (getvar 'dimscale)))); if above is non-fixed-height
  (while
    (not
      (and
        (setq plsel (entsel "\nSelect Polyline: "))
        (wcmatch (cdr (assoc 0 (entget (car plsel)))) "*POLYLINE")
        (= (logand (cdr (assoc 70 (entget (car plsel)))) 88) 0)
          ;; not 3D or mesh [88 = 8 (3D) + 16 (polygon mesh) + 64 (polyface mesh)]
      ); and
    ); not
    (prompt "\nNothing selected, or not a LW or 2D Polyline.")
  ); while
  (setq pl (vlax-ename->vla-object (car plsel)))
  (vla-offset pl styht); temporary
  (setq cw (< (vla-get-area (vlax-ename->vla-object (entlast))) (vla-get-area pl)))
    ;; clockwise for closed or clearly inside/outside open; may not give
    ;; desired result for open without obvious inside/outside
  (entdel (entlast))
  (repeat (setq inc (fix (vlax-curve-getEndParam pl)))
    (setq
      pt1 (vlax-curve-getPointAtParam pl inc)
      pt2 (vlax-curve-getPointAtParam pl (- inc 0.5)); segment midpoint
      pt3 (vlax-curve-getPointAtParam pl (1- inc))
    ); setq
    (if (equal (angle pt1 pt2) (angle pt2 pt3) 1e-8); line segment
      (command ; then
        "_.dimaligned" pt1 pt3
        "_text" "<>"
      ); [leaves at dimension line location prompt]
      (command ; else [arc segment]
        "_.dimangular" ""
        (inters ; arc center
          (setq pt4 (mapcar '/ (mapcar '+ pt1 pt2) '(2 2 2)))
          (polar pt4 (+ (angle pt1 pt2) (/ pi 2)) 1)
          (setq pt4 (mapcar '/ (mapcar '+ pt2 pt3) '(2 2 2)))
          (polar pt4 (+ (angle pt2 pt3) (/ pi 2)) 1)
          nil
        ); inters
        pt1 pt3
        "_text"
          (strcat
            (itoa *DPseq) ": "
            (rtos (abs (- (vlax-curve-getDistAtParam pl inc) (vlax-curve-getDistAtParam pl (1- inc)))) 2 0)
            "mm"
            ;; [edit mode and precision and suffix as desired -- this is per request on AutoCAD Forum]
          ); strcat
      ); command [leaves at dimension line location prompt]
    ); if
    (command ; complete Dimension: dimension line location
      (polar
        pt2
        (apply
          (if (or (and cw (= side "in")) (and (not cw) (= side "out"))) '- '+)
          (list
            (angle '(0 0 0) (vlax-curve-getFirstDeriv pl (- inc 0.5)))
            (/ pi 2)
          ); list
        ); apply
        (* styht 1.5)
          ;; [If you don't use stacked fractions, consider using styht without multiplier]
      ); polar
    ); command
    (setq
      inc (1- inc)
      *DPseq (1+ *DPseq)
    ); setq
  ); repeat
  (setvar 'clayer clay)
  (setvar 'osmode osm)
  (command "_.undo" "_end")
  (setvar 'cmdecho cmde)
  (princ)
); defun -- C:DP

(defun C:DPI () (DP "in")); = Dimension Polyline Inside
(defun C:DPO () (DP "out")); = Dimension Polyline Outside

(prompt "\nType DPI to Dimension a Polyline on the Inside, DPO to do so on the Outside.")

 

  • Like 1

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác
2 giờ trước, duy782006 đã nói:

Sửa một cách nhanh nhất đây. Dư hay thừa gì  trong code thì kệ, kết quả như ý bạn là được.


;;  DimPolySeq.lsp [command names: DPI, DPO]
;  To dimension the lengths of all segments of a Polyline on the Inboard or Outboard
;    side, adding a sequencing number and colon as prefix.  For self-intersecting or open
;    Polyline without a clear "inside" and "outside," will determine a side -- if not as
;    desired, undo and run other command.
;  Dimensions along arc segments will be angular Dimensions, showing length of arc
;    as text override, not included angle native to angular Dimensions.  They will not
;    update if Polyline is stretched, as Dimensions along line segments will.
;  Uses current Dimension and Units settings; dimension line location distance from
;    Polyline segment = 1.5 x dimension text height for stacked fractions to clear [but
;    see suggestion below if you don't use stacked fractions].
;  Sequencing number + colon & space are in text override; number is stored in non-
;    localized variable *DPseq.  Remembers that, and continues sequence on subsequent
;    usage within same editing session of same drawing, whether using all DPI or all
;    DPO or a mixture of the two commands.
;  Accepts LW and 2D "heavy" Polylines, but not 3D Polylines or meshes.
;  Kent Cooper, 29 August 2016

(vl-load-com)

(defun DP (side / *error* clay cmde styht plsel pl cw inc pt1 pt2 pt3 pt4)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg))
    ); if
    (setvar 'clayer clay)
    (setvar 'osmode osm)
    (command-s "_.undo" "_end")
    (setvar 'cmdecho cmde)
    (princ)
  ); defun -- *error*

  (setq clay (getvar 'clayer) osm (getvar 'osmode) cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setvar 'osmode 0)
  (if (not *DPseq) (setq *DPseq 1))
  (command
    "_.undo" "_begin"
    "_.layer" "_make" "A-ANNO-DIMS" "_color" 2 "" "" ;; <---EDIT if desired
  ); command
  (setq styht (cdr (assoc 40 (tblsearch "style" (getvar 'dimtxsty))))); height of text style in current dimension style
  (if (= styht 0.0) (setq styht (* (getvar 'dimtxt) (getvar 'dimscale)))); if above is non-fixed-height
  (while
    (not
      (and
        (setq plsel (entsel "\nSelect Polyline: "))
        (wcmatch (cdr (assoc 0 (entget (car plsel)))) "*POLYLINE")
        (= (logand (cdr (assoc 70 (entget (car plsel)))) 88) 0)
          ;; not 3D or mesh [88 = 8 (3D) + 16 (polygon mesh) + 64 (polyface mesh)]
      ); and
    ); not
    (prompt "\nNothing selected, or not a LW or 2D Polyline.")
  ); while
  (setq pl (vlax-ename->vla-object (car plsel)))
  (vla-offset pl styht); temporary
  (setq cw (< (vla-get-area (vlax-ename->vla-object (entlast))) (vla-get-area pl)))
    ;; clockwise for closed or clearly inside/outside open; may not give
    ;; desired result for open without obvious inside/outside
  (entdel (entlast))
  (repeat (setq inc (fix (vlax-curve-getEndParam pl)))
    (setq
      pt1 (vlax-curve-getPointAtParam pl inc)
      pt2 (vlax-curve-getPointAtParam pl (- inc 0.5)); segment midpoint
      pt3 (vlax-curve-getPointAtParam pl (1- inc))
    ); setq
    (if (equal (angle pt1 pt2) (angle pt2 pt3) 1e-8); line segment
      (command ; then
        "_.dimaligned" pt1 pt3
        "_text" "<>"
      ); [leaves at dimension line location prompt]
      (command ; else [arc segment]
        "_.dimangular" ""
        (inters ; arc center
          (setq pt4 (mapcar '/ (mapcar '+ pt1 pt2) '(2 2 2)))
          (polar pt4 (+ (angle pt1 pt2) (/ pi 2)) 1)
          (setq pt4 (mapcar '/ (mapcar '+ pt2 pt3) '(2 2 2)))
          (polar pt4 (+ (angle pt2 pt3) (/ pi 2)) 1)
          nil
        ); inters
        pt1 pt3
        "_text"
          (strcat
            (itoa *DPseq) ": "
            (rtos (abs (- (vlax-curve-getDistAtParam pl inc) (vlax-curve-getDistAtParam pl (1- inc)))) 2 0)
            "mm"
            ;; [edit mode and precision and suffix as desired -- this is per request on AutoCAD Forum]
          ); strcat
      ); command [leaves at dimension line location prompt]
    ); if
    (command ; complete Dimension: dimension line location
      (polar
        pt2
        (apply
          (if (or (and cw (= side "in")) (and (not cw) (= side "out"))) '- '+)
          (list
            (angle '(0 0 0) (vlax-curve-getFirstDeriv pl (- inc 0.5)))
            (/ pi 2)
          ); list
        ); apply
        (* styht 1.5)
          ;; [If you don't use stacked fractions, consider using styht without multiplier]
      ); polar
    ); command
    (setq
      inc (1- inc)
      *DPseq (1+ *DPseq)
    ); setq
  ); repeat
  (setvar 'clayer clay)
  (setvar 'osmode osm)
  (command "_.undo" "_end")
  (setvar 'cmdecho cmde)
  (princ)
); defun -- C:DP

(defun C:DPI () (DP "in")); = Dimension Polyline Inside
(defun C:DPO () (DP "out")); = Dimension Polyline Outside

(prompt "\nType DPI to Dimension a Polyline on the Inside, DPO to do so on the Outside."

 

Cảm ơn bạn nhiều nha.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay

×