Author Topic: Increase number of attribute block along a polyline  (Read 621 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Bull Frog
  • Posts: 403
Increase number of attribute block along a polyline
« on: January 11, 2023, 12:44:12 PM »
Hi, I am using this code to increase number of attribute block along a polyline. Some times I have situations like the example in the *.dwg file that I want to keep some numbers and increase number only to blocks without number.

The change i want to do is to choose pick the first emply point and then give the start number for example 20 and add 21,22,23.....etc only to blocks without number on the selected polyline. Is any way to do this?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )
  2.  
  3.   (defun ListClockwise-p ( lst / z vlst )
  4.     (vl-catch-all-apply 'minusp
  5.       (list
  6.         (if
  7.           (not
  8.             (equal 0.0
  9.               (setq z
  10.                 (apply '+
  11.                   (mapcar
  12.                     (function
  13.                       (lambda (u v)
  14.                         (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
  15.                       )
  16.                     )
  17.                     (setq vlst
  18.                       (mapcar
  19.                         (function
  20.                           (lambda (a b) (mapcar '- b a))
  21.                         )
  22.                         (mapcar (function (lambda (x) (car lst))) lst)
  23.                         (cdr (reverse (cons (car lst) (reverse lst))))
  24.                       )
  25.                     )
  26.                     (cdr (reverse (cons (car vlst) (reverse vlst))))
  27.                   )
  28.                 )
  29.               ) 1e-6
  30.             )
  31.           )
  32.           z
  33.           (progn
  34.             (prompt "\nChecked vectors are colinear - unable to determine clockwise-p of list")
  35.             nil
  36.           )
  37.         )
  38.       )
  39.     )
  40.   )
  41.  
  42.   (setq osm (getvar 'osmode))
  43.   (setvar 'osmode 8)
  44.   (prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
  45.   (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
  46.   (setq lw (ssname ss 0))
  47.   (setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
  48.   (if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
  49.   (setq pt (getpoint "\nPick starting point : "))
  50.   (setq n (length vl))
  51.   (setq pr (getstring "\nSpecify prefix : : "))
  52.   (setq vl (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (cdr (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (append vl vl)))))))
  53.   ;(setq k 0)
  54.   (initget 6)  
  55.   (setq k (1- (cond ( (getint (strcat "\nSpecify start number <" (itoa 1) "> : "))) ( 1 ))))
  56.   (repeat n
  57.     (setq k (1+ k))
  58.     (setq v (car vl))
  59.    (setq bl
  60.   (ssname
  61.     (ssget
  62.       "_X"
  63.       (list
  64.         '(0 . "INSERT")
  65.         '(66 . 1)
  66.         '(-4 . "<,<,*")
  67.         (list 10 (+ (car v) 1e-6) (+ (cadr v) 1e-6) 0.0)
  68.         '(-4 . ">,>,*")
  69.         (list 10 (- (car v) 1e-6) (- (cadr v) 1e-6) 0.0)
  70.       )
  71.     )
  72.     0
  73.   )
  74. )
  75.     (setq att (entnext bl))
  76.     (entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
  77.     (entupd att)
  78.     (setq vl (cdr vl))
  79.   )
  80.   (setvar 'osmode osm)
  81.   (princ)
  82. )
  83.  


Thanks

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #1 on: January 11, 2023, 06:23:45 PM »
Is it possible to be done ?

Thanks

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #2 on: January 12, 2023, 12:45:50 PM »
Something like this, Is it possible to be done ?

Thanks

mhupp

  • Bull Frog
  • Posts: 233
Re: Increase number of attribute block along a polyline
« Reply #3 on: January 13, 2023, 12:18:08 AM »
getpropertyvalue & setpropertyvalue don't work with my version of BricsCAD so can't test this. But this should get you moving in the right direction.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:PTXT (/ i ss tag)
  2.   (setq i (getint "\nStarting Number: "))
  3.   (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  4.     (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
  5.       (if (and (setq tag (getpropertyvalue blk "POINT")) (eq "" tag))       ;if block has point attribuet and its blank
  6.         (progn
  7.           (setpropertyvalue blk "POINT" (rtos i 2 0))
  8.           (setq i (1+ i))
  9.         )
  10.         (princ "\"LINE NO\" Attribute not found.")
  11.       )
  12.     )
  13.   )
  14.   (princ)
  15. )

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #4 on: January 13, 2023, 12:30:35 PM »
Hi mhupp . Thanks for the replay. Is not possible to select the polyline, and pick the first point and search clockwise to find the empty number point and increase the number by the giving start number ?

Because with your code I have to select the points with one by one to have the correct numbers at the end. That's why I post the code to modify .

Thanks

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #5 on: January 21, 2023, 05:37:21 AM »
Any ideas?

thansk

BIGAL

  • Swamp Rat
  • Posts: 1138
  • 40 + years of using Autocad
Re: Increase number of attribute block along a polyline
« Reply #6 on: January 21, 2023, 06:42:19 PM »
You have asked for lots of stuff maybe have a go, but a solution when you pick a pline you can get all the vertice points so can step through them and check does it have a block and does it have a number, if not add number. It is a simple task to use ssget "WP" using the vertices point to make a little box and look for a particular block.

You asked for automation so the point number would say swap 25&26 to 26 25 as you walk around the pline way to many headaches to work out always go clockwise.

I still think need a pick pick as you need to control the 1st number pline then which one is next. So pick white start number 1, then blue then green all done.

Oh yeah need a rotate vertices in list so can set point 1 it does exist, also number CW or CCW.

You should add block and number not just add block then add numbers.
« Last Edit: January 21, 2023, 06:45:22 PM by BIGAL »
A man who never made a mistake never made anything

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #7 on: January 22, 2023, 11:10:38 AM »
Hi BIGAL. Thanks for the reply. I see that the dwg is not correct so I upload again in this post a correct one.

The polylines all the times will be counterclockwise and close. The increase of the numbers all the time must be clockwise.

In the example we have a big polyline (white color). With the code of post 1 I add the numbers of the vertex. Then i divide the polygon with two other polylines green and blue. The problem is to add the extra numbers fast. As I said in post 1

Quote
I want to keep some numbers and increase number only to blocks without number.

The change Iwant to do is to choose pick the first emply point and then give the start number for example 20 and add 21,22,23.....etc only to blocks without number on the selected polyline. Is any way to do this?

Thanks

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #8 on: January 28, 2023, 04:39:12 AM »
Any ideas?

Thanks

BIGAL

  • Swamp Rat
  • Posts: 1138
  • 40 + years of using Autocad
Re: Increase number of attribute block along a polyline
« Reply #9 on: January 28, 2023, 05:49:43 PM »
This will reverse the pline points from a list so will be CW list of points. Then look at each point and check does a number exist. next version.

Code: [Select]
;; get closed polygon's area

(defun ss-pts2area  (l)
(/ (apply (function +)
            (mapcar (function (lambda (x y)
                                (- (* (car x) (cadr y)) (* (car y) (cadr x)))))
                    (cons (last l) l)
                    l))
2.)
)

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

(if (> (ss-pts2area co-ord) 0)
(setq co-ord (reverse co-ord))
)
A man who never made a mistake never made anything

PM

  • Bull Frog
  • Posts: 403
Re: Increase number of attribute block along a polyline
« Reply #10 on: January 31, 2023, 05:31:14 AM »
Hi  BIGAL. Thanks for the reply. I can not understand haw to use your code.  I have to delete something in the first code and add it ?

Thanks