Jump to content

Recommended Posts

Posted

In any case, it could still be simplified a bit further. But leaving aside Maahee's choice of doing it with 'foreach'....

 

(defun c:myDimAlign (/ x e  p f)
  (if (and (setq e (car (entsel "\nSelect any LWpolyline...")))
	   (= (cdr (assoc 0 (setq x (entget e)))) "LWPOLYLINE")
      )
    (while (setq f (cdr (assoc 10 (setq x (cdr (member (setq p (assoc 10 x)) x))))))
      (command "DIMALIGNED" (cdr p) f "@5<180")
    )					
  )
)

 

  • Thanks 1
Posted

Here is my attempt with foreach function based on the request of the OP.

(defun c:DimPly ( / sel 1st )
  ;;--------------------------------------------;;
  ;; Author : Tharwat Al Choufi			;;
  ;;						;;
  ;; www.AutolispPrograms.WordPress.com		;;
  ;;--------------------------------------------;;
  (and (princ "\nSelect LWpolyline to dimension : ")
       (or (setq sel (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))
           (alert "Invalid object.! Try again")
           )
       (foreach itm (entget (ssname sel 0))
         (and (= (car itm) 10)
              (or (and 1st (or (command "_.DIMALIGNED" "_non" 1st "_non" (setq 1st (trans (cdr itm) 0 1)) "@0.35<180") t))
                  (setq 1st (trans (cdr itm) 0 1))
                  )
              )
         )
       )
  (princ)
  )
       

 

  • Thanks 1
Posted (edited)
8 hours ago, Lee Mac said:

 

Only one DIMALIGNED call is required, e.g.:

(defun c:mydimalign ( / e p x )
    (if (and (setq e (car (entsel)))
             (= "LWPOLYLINE" (cdr (assoc 0 (setq x (entget e)))))
        )
        (foreach g x
            (cond
                (   (/= 10 (car g)))
                (   p (command "_.dimaligned" p (setq p (cdr g)) "@5<180"))
                (   (setq p (cdr g)))
            )
        )
    )
    (princ)
)

 

 

@Lee Mac Or another variation of your idea

(defun c:myDimAlign (/ x e g p)
  (if (and (setq e (car (entsel "\nSelect any LWpolyline...")))
	   (= (cdr (assoc 0 (setq x (entget e)))) "LWPOLYLINE")
      )
    (foreach g x
      (if (= (car g) 10)
	(if p
	  (command "DIMALIGNED" p (setq p (cdr g)) "@5<180")
	  (setq p (cdr g))
	)
      )
    )
  )
)

 

Edited by GLAVCVS
  • Thanks 1
Posted

But...

Better thought, it's basically the same thing. 

  • Agree 1
Posted (edited)

Thank you to all. I have tried all the codes that work uniquely and are simple, clean, and easy to understand. It's a great and nice alternative, However, one common drawback is that the codes cannot give the last polyline dimension if it has a closed polyline, which I think does not provide sufficient information from my side. I am trying to fix it.

Edited by maahee
Posted
6 minutes ago, maahee said:

one common drawback is that the codes cannot give the last polyline dimension if it has a closed polyline

 

To account for such a case, you can append the first vertex to the DXF data list, e.g.:

(defun c:mydimalign ( / e p x )
    (if (and (setq e (car (entsel)))
             (= "LWPOLYLINE" (cdr (assoc 0 (setq x (entget e)))))
        )
        (foreach g (if (= 1 (logand 1 (cdr (assoc 70 x)))) (append x (list (assoc 10 x))) x)
            (cond
                (   (/= 10 (car g)))
                (   p (command "_.dimaligned" p (setq p (cdr g)) "@5<180"))
                (   (setq p (cdr g)))
            )
        )
    )
    (princ)
)

 

  • Thanks 1
Posted

Just a comment like @Lee Mac when doing ssget with filters "F" "CP" "WP" it is always a good idea to add the last point to the list again this has the effect of a closed group of points.

 

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

 

  • Thanks 1
Posted (edited)
(if (= (cdr (assoc 0 bm)) "LWPOLYLINE") ; Check if the entity type is LWPOLYLINE
  (progn
      (setq pline (cdr (assoc -1 bm)))
      (setq pdb (entget pline)) ; Get the entity list for the selected polyline.
      (setq p1 nil)
      (foreach sublist pdb
        (if (= (car sublist) 10) ; Look for vertex points (coded as 10).
          (progn
                (if (null p1)
                  (setq p1 (cdr sublist)) ;; First vertex
                  (progn
                    (setq p2 (cdr sublist)) ;; Next vertex
                    (command "DIMALIGNED" p1 p2 "@1<180") 
                    (setq p1 p2) ;; Update p1 for the next iteration
                  ) ; end progn
                ) ; end if
           ) ; end progn
        ) ; end if
      ) ; end foreach
    ) ; end progn
) ; if

