Author Topic: How to insert these set of dimensions?  (Read 2381 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How to insert these set of dimensions?
« on: February 23, 2019, 03:37:05 PM »
Hi all
I am working on a Roads project.
The task is adding these dimesions
I tried several times to code this lisp but can not
Option one there is itermediate iland and another one is no itermediate island

attached a sample file

Thanks in advance
« Last Edit: February 28, 2019, 09:16:23 AM by HasanCAD »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: How to insert these set of dimensions?
« Reply #1 on: March 01, 2019, 04:21:01 PM »
Hi,
This should get you started and would sort the list of coordinates according to the shortest distance to point one ( variable 'p1' ) then you can iterate the coordinates and create the dimensions based on that.
Code - Auto/Visual Lisp: [Select]
  1. (and (setq p1 (getpoint "\nSpecify first point :"))
  2.      (setq p2 (getpoint "\nNext point :" p1))
  3.      (setq ss (ssget "_C" p1 p2 '((0 . "LINE"))))
  4.      (repeat (setq i (sslength ss))
  5.        (setq pts (cons (vlax-curve-getclosestpointto (ssname ss (setq i (1- i))) p1) pts))
  6.      )
  7.      (setq pts (vl-sort pts '(lambda (a b) (< (distance p1 a) (distance p1 b))))
  8.      )
  9. )

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to insert these set of dimensions?
« Reply #2 on: March 01, 2019, 08:30:57 PM »
This What i ened up to
Created a cad file has a set of dimentions as  3 blocks then insert the block related to number of selected lines
the lisp working good for first selection of lines but the second
Attached the cad file and a screenshoot for the error

Thanks in advance

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN C:RoadDimensionInsert ( / ANG BN BOBJ CLYR CNT DIS DISS DOC DTLST LST N1 OBJS OBJVL OSNP P1 P1N P2 PNTS-LST PNTS-LST-1 PNTS-LSTR PNTS-LSTS SPC SSLNGTH X )
  2.  
  3.     (setq *acad (cond (*acad) ((vlax-get-acad-object))))
  4.         spc (if (zerop (vla-get-activespace doc))
  5.               (if (= (vla-get-mspace doc) :vlax-true)
  6.                 (vla-get-modelspace doc) (vla-get-paperspace doc))
  7.               (vla-get-modelspace doc)))
  8.  
  9.   (setq uFlag (not (vla-StartUndoMark doc)))
  10.   (setq osnp (getvar "osmode"))         (setvar "osmode" 0)
  11.   (setq clyr (getvar "CLAYER"))
  12.   (setq diss nil)
  13.   (setq dtlst nil)
  14.  
  15.   (if (MakeLayer "TEMP" 8 "Continuous" 0.01 nil 0 "TEMP LAYER")
  16.     (progn
  17.       (setq clyr (getvar "CLAYER"))
  18.       (setvar "CLAYER" "TEMP"))
  19.     (setvar "CLAYER" "Defpoints"))
  20.   (if (and
  21.         (vl-cmdf "_.-insert" "C:/RoadDimension/RoadDimension.dwg" "0,0,0" "1" "1" "0")          ; inser blocks
  22.         (tblsearch "BLOCK" "RoadDimension"))
  23.     (progn
  24.       (vl-cmdf "_.erase" "last" "")
  25.       (vl-cmdf "_.-purge" "blocks" "RoadDimension" "n")
  26.  
  27.       (while (and
  28.                (setq p1 (getpoint"\nPick Dimension Point at left side of road "))
  29.                ;(setvar "osmode" 128)
  30.                (setq p2 (getpoint p1 "\nPick Dimension Point at right side of road")))
  31.  
  32.       (setq objs (ssget "_C" p1 p2 ))
  33.         (cond ( (= 10 (setq SSLngth (sslength objs))) (HSN:10lines)     )
  34.               ( (= 8  (setq SSLngth (sslength objs))) (HSN:8lines)      )
  35.               ( (= 6  (setq SSLngth (sslength objs))) (HSN:6lines)      )
  36.               ( T (alert "\nNo lines selected \nTry to isolate road lines then reuse the lisp"))
  37.               )
  38.         (setvar "osmode" osnp)
  39.         (setvar "CLAYER" clyr)
  40.         (setq uFlag (vla-EndUndoMark doc))
  41.         ))))
  42.  
  43. (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))
  44.   (setvar "osmode"      osnp )
  45.   (setvar "cmdecho"     cmd )
  46.   (princ)
  47. )
  48.  
  49. (defun HSN:10lines ( / )
  50.   (repeat (setq cnt (sslength objs))
  51.     (setq objVL (vlax-ename->vla-object (ssname objs (setq cnt (1- cnt)))))
  52.     (setq p1n (vlax-curve-getclosestpointto objVL p1))
  53.     (setq dtlst (cons p1n dtlst))
  54.     (setq dis (distance p1 p1n ))
  55.     (setq diss (cons dis diss))
  56.     )
  57.   (setq lst (gc:sort diss <))
  58.   (setq n1 (nth 0 lst))
  59.   (setq lst (mapcar '(lambda (x) (- x n1)) lst))
  60.   (setq lst (vl-remove (nth 0 lst) lst))
  61.  
  62.   (setq pnts-lst (SortPointList 'XYZ 1e-3 < < < dtlst))
  63.   (setq pnts-lstS (vl-remove (nth 0 pnts-lst) pnts-lst))
  64.   (setq pnts-lstR (reverse  pnts-lst))
  65.   (setq pnts-lst-1 (nth 0 pnts-lst ))
  66.   (setq ang (angle pnts-lst-1  (nth 0 pnts-lstR )))
  67.   (setq bn (strcat "RoadDim-" (itoa SSLngth)))
  68.   (vl-catch-all-error-p (setq bobj (vl-catch-all-apply (function vla-InsertBlock) (list spc (vlax-3D-point pnts-lst-1) bn 1.0 1.0 1.0 ang))))
  69.   (LM:setdynprops
  70.     bobj
  71.     (list (cons "0" (nth 0 lst))
  72.           (cons "1" (nth 1 lst))
  73.           (cons "2" (nth 2 lst))
  74.           (cons "3" (nth 3 lst))
  75.           (cons "4" (nth 4 lst))
  76.           (cons "5" (nth 5 lst))
  77.           (cons "6" (nth 6 lst))
  78.           (cons "7" (nth 7 lst))
  79.           (cons "8" (nth 8 lst))
  80.           )
  81.     )
  82.   (command "_.EXPLODE" "Last")
  83.   )
  84.  
  85. (defun HSN:8lines ( / )
  86.   (repeat (setq cnt (sslength objs))
  87.     (setq objVL (vlax-ename->vla-object (ssname objs (setq cnt (1- cnt)))))
  88.     (setq p1n (vlax-curve-getclosestpointto objVL p1))
  89.     (setq dtlst (cons p1n dtlst))
  90.     (setq dis (distance p1 p1n ))
  91.     (setq diss (cons dis diss))
  92.     )
  93.   (setq lst (gc:sort diss <))
  94.   (setq n1 (nth 0 lst))
  95.   (setq lst (mapcar '(lambda (x) (- x n1)) lst))
  96.   (setq lst (vl-remove (nth 0 lst) lst))
  97.  
  98.   (setq pnts-lst (SortPointList 'XYZ 1e-3 < < < dtlst))
  99.   (setq pnts-lstS (vl-remove (nth 0 pnts-lst) pnts-lst))
  100.   (setq pnts-lstR (reverse  pnts-lst))
  101.   (setq pnts-lst-1 (nth 0 pnts-lst ))
  102.   (setq ang (angle pnts-lst-1  (nth 0 pnts-lstR )))
  103.   (setq bn (strcat "RoadDim-0" (itoa SSLngth)))
  104.   (vl-catch-all-error-p (setq bobj (vl-catch-all-apply (function vla-InsertBlock) (list spc (vlax-3D-point pnts-lst-1) bn 1.0 1.0 1.0 ang))))
  105.   (LM:setdynprops
  106.     bobj
  107.     (list (cons "0" (nth 0 lst))
  108.           (cons "1" (nth 1 lst))
  109.           (cons "2" (nth 2 lst))
  110.           (cons "3" (nth 3 lst))
  111.           (cons "4" (nth 4 lst))
  112.           (cons "5" (nth 5 lst))
  113.           (cons "6" (nth 6 lst))
  114.           )
  115.     )
  116.   (command "_.EXPLODE" "Last")
  117.   )
  118. (defun HSN:6lines ( / )
  119.   (repeat (setq cnt (sslength objs))
  120.     (setq objVL (vlax-ename->vla-object (ssname objs (setq cnt (1- cnt)))))
  121.     (setq p1n (vlax-curve-getclosestpointto objVL p1))
  122.     (setq dtlst (cons p1n dtlst))
  123.     (setq dis (distance p1 p1n ))
  124.     (setq diss (cons dis diss))
  125.     )
  126.   (setq lst (gc:sort diss <))
  127.   (setq n1 (nth 0 lst))
  128.   (setq lst (mapcar '(lambda (x) (- x n1)) lst))
  129.   (setq lst (vl-remove (nth 0 lst) lst))
  130.  
  131.   (setq pnts-lst (SortPointList 'XYZ 1e-3 < < < dtlst))
  132.   (setq pnts-lstS (vl-remove (nth 0 pnts-lst) pnts-lst))
  133.   (setq pnts-lstR (reverse  pnts-lst))
  134.   (setq pnts-lst-1 (nth 0 pnts-lst ))
  135.   (setq ang (angle pnts-lst-1  (nth 0 pnts-lstR )))
  136.   (setq bn (strcat "RoadDim-0" (itoa SSLngth)))
  137.   (vl-catch-all-error-p (setq bobj (vl-catch-all-apply (function vla-InsertBlock) (list spc (vlax-3D-point pnts-lst-1) bn 1.0 1.0 1.0 ang))))
  138.   (LM:setdynprops
  139.     bobj
  140.     (list (cons "0" (nth 0 lst))
  141.           (cons "1" (nth 1 lst))
  142.           (cons "2" (nth 2 lst))
  143.           (cons "3" (nth 3 lst))
  144.           (cons "4" (nth 4 lst))
  145.           )
  146.     )
  147.   (command "_.EXPLODE" "Last")
  148.   )
  149.  
  150. ;; Set Dynamic Block Properties  -  Lee Mac
  151. ;; Modifies values of Dynamic Block properties using a supplied association list.
  152. ;; blk - [vla] VLA Dynamic Block Reference object
  153. ;; lst - [lst] Association list of ((<Property> . <Value>) ... )
  154. ;; Returns: nil
  155. (defun LM:setdynprops (blk lst / itm x)
  156.   (setq lst (mapcar '(lambda (x) (cons (strcase (car x)) (cdr x))) lst))
  157.   (foreach x (vlax-invoke blk 'getdynamicblockproperties)
  158.     (if (setq itm (assoc (strcase (vla-get-propertyname x)) lst))
  159.       (vla-put-value
  160.         x
  161.         (vlax-make-variant
  162.           (cdr itm)
  163.           (vlax-variant-type (vla-get-value x)) )      )    )  ))
  164. ; END DEFUN - LM:setdynprops
  165.  
  166. (defun SortPointList (fA fz dx dy dz pL / fp f)
  167.   (if
  168.     (and
  169.       (setq fp
  170.              (cadr
  171.                (assoc fA
  172.                       (list
  173.                         (list 'XYZ
  174.                               (lambda (a b c)
  175.                                 (if a
  176.                                   (if b
  177.                                     (if c
  178.                                       (dz z1 z2)
  179.                                       (dz z1 z2)                                    )
  180.                                     (dy y1 y2)                            )
  181.                                   (dx x1 x2)                            )                             )                 )
  182.                         (list 'XZY
  183.                               (lambda (a b c)
  184.                                 (if a
  185.                                   (if c
  186.                                     (if b
  187.                                       (dy y1 y2)
  188.                                       (dy y1 y2)                                    )
  189.                                     (dz z1 z2)                            )
  190.                                   (dx x1 x2)    )       )                       )
  191.                         (list 'YXZ
  192.                               (lambda (a b c)
  193.                                 (if b
  194.                                   (if a
  195.                                     (if c
  196.                                       (dz z1 z2)
  197.                                       (dz z1 z2)                                    )
  198.                                     (dx x1 x2)                            )
  199.                                   (dy y1 y2)    )      )                        )
  200.                         (list 'YZX
  201.                               (lambda (a b c)
  202.                                 (if b
  203.                                   (if c
  204.                                     (if a
  205.                                       (dx x1 x2)
  206.                                       (dx x1 x2)                                    )
  207.                                     (dz z1 z2)                            )
  208.                                   (dy y1 y2)    )       )                       )
  209.                         (list 'ZXY
  210.                               (lambda (a b c)
  211.                                 (if c
  212.                                   (if a
  213.                                     (if b
  214.                                       (dy y1 y2)
  215.                                       (dy y1 y2)                                    )
  216.                                     (dx x1 x2)                            )
  217.                                   (dz z1 z2)    )       ) )
  218.                         (list 'ZYX
  219.                               (lambda (a b c)
  220.                                 (if c
  221.                                   (if b
  222.                                     (if a
  223.                                       (dx x1 x2)
  224.                                       (dx x1 x2)                                    )
  225.                                     (dy y1 y2)                            )
  226.                                   (dz z1 z2)    )       ) )                   )                )     )        )                        
  227.       (setq f                  
  228.              (lambda (p1 p2 / x1 y1 z1 x2 y2 z2 a b c)                         
  229.                (mapcar 'set '(x1 y1 z1) p1)
  230.                (mapcar 'set '(x2 y2 z2) p2)                            
  231.                (mapcar 'set '(a b c)  (mapcar (function (lambda (a b) (equal a b fz))) p1 p2)       )
  232.                (fp a b c)            )                )     )                          
  233.      (vl-sort pL (function f))    ))                                    ; defun SortPointList
  234.  
  235.  
  236. (defun gc:sort (lst fun / merge tmp)
  237.   (defun merge (l1 l2)
  238.     (cond      ((null l1) l2)      ((null l2) l1)
  239.       ((fun (car l1) (car l2)) (cons (car l1) (merge (cdr l1) l2)))
  240.       (T (cons (car l2) (merge l1 (cdr l2))))))
  241.  
  242.   (setq fun (eval fun)  lst (mapcar 'list lst))
  243.   (while (cdr lst)
  244.     (setq tmp lst lst nil)
  245.     (while (cdr tmp)
  246.       (setq lst (cons (merge (car tmp) (cadr tmp)) lst)
  247.             tmp (cddr tmp)))
  248.     (and tmp (setq lst (cons (car tmp) lst))))
  249.   (car lst))
  250.  
  251.  
  252. (defun MakeLayer ( name colour linetype lineweight willplot bitflag description )
  253.   (regapp "AcAecLayerStandard")
  254.     ;; (MakeLayer name colour linetype lineweight willplot bitflag description )
  255.     ;; Specifications:
  256.     ;; Description        Data Type        Remarks
  257.     ;; ---------------------------------------------------------------------------------
  258.     ;; Layer Name          STRING          Only standard chars allowed                 
  259.     ;; Layer Colour        INTEGER         may be nil, -ve for Layer Off, Colour < 256 
  260.     ;; Layer Linetype      STRING          may be nil, If not loaded, CONTINUOUS.      
  261.     ;; Layer Lineweight    REAL            may be nil, 0 <= x <= 2.11                  
  262.     ;; Plot?               BOOLEAN         T = Plot Layer, nil otherwise               
  263.     ;; Bit Flag            INTEGER         0=None, 1=Frozen, 2=Frozen in VP, 4=Locked  
  264.     ;; Description         STRING          may be nil for no description               
  265.     ;; Function will return list detailing whether layer creation is successful.       
  266.  
  267.     ;; © Lee Mac 2010
  268.   (or (tblsearch "LAYER" name)
  269.     (entmake
  270.       (append
  271.         (list
  272.           (cons 0       "LAYER")
  273.           (cons 100     "AcDbSymbolTableRecord")
  274.           (cons 100     "AcDbLayerTableRecord")
  275.           (cons 2       name)
  276.           (cons 70      bitflag)
  277.           (cons 290     (if willplot 1 0))
  278.           (cons 6       (if (and linetype (tblsearch "LTYPE" linetype)) linetype "CONTINUOUS"))
  279.           (cons 62      (if (and colour (< 0 (abs colour) 256)) colour 7))
  280.           (cons 370     (fix (* 100 (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0))))
  281.           )
  282.         (if description (list (list -3 (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description)))))
  283.         ))))

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: How to insert these set of dimensions?
« Reply #3 on: March 02, 2019, 04:42:18 AM »
Hi,
Try the following program and be sure is that the program would select the crossed Line objects only and ignores polylines and I am raising this issue because you already have polyline objects among the lines that represents the road routes as in the above attached sample drawing.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:dimroad (/ p1 p2 ss i bkn int pts doc ins ang blk prs bse)
  2.   ;;    Tharwat - 02.Mar.2019           ;;
  3.   (if
  4.     (and
  5.       (setq p1 (getpoint "\nSpecify first point :"))
  6.       (setq p2 (getpoint "\nNext point :" p1))
  7.       (setq ss (ssget "_C" p1 p2 '((0 . "LINE"))))
  8.       (setq i (sslength ss))
  9.       (if (or (= i 6) (= i 8) (= i 10))
  10.         (or (tblsearch "BLOCK"
  11.                        (setq bkn (strcat "RoadDim-"
  12.                                          (if (= i 10)
  13.                                            "10"
  14.                                            (strcat "0" (itoa i))
  15.                                          )
  16.                                  )
  17.                        )
  18.             )
  19.             (alert (strcat "Block name <"
  20.                            bkn
  21.                            "> not found in current drawing."
  22.                    )
  23.             )
  24.         )
  25.         (alert
  26.           "Number of collected lines are not equal to 6 or 8 nor to 10"
  27.         )
  28.       )
  29.       (setq int -1)
  30.       (repeat i
  31.                           (ssname ss (setq i (1- i)))
  32.                           p1
  33.                         )
  34.                         pts
  35.                   )
  36.         )
  37.       )
  38.       (setq pts
  39.              (vl-sort pts
  40.                       '(lambda (a b) (< (distance p1 a) (distance p1 b)))
  41.              )
  42.       )
  43.             ins (last pts)
  44.             ang (angle (car pts) ins)
  45.       )
  46.       (if (and (> ang (* pi 0.5)) (< ang (* pi 1.5)))
  47.         (setq ang (+ pi ang))
  48.         (setq ins (car pts))
  49.       )
  50.     )
  51.      (progn
  52.        (vla-endUndomark doc)
  53.        (vla-StartUndoMark doc)
  54.        (setq blk (entmakex (list '(0 . "INSERT")
  55.                                  (cons 10 ins)
  56.                                  (cons 2 bkn)
  57.                                  (cons 50 ang)
  58.                                  '(41 . 1.0)
  59.                                  '(42 . 1.0)
  60.                                  '(43 . 1.0)
  61.                            )
  62.                  )
  63.              prs (vlax-invoke
  64.                    (vlax-ename->vla-object blk)
  65.                    'getdynamicBlockproperties
  66.                  )
  67.              pts (reverse pts)
  68.              bse (car pts)
  69.        )
  70.        (mapcar
  71.          '(lambda (d)
  72.             (setq int (1+ int))
  73.             (vl-some '(lambda (x)
  74.                         (if (= (vla-get-propertyname x) (itoa int))
  75.                           (progn (vlax-put x 'Value (distance bse d)) t)
  76.                         )
  77.                       )
  78.                      prs
  79.             )
  80.           )
  81.          (cdr pts)
  82.        )
  83.        (vla-endUndomark doc)
  84.      )
  85.   )
  86.   (princ)
  87.  
  88.  

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to insert these set of dimensions?
« Reply #4 on: March 03, 2019, 12:00:55 PM »
OK
Thanks for your lisp but whats making my lisp not working.