Jump to content

help me create a lisp adjust the distance of the dimension line to the polyline according to the distance you enter, thanks.


Recommended Posts

Posted (edited)

this is i am assuming a short and want to have a lisp that adjusts polyline to dimension distance so with many spacing lines overlapping polyline like this you have an idea to adjust distance from polyline to line size ?

 

123.dwg

Edited by Hải_Duy
Posted

This can help you?

(vl-load-com)
(defun c:Dim_PolyArc ( / js AcDoc modelSpace n ename obj pr dist_start dist_end pt_start pt_end pt_sel seg_len seg_bulge pos offset ang_base ang rad alpha pt_cen)
  (princ "\nSelect polylines.")
  (while (null (setq js (ssget '((0 . "LWPOLYLINE")))))
    (princ "\nSelection is empty, or aren't POLYLINES!")
  )
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    modelSpace (vla-get-ModelSpace Acdoc)
  )
  (vla-StartUndoMark AcDoc)
  (repeat (setq n (sslength js))
    (setq
      ename (ssname js (setq n (1- n)))
      obj (vlax-ename->vla-object ename)
      pr -1
    )
    (repeat (fix (vlax-curve-getEndParam obj))
      (setq
        dist_start (vlax-curve-GetDistAtParam obj (setq pr (1+ pr)))
        dist_end (vlax-curve-GetDistAtParam obj (1+ pr))
        pt_start (vlax-curve-GetPointAtParam obj pr)
        pt_sel (vlax-curve-GetPointAtParam obj (+ pr 0.5))
        pt_end (vlax-curve-GetPointAtParam obj (1+ pr))
        seg_len (- dist_end dist_start)
        seg_bulge (vla-GetBulge obj pr)
        ang_base (angle pt_start pt_end)
      )
      (if (or (not offset) (and (not (eq (getvar "USERR1") (* pi 0.5))) (not (eq (getvar "USERR1") (* pi 1.5)))))
        (progn
          (initget 1)
          (setq
            pos (getpoint pt_sel "\nPosition for all dimensions: ")
            offset (distance pt_sel pos)
            ang (angle pt_sel pos)
          )
          (setvar "USERR1" (if (eq (rem pi (- ang ang_base)) pi) (* 0.5 pi) (* 1.5 pi)))
        )
      )
      (if (not (zerop seg_bulge))
        (progn
          (setq
            rad (/ seg_len (* 4.0 (atan seg_bulge)))
            alpha (+ (angle pt_start pt_end) (- (* pi 0.5) (* 2.0 (atan seg_bulge))))
            pt_cen (polar pt_start alpha rad)
          )
          (vlax-put
            (vla-AddDimAngular
              modelSpace
              (vlax-3d-point pt_cen)
              (vlax-3d-point pt_start)
              (vlax-3d-point pt_end)
              (vlax-3d-point (polar pt_sel (+ ang_base (getvar "USERR1")) offset))
            )
            'TextOverride
            (vl-string-subst (getvar "DIMDSEP") "." (rtos seg_len (getvar "DIMLUNIT") (getvar "DIMDEC")))
          )
        )
        (vla-AddDimAligned
          modelSpace
          (vlax-3d-point pt_start)
          (vlax-3d-point pt_end)
          (vlax-3d-point (polar pt_sel (+ ang_base (getvar "USERR1")) offset))
        )
      )
    )
  )
  (vla-EndUndoMark AcDoc)
  (prin1)
)

 

  • Like 3
Posted

 

this is what i need for my work, thank you very much 🍻

13 hours ago, Tsuky said:

This can help you?

(vl-load-com)
(defun c:Dim_PolyArc ( / js AcDoc modelSpace n ename obj pr dist_start dist_end pt_start pt_end pt_sel seg_len seg_bulge pos offset ang_base ang rad alpha pt_cen)
  (princ "\nSelect polylines.")
  (while (null (setq js (ssget '((0 . "LWPOLYLINE")))))
    (princ "\nSelection is empty, or aren't POLYLINES!")
  )
  (setq
    AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    modelSpace (vla-get-ModelSpace Acdoc)
  )
  (vla-StartUndoMark AcDoc)
  (repeat (setq n (sslength js))
    (setq
      ename (ssname js (setq n (1- n)))
      obj (vlax-ename->vla-object ename)
      pr -1
    )
    (repeat (fix (vlax-curve-getEndParam obj))
      (setq
        dist_start (vlax-curve-GetDistAtParam obj (setq pr (1+ pr)))
        dist_end (vlax-curve-GetDistAtParam obj (1+ pr))
        pt_start (vlax-curve-GetPointAtParam obj pr)
        pt_sel (vlax-curve-GetPointAtParam obj (+ pr 0.5))
        pt_end (vlax-curve-GetPointAtParam obj (1+ pr))
        seg_len (- dist_end dist_start)
        seg_bulge (vla-GetBulge obj pr)
        ang_base (angle pt_start pt_end)
      )
      (if (or (not offset) (and (not (eq (getvar "USERR1") (* pi 0.5))) (not (eq (getvar "USERR1") (* pi 1.5)))))
        (progn
          (initget 1)
          (setq
            pos (getpoint pt_sel "\nPosition for all dimensions: ")
            offset (distance pt_sel pos)
            ang (angle pt_sel pos)
          )
          (setvar "USERR1" (if (eq (rem pi (- ang ang_base)) pi) (* 0.5 pi) (* 1.5 pi)))
        )
      )
      (if (not (zerop seg_bulge))
        (progn
          (setq
            rad (/ seg_len (* 4.0 (atan seg_bulge)))
            alpha (+ (angle pt_start pt_end) (- (* pi 0.5) (* 2.0 (atan seg_bulge))))
            pt_cen (polar pt_start alpha rad)
          )
          (vlax-put
            (vla-AddDimAngular
              modelSpace
              (vlax-3d-point pt_cen)
              (vlax-3d-point pt_start)
              (vlax-3d-point pt_end)
              (vlax-3d-point (polar pt_sel (+ ang_base (getvar "USERR1")) offset))
            )
            'TextOverride
            (vl-string-subst (getvar "DIMDSEP") "." (rtos seg_len (getvar "DIMLUNIT") (getvar "DIMDEC")))
          )
        )
        (vla-AddDimAligned
          modelSpace
          (vlax-3d-point pt_start)
          (vlax-3d-point pt_end)
          (vlax-3d-point (polar pt_sel (+ ang_base (getvar "USERR1")) offset))
        )
      )
    )
  )
  (vla-EndUndoMark AcDoc)
  (prin1)
)

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...