Author Topic: Help with lisp - intersections dimension  (Read 1890 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help with lisp - intersections dimension
« on: September 19, 2021, 03:55:47 AM »
Hi i am using Lee Mac code for intersection dimension. I add two lines in the code to work for annotation text. I want to ask if someone or Lee Mac can help. Is it possible to identify all lines,polylines, circles in specific layer and insert the dimensions. In my example i have 7 parallel  in layer DR_LINES. To dimension them i have to pick one line a time.Is it possible to autoselect all in layer DR_LINES and dimension them?

Code - Auto/Visual Lisp: [Select]
  1. ;;-------------=={ Length Between Intersections }==-----------;;
  2. ;;                                                            ;;
  3. ;;  Displays the length of segments of a curve divided at     ;;
  4. ;;  intersections with other objects.                         ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  7. ;;------------------------------------------------------------;;
  8. ;;  Version 1.4    -    26-04-2011                            ;;
  9. ;;------------------------------------------------------------;;
  10.  
  11. (defun c:IntLen ( / *error* _iscurveobject e )
  12.  
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. ; Add two lines for Annotation Text
  16.  
  17.   (command "_.-layer" "_make" "_DIM" "_color" 93 "" "_lweight" 0.30 "" "")
  18.   (command "_.-style" "_diast" "wgsimpl.shx" "_annotative" "_yes" "_no" 1.75 1.2 0.0 "_no" "_no" "_no")
  19.  
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.  
  22.   (defun *error* ( msg )
  23.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  24.         (princ (strcat "\n** Error: " msg " **")))
  25.     (princ)
  26.   )
  27.  
  28.   (defun _IsCurveObject ( entity / param )
  29.     (and
  30.       (not
  31.           (setq param
  32.             (vl-catch-all-apply 'vlax-curve-getendparam (list entity))
  33.           )
  34.         )
  35.       )
  36.       param
  37.     )
  38.   )
  39.  
  40.   (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER))))))
  41.     (princ "\n--> Current Layer Locked.")  
  42.     (while
  43.       (progn (setvar 'ERRNO 0) (setq e (car (entsel)))
  44.         (cond
  45.           (
  46.             (= 7 (getvar 'ERRNO))
  47.  
  48.             (princ "\n--> Missed, Try again.")
  49.           )
  50.           (
  51.             (eq 'ENAME (type e))
  52.  
  53.             (if (_iscurveobject e)
  54.               (LM:IntersectionLengths e)
  55.               (princ "\n--> Invalid Object Selected.")
  56.             )
  57.             t
  58.           )
  59.         )
  60.       )
  61.     )
  62.   )
  63.   (princ)
  64. )
  65.  
  66. ;;------------------------------------------------------------;;
  67.  
  68. (defun c:IntLenM ( / *error* ss i )
  69.  
  70.   (defun *error* ( msg )
  71.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  72.         (princ (strcat "\n** Error: " msg " **")))
  73.     (princ)
  74.   )
  75.  
  76.   (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (getvar 'CLAYER))))))
  77.     (princ "\n--> Current Layer Locked.")
  78.     (if (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE"))))
  79.       (repeat (setq i (sslength ss))
  80.         (LM:IntersectionLengths (ssname ss (setq i (1- i))))
  81.       )
  82.     )
  83.   )
  84.  
  85.   (princ)
  86. )
  87.  
  88. ;;------------------------------------------------------------;;
  89.  
  90. (defun LM:IntersectionLengths
  91.  
  92.   ( e  ;; Entity name
  93.    
  94.     / *error* _startundo _endundo _groupbynum _sortbyparam _makereadable _isannotative _uniquefuzz
  95.       a acspc c d d1 d2 da e i l ll m o ss ta to ts ur x y
  96.   )
  97.  
  98.         acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
  99.   )
  100.  
  101.   (defun *error* ( msg )
  102.     (if acdoc (_EndUndo acdoc))
  103.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  104.         (princ (strcat "\n** Error: " msg " **")))
  105.     (princ)
  106.   )
  107.  
  108.   (defun _StartUndo ( doc ) (_EndUndo doc)
  109.     (vla-StartUndoMark doc)
  110.   )
  111.  
  112.   (defun _EndUndo ( doc )
  113.     (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc))
  114.   )
  115.  
  116.   (defun _GroupByNum ( l n / r)
  117.     (if l
  118.       (cons
  119.         (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
  120.         (_GroupByNum l n)
  121.       )
  122.     )
  123.   )
  124.  
  125.   (defun _SortbyParam ( e l )
  126.   )
  127.  
  128.   (defun _MakeReadable ( a )
  129.     (
  130.       (lambda ( a )
  131.         (cond
  132.           ( (and (> a (/ pi 2)) (<= a pi))
  133.  
  134.             (- a pi)
  135.           )
  136.           ( (and (> a pi) (<= a (/ (* 3 pi) 2)))
  137.  
  138.             (+ a pi)
  139.           )
  140.           ( a )
  141.         )
  142.       )
  143.       (rem a (* 2 pi))
  144.     )
  145.   )
  146.  
  147.   (defun _isAnnotative ( style / object annotx )
  148.     (and
  149.       (setq object (tblobjname "STYLE" style))
  150.       (setq annotx (cadr (assoc -3 (entget object '("AcadAnnotative")))))
  151.       (= 1 (cdr (assoc 1070 (reverse annotx))))
  152.     )
  153.   )
  154.  
  155.   (defun _uniquefuzz ( lst fuzz )
  156.     (if lst
  157.       (cons (car lst)
  158.         (_uniquefuzz
  159.           (vl-remove-if '(lambda ( x ) (equal x (car lst) fuzz)) (cdr lst)) fuzz
  160.         )
  161.       )
  162.     )
  163.   )
  164.  
  165.   (setq ts
  166.     (/ (getvar 'textsize)
  167.       (if (_isAnnotative (getvar 'textstyle))
  168.         (cond ( (getvar 'cannoscalevalue) ) ( 1.0 )) 1.0
  169.       )
  170.     )
  171.   )
  172.  
  173.   (_StartUndo acdoc)
  174.  
  175.   (vla-getBoundingBox (setq o (vlax-ename->vla-object e)) 'll 'ur)
  176.  
  177.   (mapcar '(lambda ( x ) (set x (vlax-safearray->list (eval x)))) '(ll ur))
  178.  
  179.   (if
  180.     (setq l
  181.       (_sortbyparam e
  182.         (_uniquefuzz
  183.           (apply 'append
  184.             (repeat
  185.               (setq i
  186.                 (sslength
  187.                   (ssdel e
  188.                     (setq ss
  189.                       (ssget "_C" (trans ur 0 1) (trans ll 0 1) '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))
  190.                     )
  191.                   )
  192.                 )
  193.               )
  194.               (setq l
  195.                 (cons
  196.                   (_groupbynum
  197.                     (vlax-invoke o 'intersectwith
  198.                       (vlax-ename->vla-object (ssname ss (setq i (1- i)))) acextendnone
  199.                     )
  200.                     3
  201.                   )
  202.                   l
  203.                 )
  204.               )
  205.             )
  206.           )
  207.           1e-8
  208.         )
  209.       )
  210.     )
  211.       (progn
  212.         (or
  213.           (setq l (cons (vlax-curve-getStartPoint e) l))
  214.         )
  215.         (or
  216.           (equal (vlax-curve-getEndParam e) (vlax-curve-getParamatPoint e (last l)) 0.001)
  217.           (setq l (append l (list (vlax-curve-getEndPoint e))))
  218.         )
  219.       )
  220.       (setq c l)
  221.     )
  222.       (setq l (list (vlax-curve-getStartPoint e)) c l)
  223.     )
  224.   )
  225.  
  226.   (while (cadr l) (setq x (car l) y (cadr l) l (cdr l))
  227.     (setq m
  228.         (/ (+ (vlax-curve-getDistatPoint e y) (vlax-curve-getDistAtPoint e x)) 2.)
  229.       )
  230.     )
  231.     (setq d
  232.       (abs
  233.       )
  234.     )
  235.     (setq a
  236.       (angle '(0. 0. 0.)
  237.       )
  238.     )
  239.     (setq ta (_makereadable a))
  240.  
  241.     (setq to (vla-AddText acspc (rtos d) (vlax-3D-point '(0. 0. 0.)) ts))
  242.     (vla-put-Alignment to acAlignmentMiddleCenter)
  243.     (vla-put-TextAlignmentPoint to (vlax-3D-point (polar m (+ ta (/ pi 2.)) (* 1.1 ts))))
  244.     (vla-put-rotation to ta)    
  245.   )
  246.  
  247.     (progn
  248.       (if (= 1 (length c)) (setq c (append c c)))
  249.       (setq d
  250.         (+
  251.           (setq d1 (vlax-curve-getDistatPoint e (car c)))
  252.         )
  253.       )                  
  254.       (setq m
  255.           (if (< d1 (setq da (/ (+ d1 d2) 2.)))
  256.             (setq da (- (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) (- da d1)))
  257.             (setq da (- da d2))
  258.           )
  259.         )
  260.       )
  261.       (setq a
  262.         (angle '(0. 0. 0.)
  263.         )
  264.       )
  265.       (setq ta (_makereadable a))
  266.  
  267.       (setq to (vla-AddText acspc (rtos d) (vlax-3D-point '(0. 0. 0.)) ts))
  268.       (vla-put-Alignment to acAlignmentMiddleCenter)
  269.       (vla-put-TextAlignmentPoint to (vlax-3D-point (polar m (+ ta (/ pi 2.)) (* 1.1 ts))))
  270.       (vla-put-rotation to ta)
  271.     )
  272.   )
  273.  
  274.   (_EndUndo acdoc)
  275.   (princ)
  276. )
  277.  
  278. ;;------------------------------------------------------------;;
  279.  
  280. (princ "\n:: IntLen.lsp | Version 1.4 | © Lee Mac 2011 www.lee-mac.com ::")
  281. (princ "\n:: Type \"IntLen\" or \"IntLenM\" to Invoke ::")
  282.  
  283. ;;------------------------------------------------------------;;
  284. ;;                         End of File                        ;;
  285. ;;------------------------------------------------------------;;
  286.  

PM

  • Guest
Re: Help with lisp - intersections dimension
« Reply #1 on: September 19, 2021, 06:11:24 PM »
I think that i have to add in the code something like this

Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "x" (list (cons 8 "DR_LINES"))))
  2.  
Can any one help?

I know that there is an option to select multyple lines with INTLENM but if searching for something faster

Thanks
« Last Edit: September 19, 2021, 06:27:11 PM by PM »

BIGAL

  • Swamp Rat
  • Posts: 1410
  • 40 + years of using Autocad
Re: Help with lisp - intersections dimension
« Reply #2 on: September 19, 2021, 07:53:12 PM »
Have you looked at (ssget "F" pts you would pick the white line it will then find all the orange lines and get there intersection point, making a list and sort on dist from end point of white line so in correct order then just do dimension.

After saying all that there is a quickdimension command came across it the other day it was ????? cant remember.
A man who never made a mistake never made anything

PM

  • Guest
Re: Help with lisp - intersections dimension
« Reply #3 on: September 20, 2021, 04:53:21 AM »
Can any one fix it?

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1410
  • 40 + years of using Autocad
Re: Help with lisp - intersections dimension
« Reply #4 on: September 20, 2021, 09:32:20 PM »
What part of the big hint "quick dimension" did you not understand. Does what you want.
A man who never made a mistake never made anything

PM

  • Guest
Re: Help with lisp - intersections dimension
« Reply #5 on: September 21, 2021, 02:56:46 AM »
Sory BIGAL.What quick dimension. I can not understand?

BIGAL

  • Swamp Rat
  • Posts: 1410
  • 40 + years of using Autocad
Re: Help with lisp - intersections dimension
« Reply #6 on: September 21, 2021, 09:44:06 PM »
QDIM if you had googled.
A man who never made a mistake never made anything