another alternative code, which handles closed  polyline vertex, thanks to all for help

Edited by maahee
Posted

I think a necessary improvement to all the codes proposed so far could be to get it to draw the dimensions on the side of the polyline desired by the user.

  • Agree 1
Posted
1 hour ago, GLAVCVS said:

I think a necessary improvement to all the codes proposed so far could be to get it to draw the dimensions on the side of the polyline desired by the user.

There is something similar.

AutoDimPL.lsp

  • Like 1
  • Thanks 1
Posted (edited)

So that no one says that I throw stones and hide my hand, here is my proposal for improvement.

 

(defun c:myDimAlign (/ x e p s d o pS os xD asr dt pr ar osmant)

;;  A D * I N F I N I T V M   A D * I N F I N I T V M   A D * I N F I N I T V M
;;  A D * I N F I N I T V M   A D * I N F I N I T V M   A D * I N F I N I T V M
;;									    ;;;
;;      GGGG   LL           A   VV        VV  CCCC  VV        VV  SSSS      ;;;
;;    GG    GG LL         AA AA  VV      VV CC    CC VV      VV SS    SS    ;;;
;;   GG        LL        AA   AA  VV    VV CC         VV    VV  SS          ;;;
;;   GG   GGGG LL       AA     AA  VV  VV  CC          VV  VV     SSSS      ;;;
;;   GG     GG LL       AA AAA AA  VV  VV  CC          VV  VV         SS    ;;;
;;    GG    GG LL    LL AA     AA   V  V    CC    CC    V  V    SS    SS    ;;;
;;      GGG    LLLLLLLL AA     AA    VV       CCCC       VV       SSSS      ;;;
;;                                                                          ;;;
;;  A D * I N F I N I T V M   A D * I N F I N I T V M   A D * I N F I N I T V M
;;  A D * I N F I N I T V M   A D * I N F I N I T V M   A D * I N F I N I T V M

  (defun os (/ d p i)
    (while (and
	     (setq f (cdr (assoc 10 (setq x (cdr (member (setq p (assoc 10 x)) x))))))
	     (/= (max (distance (cdr p) pS) (distance f pS) (setq d (distance (setq i (cdr p)) f))) d)
	   )
    )
    i
  )
  (defun xD (c1 c2 / ed pt r of)
    (if (not dt)
      (setq dt (distance o (cadr s)) ar (asr (os) pS o))
    )
    (polar c2 (ar (angle c1 c2) (/ pi 2)) dt)
  )
  (defun asr (p1 p2 p3 / a b)
    (if (> (abs (- (setq a (angle p1 p2)) (setq b (angle p2 p3)))) PI)
      (if (< a b)
        (if (> (+ a PI PI) b) - +)
        (if (> (- a PI PI) b) - +)
      )
      (if (> a b) - +)
    )
  )
  (setq osmant (getvar 'OSMODE))
  (setvar 'OSMODE 0) 
  (if (and (setq e (car (setq s (entsel "\nSelect any LWpolyline..."))))
	   (= (cdr (assoc 0 (setq x (entget e)))) "LWPOLYLINE")
	   (setq o (getpoint (setq pS (cadr s)) "\nSide to act on..."))
      )
    (foreach g (if (= (rem (cdr (assoc 70 x)) 2) 0) x (setq x (append x (list (assoc 10 x)))))
      (if (= (car g) 10)
	(if p
	  (command "_DIMALIGNED" p (cdr g) (xD p (setq p (cdr g))))
	  (setq p (cdr g))
	)
      )
    )
  )
  (if osmant (setvar 'OSMODE osmant))
  (princ)
)

 

 

Edited by GLAVCVS
  • Like 1
  • Thanks 1
Posted

If you need to modify parameters such as text size or inclination, arrow size, etc... you may need to add some code modifying a system variable.
That's up to you.
Do your testing.

Posted
1 hour ago, GLAVCVS said:

So that no one says that I throw stones and hide my hand, here is my proposal for improvement.

Good improvement!

And one more thing...

dmp.lsp

  • Like 1
  • Thanks 1
Posted (edited)
14 hours ago, GLAVCVS said:

If you need to modify parameters such as text size or inclination, arrow size, etc... you may need to add some code modifying a system variable.
That's up to you.
Do your testing.

Deciding the direction (inside/outside) by cursor movement is interesting and funny. can add arc dimension in a closed polyline.

Edited by maahee

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