Author Topic: How to display dimensions before pick the location?  (Read 1756 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How to display dimensions before pick the location?
« on: April 28, 2020, 06:51:05 AM »
Hi all
This lisp was on internet I want one modification
I want to react the dimension before pick the location
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun C:BSD ( / *error* doc oVAR ss i pts ptsx ptsy d d0 filter)
  3.  
  4.    (defun *error* (errmsg)
  5.     (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
  6.       (princ (strcat "\nError: " errmsg)))
  7.     (foreach e oVAR (setvar (car e) (cdr e)))
  8.     (vla-endundomark doc)
  9.     (princ))
  10.  
  11.   ;------------------------------------------------------------------------------------------------------
  12.  
  13.   (foreach e '(CMDECHO ORTHOMODE)
  14.     (setq oVAR (cons (cons e (getvar e)) oVAR)))
  15.  
  16.   (setvar 'CMDECHO      0)
  17.   (setvar 'ORTHOMODE    0)
  18.    
  19.   (if (and (princ "\nNeed blocks, ")
  20.                (setq ss (ssget (list '(0 . "INSERT"))))
  21.            (< 1 (setq i (sslength ss)))
  22.            (while (not (minusp (setq i (1- i))))
  23.              (setq pts (cons (cdr (assoc 10 (entget (ssname ss i)))) pts)))
  24.            (setq ptsx (vl-sort pts '(lambda (p q) (< (car  p) (car  q)))))
  25.            (setq ptsy (vl-sort pts '(lambda (p q) (< (cadr p) (cadr q)))))
  26.  
  27.            (setq d (abs (/ (- (car  (last ptsx)) (caar  ptsx))      ;xmax-xmin
  28.                            (if (zerop (setq d0 (- (cadr (last ptsy)) (cadar ptsy)))) ;ymax-ymin
  29.                              0.001
  30.                              d0))))
  31.  
  32.            
  33.            (setq pt (getpoint "\nSpecify dimension line location: "))
  34.  
  35.            (or *DimTypeBDA
  36.                (setq *DimTypeBDA "Aligned"))
  37.            (not (initget "Horizontal Vertical Aligned"))
  38.            (setq *DimTypeBDA (cond ((getkword (strcat "\nType of dimension ["
  39.                                                       (cond ((> d 1000.) (if (= *DimTypeBDA "Vertical") (setq *DimTypeBDA "Horizontal")) "Horizontal")
  40.                                                             ((< d 0.001) (if (= *DimTypeBDA "Horizontal") (setq *DimTypeBDA "Vertical")) "Vertical")
  41.                                                             ("Horizontal/Vertical"))
  42.                                                       "/Aligned] <" *DimTypeBDA ">: ")))
  43.                                    (*DimTypeBDA)))
  44.  
  45.            (setq pts (if (or (= *DimTypeBDA "Horizontal")
  46.                              (and (= *DimTypeBDA "Aligned")
  47.                                   (> (- (car (last ptsx))  (caar ptsx))
  48.                                      (- (cadr (last ptsy)) (cadar ptsy)))))
  49.                        ptsx
  50.                        ptsy))
  51.            
  52.        
  53.  
  54.            (setq i 0)
  55.            )
  56.  
  57.    
  58.     (repeat (1- (length pts))  
  59.  
  60.       (cond ((= *DimTypeBDA "Horizontal")
  61.              (command "_.DIMLINEAR"
  62.                         "_none" (nth i pts)
  63.                         "_none" (nth (1+ i) pts)
  64.                         "_H"
  65.                         "_none" pt))
  66.            
  67.             ((= *DimTypeBDA "Vertical")
  68.                (command "_.DIMLINEAR"
  69.                         "_none" (nth i pts)
  70.                         "_none" (nth (1+ i) pts)
  71.                         "_V"
  72.                         "_none" pt))
  73.            
  74.             (T ;Aligned
  75.                (command "_.DIMALIGNED"
  76.                         "_none" (nth i pts)
  77.                         "_none" (nth (1+ i) pts)
  78.                         "_none" pt)))
  79.  
  80.  
  81.  
  82.       (setq i (1+ i)))
  83.  
  84.     (princ (strcat "\nError: Wrong selection of at least 2 BLOCKS.")))
  85.  
  86.   (foreach e oVAR (setvar (car e) (cdr e)))
  87.   (princ)
  88. )

Thanks

DEVITG

  • Bull Frog
  • Posts: 480
Re: How to display dimensions before pick the location?
« Reply #1 on: May 01, 2020, 04:31:48 PM »
@HasanCAD , would you, please, upload the sample.dwg where you apply the lisp?
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to display dimensions before pick the location?
« Reply #2 on: May 02, 2020, 08:27:37 PM »
Attached a sample file
I want to locate the dimension line after the appearance of the dimension. Like QDIM command.

hanhphuc

  • Newt
  • Posts: 64
Re: How to display dimensions before pick the location?
« Reply #3 on: May 05, 2020, 02:02:25 AM »
Hi all
This lisp was on internet I want one modification
I want to react the dimension before pick the location
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun C:BSD ( / *error* doc oVAR ss i pts ptsx ptsy d d0 filter)
  3.  
  4.   ;;<snippets>
  5. )
  6.  

Thanks


C:BSD ??
C:FH ??
Just notice someone posted at cadtutor 99% identical? author? :thinking:
https://www.cadtutor.net/forum/topic/70445-automatic-dimensioning-for-blocks-in-autocad/

my grread solution - dynamic transient function gr-lines
wrap progn before 'repeat'

pseudo :
(setq pt (getpoint ... )) ;<-- to be deleted
{if and progn else}

Code - Auto/Visual Lisp: [Select]
  1.               (setq  pts (mapcar '(lambda (x) (trans x 0 1)) pts)
  2.                      pt (gr-lines (vl-position *DimTypeBDA '("Horizontal" "Vertical" "Aligned"))
  3.                          4 (getvar 'viewctr)
  4.                          pts
  5.                         )
  6.                 ) ;setq
  7.  
  8.   (repeat ;;<snippets>;;)
  9.  
  10. ); end of progn
  11.  
  12.  

« Last Edit: May 05, 2020, 02:17:45 PM by hanhphuc »
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments