Jump to content

This lisp puts dimensions on a pline, how can I have it put the dimensions above the pline? Also it doesn't put a dimension on the last line.


Recommended Posts

Posted (edited)
(defun c:PLD (/ ent obj i p1 p2)
  (vl-load-com)
  (if (setq ent (car (entsel "\nSelect Polyline to Dimension: ")))
    (progn
      (setq obj (vlax-ename->vla-object ent))
      (if (= (vla-get-ObjectName obj) "AcDbPolyline")
        (progn
          (setvar "cmdecho" 0)
          (command "._undo" "_begin")
          (setq i 0)
          ;; Loop through vertices
          (repeat (fix (- (vlax-curve-getEndParam obj) 1))
            (setq p1 (vlax-curve-getPointAtParam obj i)
                  p2 (vlax-curve-getPointAtParam obj (1+ i)))
            ;; Create aligned dimension
            (command "_.dimaligned" "_none" p1 "_none" p2 "_none" (polar p1 (+ (angle p1 p2) (/ pi 2)) 1.0))
            (setq i (1+ i))
          )
          (command "._undo" "_end")
          (setvar "cmdecho" 1)
        )
        (princ "\nSelected object is not a LightWeight Polyline.")
      )
    )
  )
  (princ)
)
(princ "\nType 'DimPlineSegments' to run.")

 

Edited by SLW210
Added Code Tags!!
Posted

In the future please place your code in Code Tags. (<> in the editor toolbar)

Posted (edited)

Another way to approach this ";; Loop through vertices" is to get all the vertices and simply use those XY values of the corresponding two points in a repeat. You can check the readabilty of the answer by looking at the angle of the two points, so place answer above or below.

 

There are plenty of label plines out there do a google,  "Kent Cooper" has some good ones. may be faster than debugging what you have.

 

setq plent (entsel "\nPick pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(princ co-ord)

 

Edited by BIGAL
Posted

Perhaps it will suit you. Polyline Dimension by marko_ribar

(defun c:pdim ( / ListClockwise-p ch plSet pLlst vLst oldOsn cAng cDis cPt )
;;; Polyline Dimension by marko_ribar  
;;;https://www.cadtutor.net/forum/topic/54351-automatic-distance-between-polygon-vertices/#comment-451128
;;; posted https://forum.dwg.ru/forumdisplay.php?f=13  
 (vl-load-com) 
 (defun ListClockwise-p ( lst / z vlst )
   (vl-catch-all-apply 'minusp 
     (list
       (if 
         (not 
           (equal 0.0
             (setq z
               (apply '+
                 (mapcar 
                   (function
                     (lambda (u v)
                       (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
                     )
                   )
                   (setq vlst
                     (mapcar
                       (function
                         (lambda (a b) (mapcar '- b a))
                       )
                       (mapcar (function (lambda (x) (car lst))) lst) 
                       (cdr (reverse (cons (car lst) (reverse lst))))
                     )
                   )
                   (cdr (reverse (cons (car vlst) (reverse vlst))))
                 )
               )
             ) 1e-6
           )
         )
         z
         (progn
           (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
           nil
         )
       )
     )
   )
 )

 (initget 1 "Outside Inside")
 (setq ch (getkword "\nChoose on which side to put dimensions [Outside/Inside] : "))
 (princ "\n<<< Select LwPolyline(s) for dimensioning >>> ")
 (if (setq plSet (ssget '((0 . "LWPOLYLINE"))))
   (progn
     (setq pLlst (vl-remove-if 'listp
                        (mapcar 'cadr(ssnamex plSet)))
           oldOsn (getvar "OSMODE")
     ); end setq
     (setvar "OSMODE" 0) (setvar "CMDECHO" 0)
     (command "_.undo" "_be")
     (foreach pl pLlst
      (setq vLst (mapcar '(lambda( x ) (trans x 0 1)) 
                   (mapcar 'cdr (vl-remove-if-not '(lambda( x ) (= 10 (car x)))
                                  (entget pl)
                                )
                   )
                 )
      ); end setq
      (if (equal (logand (cdr (assoc 70 (entget pl))) 1) 1)
       (setq vLst (append vLst (list (car vLst))))
      ); end if
      (if (not (ListClockwise-p vLst)) (setq vLst (reverse vLst)))
      (while (< 1 (length vLst))
       (setq cAng (angle (car vLst) (cadr vLst))
               cDis (/ (distance (car vLst) (cadr vLst)) 2.0)
       )
;_        (if (>= (caar vLst) (caadr vLst))
;_         (setq cAng (- cAng pi))
;_        ); end if
       (if (eq ch "Inside")
        (setq cPt (polar (polar (car vLst) cAng cDis) (- cAng (* 0.5 pi)) (* 2.5 (getvar "DIMTXT")))); end setq
        (setq cPt (polar (polar (car vLst) cAng cDis) (+ cAng (* 0.5 pi)) (* 2.5 (getvar "DIMTXT")))); end setq
       ); end if
       (command "_.dimaligned" (car vLst) (cadr vLst) cPt)
       (setq vLst (cdr vLst))
      ); end while
     ); end foreach
     (command "_.undo" "_e")
     (setvar "OSMODE" oldOsn) (setvar "CMDECHO" 1)
   ); end progn
 ); end if
 (princ)
)

 

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...