Author Topic: increase number of attribute block along a polyline  (Read 8257 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
increase number of attribute block along a polyline
« on: May 10, 2014, 03:08:42 AM »
Hi,Is it possible to increase number of attribute block along a polyline allways in clockwise direction. Look the attach test2.dwg

Thanks

reltro

  • Guest
Re: increase number of attribute block along a polyline
« Reply #1 on: May 10, 2014, 07:34:15 AM »
Hey...
its possible for sure...

Start with PseudoCode:
1. Select Polyline
2. Pick the Point
3. Get the Vertices of the Polyline
4. Sort them, so that the vertices nearest to the Point in 2. is the first.
5. reverse or not the list from step 4. to be clockwise
6. insert BlockReference on each vertex
7. change Attribute value

An approach...
Code: [Select]
(defun From1to4 ( / vertices entselOut PickPoint dist StartIndex)
   (vl-load-com)
   (setq   entselOut   (entsel "Pick a polyline near to the startpoint")
         PickPoint   (cadr entselOut)
         vertices   (mapcar
                     'cdr
                     (vl-remove-if-not
                        '(lambda (a / )
                           (= (car a) 10)
                        )
                        (entget (car entselOut))
                     )
                  )
         StartIndex   (vl-position
                     (apply
                        'min
                        (setq dist
                           (mapcar
                              '(lambda (a / )
                                 (distance PickPoint a)
                              )
                              vertices
                           )
                        )
                     )
                     dist
                  )
   )
   
   (repeat StartIndex (setq vertices (reverse (cons (car vertices) (reverse (cdr vertices))))))
)

Greets reltro

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #2 on: May 10, 2014, 10:13:25 AM »
Hi reltro

Quote
1. Select Polyline
2. Pick the Point
3. Get the Vertices of the Polyline
4. Sort them, so that the vertices nearest to the Point in 2. is the first.
5. reverse or not the list from step 4. to be clockwise
6. insert BlockReference on each vertex
7. change Attribute value

this is exactly what i am looking for , but this code after select the polyline stops ....

Thanks

reltro

  • Guest
Re: increase number of attribute block along a polyline
« Reply #3 on: May 10, 2014, 10:28:11 AM »
sure it stops, all has to have an end ;)

look at his name! its called: "From1to4"
its just a Part...

Try coding yourself!

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #4 on: May 10, 2014, 10:38:17 AM »
Thanks you for your time reltro

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #5 on: May 14, 2014, 05:12:40 AM »
Can anyone help

Thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ChrisCarlson

  • Guest
Re: increase number of attribute block along a polyline
« Reply #7 on: May 14, 2014, 08:05:58 AM »
Where have you left off? What part are you stuck on?

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #8 on: May 14, 2014, 12:17:26 PM »
The polyline have allready attribiute blocks on it .The only thing i want to do is to increase the value of attribute block along a polyline clockwise all the times like this

1,2,3,4,5,6,7,8,...............
Or
Giving a letter first like
K1,K2,K3,K4,..........................
T1,T2,T3,.............................

1) first select the polyline .(The polyline have allready attribiuts on it)
2) Give or not a letter
3)Pick the first point (the point that will have the number 1 or K1 etc...)
4) increase the value of attribute block along a polyline clockwise 

ChrisCarlson

  • Guest
Re: increase number of attribute block along a polyline
« Reply #9 on: May 14, 2014, 04:24:06 PM »
I'm not sure how to gather the coordinates in a clockwise fashion but if it's not many attributes you can just manually select them one at a time?

Code: [Select]
(setq num_seq
    (getint
      (strcat "\nStarting number <"
         (itoa num_seq)">: ")))
(car (nentsel "\n--- SELECT ATTRIBUTE ---- ")))
(if (and curText ;
                 (setq curData (entget curText))
                 (= (cdr (assoc 0 curData)) "ATTRIB")
)
         (progn
            (vla-put-TextString
(vlax-ename->vla-object curText)curStr)
(setq num_seq(1+ num_seq))
         )
        (princ "\n--- THIS IS NOT AN ATTRIBUTE ---- ")

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #10 on: May 14, 2014, 04:31:26 PM »
Thank you ChrisCarlson but i want to  increase the value of attribute block along a polyline clockwise  automaticaly all. Select only the first ,because i have a lot of points to rename...

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #11 on: May 16, 2014, 01:28:37 AM »
is it possible to  increase the value of attribute block along a polyline clockwise  automaticaly. and how?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: increase number of attribute block along a polyline
« Reply #12 on: May 16, 2014, 08:56:53 AM »
is it possible to  increase the value of attribute block along a polyline clockwise  automaticaly. and how?

Perhaps a bit of searching will lead you in the right direction
http://goo.gl/M9O64C
http://goo.gl/GhIaYY

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #13 on: May 16, 2014, 04:07:16 PM »
can anyone help with the code ?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: increase number of attribute block along a polyline
« Reply #14 on: May 16, 2014, 04:09:27 PM »
is it possible to  increase the value of attribute block along a polyline clockwise  automaticaly. and how?

Perhaps a bit of searching will lead you in the right direction
http://goo.gl/M9O64C
http://goo.gl/GhIaYY

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #15 on: May 26, 2014, 03:20:23 AM »
I find this lisp but renale all attribiute poins radom. CAn any one help?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:AutoInc (/ _x _y _gbn _ss2l _0 r ss i lat long)
  2.   ;; Alan J. Thompson, 03.26.10
  3.  
  4.  
  5.   (setq _x (lambda (e) (car (cdr (assoc 10 (entget e))))))
  6.   (setq _y (lambda (e) (cadr (cdr (assoc 10 (entget e))))))
  7.   (setq _gbn (lambda (L # / n g f)
  8.                (setq n -1)
  9.                (while (> (1- (length L)) n)
  10.                  (repeat # (setq g (cons (nth (setq n (1+ n)) L) g)))
  11.                  (setq f (cons (reverse g) f)
  12.                        g nil
  13.                  ) ;_ setq
  14.                ) ;_ while
  15.                (reverse f)
  16.              ) ;_ lambda
  17.   ) ;_ setq
  18.   (setq _ss2l (lambda (x / e i l)
  19.                 (if (eq (type x) 'PICKSET)
  20.                   (progn (setq i -1)
  21.                          (while (setq e (ssname x (setq i (1+ i))))
  22.                            (setq l (cons e l))
  23.                          ) ;_ while
  24.                          l
  25.                   ) ;_ progn
  26.                 ) ;_ if
  27.               ) ;_ lambda
  28.   ) ;_ setq
  29.   (setq _0 (lambda (l) (vl-position (cdr (assoc 0 (entget x))) l)))
  30.  
  31.   (or *AI:LR* (setq *AI:LR* "Right"))
  32.   (or *AI:TB* (setq *AI:TB* "Top"))
  33.  
  34.   (cond
  35.     ((and (setq r (getint "\nSpecify number of rows: "))
  36.           (not (initget 0 "Left Right"))
  37.           (setq *AI:LR* (cond
  38.                           ((getkword (strcat "\nSort from Left or Right? [Left/Right] <"
  39.                                              *AI:LR*
  40.                                              ">: "
  41.                                      ) ;_ strcat
  42.                            ) ;_ getkword
  43.                           )
  44.                           (*AI:LR*)
  45.                         ) ;_ cond
  46.           ) ;_ setq
  47.           (not (initget 0 "Top Bottom"))
  48.           (setq *AI:TB* (cond
  49.                           ((getkword (strcat "\nSort from Top or Bottom? [Top/Bottom] <"
  50.                                              *AI:TB*
  51.                                              ">: "
  52.                                      ) ;_ strcat
  53.                            ) ;_ getkword
  54.                           )
  55.                           (*AI:TB*)
  56.                         ) ;_ cond
  57.           ) ;_ setq
  58.           (setq ss (_ss2l (ssget "_:L"
  59.                                  '((-4 . "<OR")
  60.                                    (0 . "MTEXT,TEXT")
  61.                                    (-4 . "<AND")
  62.                                    (0 . "INSERT")
  63.                                    (66 . 1)
  64.                                    (-4 . "AND>")
  65.                                    (-4 . "OR>")
  66.                                   )
  67.                           ) ;_ ssget
  68.                    ) ;_ _ss2l
  69.           ) ;_ setq
  70.  
  71.      ) ;_ and
  72.  
  73.      (setq lat  (if (eq *AI:LR* "Left")
  74.                   <
  75.                   >
  76.                 ) ;_ if
  77.            long (if (eq *AI:TB* "Top")
  78.                   >
  79.                   <
  80.                 ) ;_ if
  81.      ) ;_ setq
  82.  
  83.      (setq i 0)
  84.      (foreach x
  85.               (apply
  86.                 (function append)
  87.                 (mapcar
  88.                   (function (lambda (l) (vl-sort l (function (lambda (a b) (long (_y a) (_y b)))))))
  89.                   (mapcar (function (lambda (y) (vl-remove nil y)))
  90.                           (_gbn (vl-sort ss (function (lambda (a b) (lat (_x a) (_x b))))) r)
  91.                   ) ;_ mapcar
  92.                 ) ;_ mapcar
  93.               ) ;_ apply
  94.  
  95.        (cond
  96.          ((_0 '("MTEXT" "TEXT"))
  97.           (vl-catch-all-apply
  98.             (function vla-put-textstring)
  99.             (list (vlax-ename->vla-object x) (itoa (setq i (1+ i))))
  100.           ) ;_ vl-catch-all-apply
  101.          )
  102.          ((_0 '("INSERT"))
  103.           (vl-catch-all-apply
  104.             (function vla-put-textstring)
  105.             (list (car (vlax-invoke (vlax-ename->vla-object x) (function GetAttributes)))
  106.                   (itoa (setq i (1+ i)))
  107.             ) ;_ list
  108.           ) ;_ vl-catch-all-apply
  109.          )
  110.        ) ;_ cond
  111.  
  112.  
  113.      ) ;_ foreach
  114.     ) ;_ cond
  115.   ) ;_ cond
  116.   (princ)
  117. ) ;_ defun
  118.  
  119.  

Thanks

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #16 on: May 31, 2014, 01:31:57 PM »
any other options

Thanks

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #17 on: August 03, 2014, 11:27:25 AM »
Any ideas

Code - Auto/Visual Lisp: [Select]
  1. (defun c:AutoInc (/ _x _y _gbn _ss2l _0 r ss i lat long)
  2.   ;; Alan J. Thompson, 03.26.10
  3.  
  4.  
  5.   (setq _x (lambda (e) (car (cdr (assoc 10 (entget e))))))
  6.   (setq _y (lambda (e) (cadr (cdr (assoc 10 (entget e))))))
  7.   (setq _gbn (lambda (L # / n g f)
  8.                (setq n -1)
  9.                (while (> (1- (length L)) n)
  10.                  (repeat # (setq g (cons (nth (setq n (1+ n)) L) g)))
  11.                  (setq f (cons (reverse g) f)
  12.                        g nil
  13.                  ) ;_ setq
  14.                ) ;_ while
  15.                (reverse f)
  16.              ) ;_ lambda
  17.   ) ;_ setq
  18.   (setq _ss2l (lambda (x / e i l)
  19.                 (if (eq (type x) 'PICKSET)
  20.                   (progn (setq i -1)
  21.                          (while (setq e (ssname x (setq i (1+ i))))
  22.                            (setq l (cons e l))
  23.                          ) ;_ while
  24.                          l
  25.                   ) ;_ progn
  26.                 ) ;_ if
  27.               ) ;_ lambda
  28.   ) ;_ setq
  29.   (setq _0 (lambda (l) (vl-position (cdr (assoc 0 (entget x))) l)))
  30.  
  31.   (or *AI:LR* (setq *AI:LR* "Right"))
  32.   (or *AI:TB* (setq *AI:TB* "Top"))
  33.  
  34.   (cond
  35.     ((and (setq r (getint "\nSpecify number of rows: "))
  36.           (not (initget 0 "Left Right"))
  37.           (setq *AI:LR* (cond
  38.                           ((getkword (strcat "\nSort from Left or Right? [Left/Right] <"
  39.                                              *AI:LR*
  40.                                              ">: "
  41.                                      ) ;_ strcat
  42.                            ) ;_ getkword
  43.                           )
  44.                           (*AI:LR*)
  45.                         ) ;_ cond
  46.           ) ;_ setq
  47.           (not (initget 0 "Top Bottom"))
  48.           (setq *AI:TB* (cond
  49.                           ((getkword (strcat "\nSort from Top or Bottom? [Top/Bottom] <"
  50.                                              *AI:TB*
  51.                                              ">: "
  52.                                      ) ;_ strcat
  53.                            ) ;_ getkword
  54.                           )
  55.                           (*AI:TB*)
  56.                         ) ;_ cond
  57.           ) ;_ setq
  58.           (setq ss (_ss2l (ssget "_:L"
  59.                                  '((-4 . "<OR")
  60.                                    (0 . "MTEXT,TEXT")
  61.                                    (-4 . "<AND")
  62.                                    (0 . "INSERT")
  63.                                    (66 . 1)
  64.                                    (-4 . "AND>")
  65.                                    (-4 . "OR>")
  66.                                   )
  67.                           ) ;_ ssget
  68.                    ) ;_ _ss2l
  69.           ) ;_ setq
  70.  
  71.      ) ;_ and
  72.  
  73.      (setq lat  (if (eq *AI:LR* "Left")
  74.                   <
  75.                   >
  76.                 ) ;_ if
  77.            long (if (eq *AI:TB* "Top")
  78.                   >
  79.                   <
  80.                 ) ;_ if
  81.      ) ;_ setq
  82.  
  83.      (setq i 0)
  84.      (foreach x
  85.               (apply
  86.                 (function append)
  87.                 (mapcar
  88.                   (function (lambda (l) (vl-sort l (function (lambda (a b) (long (_y a) (_y b)))))))
  89.                   (mapcar (function (lambda (y) (vl-remove nil y)))
  90.                           (_gbn (vl-sort ss (function (lambda (a b) (lat (_x a) (_x b))))) r)
  91.                   ) ;_ mapcar
  92.                 ) ;_ mapcar
  93.               ) ;_ apply
  94.  
  95.        (cond
  96.          ((_0 '("MTEXT" "TEXT"))
  97.           (vl-catch-all-apply
  98.             (function vla-put-textstring)
  99.             (list (vlax-ename->vla-object x) (itoa (setq i (1+ i))))
  100.           ) ;_ vl-catch-all-apply
  101.          )
  102.          ((_0 '("INSERT"))
  103.           (vl-catch-all-apply
  104.             (function vla-put-textstring)
  105.             (list (car (vlax-invoke (vlax-ename->vla-object x) (function GetAttributes)))
  106.                   (itoa (setq i (1+ i)))
  107.             ) ;_ list
  108.           ) ;_ vl-catch-all-apply
  109.          )
  110.        ) ;_ cond
  111.  
  112.  
  113.      ) ;_ foreach
  114.     ) ;_ cond
  115.   ) ;_ cond
  116.   (princ)
  117. ) ;_ defun
  118.  
  119.  
  120.  

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #18 on: August 05, 2014, 02:48:41 AM »
Hi .I am looking for a lisp to do this

The polyline have allready attribiute blocks on it .The only thing i want to do is to increase the value of attribute block along a polyline clockwise all the times like this

1,2,3,4,5,6,7,8,...............
Or
Giving a letter first like
K1,K2,K3,K4,..........................
T1,T2,T3,.............................

1) first select the polyline .(The polyline have allready attribiuts on it)
2) Give or not a letter
3)Pick the first point (the point that will have the number 1 or K1 etc...)
4) increase the value of attribute block along a polyline clockwise 

Any ideas ?

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: increase number of attribute block along a polyline
« Reply #19 on: August 05, 2014, 06:10:21 AM »
Try this simple one :

Code: [Select]
(defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )

  (defun ListClockwise-p ( lst / z vlst )
    (vl-catch-all-apply 'minusp
      (list
        (if
          (not
            (equal 0.0
              (setq z
                (apply '+
                  (mapcar
                    (function
                      (lambda (u v)
                        (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
                      )
                    )
                    (setq vlst
                      (mapcar
                        (function
                          (lambda (a b) (mapcar '- b a))
                        )
                        (mapcar (function (lambda (x) (car lst))) lst)
                        (cdr (reverse (cons (car lst) (reverse lst))))
                      )
                    )
                    (cdr (reverse (cons (car vlst) (reverse vlst))))
                  )
                )
              ) 1e-6
            )
          )
          z
          (progn
            (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
            nil
          )
        )
      )
    )
  )

  (setq osm (getvar 'osmode))
  (setvar 'osmode 8)
  (prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
  (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
  (setq lw (ssname ss 0))
  (setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
  (if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
  (setq pt (getpoint "\nPick starting point : "))
  (setq n (length vl))
  (setq pr (getstring "\nSpecify prefix : "))
  (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)))))))
  (setq k 0)
  (repeat n
    (setq k (1+ k))
    (setq v (car vl))
    (setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))
    (setq att (entnext bl))
    (entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
    (entupd att)
    (setq vl (cdr vl))
  )
  (setvar 'osmode osm)
  (princ)
)

[EDIT : LWPOLYLINE and its ATTRIBUTED BLOCKS set at each vertex must be completely visible on screen for routine to operate as should...]
« Last Edit: August 05, 2014, 06:42:40 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #20 on: August 05, 2014, 10:00:36 AM »
hi ribarm. I think that works fine. I will test it for a few day .If i find any bug i will tell you.

Thanks   :laugh:

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #21 on: August 05, 2014, 11:27:28 AM »
hi ribarm. Same times gives me this error message and the lisp stop
; error: bad argument type: lselsetp nil

Why ?

Look the test file . Why in this file the code didn't work?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: increase number of attribute block along a polyline
« Reply #22 on: August 05, 2014, 11:33:34 AM »
hi ribarm. Same times gives me this error message and the lisp stop
; error: bad argument type: lselsetp nil

Why ?

Look the test file . Why in this file the code didn't work?


http://www.lee-mac.com/debugvlide.html

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #23 on: August 05, 2014, 11:53:19 AM »
Hi ronjonp . In vlisp editor the code have no errors ...

But in the test,dwg file didn't work properly. Look the test.dwg file and test the code and you will understand.

Thanks

ronjonp

  • Needs a day job
  • Posts: 7529
Re: increase number of attribute block along a polyline
« Reply #24 on: August 05, 2014, 12:21:33 PM »
You have to make sure that you don't miss your selection the way the code is written. Generally an if statement is included to verify that all items needed exist before actually executing the code.

(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MORITZK

  • Mosquito
  • Posts: 18
Re: increase number of attribute block along a polyline
« Reply #25 on: August 05, 2014, 12:28:46 PM »
The code works without failure with test dwg.
Moritz

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #26 on: August 05, 2014, 05:42:24 PM »
Quote
The code works without failure with test dwg.
Moritz

I use Autocad 2010. When i run the code rename 2 or 3 first points and then stop. The example is the test.dwg

Quote
You have to make sure that you don't miss your selection the way the code is written. Generally an if statement is included to verify that all items needed exist before actually executing the code.

(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))

I load all my lisp files when the autocad start , but i try to load the lisp file after i draw the points and the polyline and i have the same problem
When i run the code rename 2 or 3 first points and then stop. The example is the test.dwg

Any ideas?

Thanks

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: increase number of attribute block along a polyline
« Reply #27 on: August 06, 2014, 04:28:31 AM »
Four ideas. All related to this line of code:
Code: [Select]
(setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))1.
If some of the blocks are off-screen ssget will/may not work.
2.
Since there is no entity in the center of the circle inside the block, and a single point is used to select the block, the current pickbox and zoom settings will influence the result of ssget.
3.
The draworder may also play a part. If the polyline is 'on top' ssget will return nil.
4.
For the last two reasons and to allow for tolerances, using a small crossing to select the blocks is better. Alternatively a fence could be used to select all the blocks at once.

It would of course be much easier and more reliable to change the atributes while the blocks are being inserted...

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #28 on: August 06, 2014, 05:11:25 AM »
thank you roy_043 for the help.

To avoid all this problem is it possible to add two lines to this code
when select the polyline
a)zoom extend the drawing
b)sent back the polyline ,and then rename the blocks

thanks
« Last Edit: August 06, 2014, 05:19:46 AM by Topographer »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: increase number of attribute block along a polyline
« Reply #29 on: August 06, 2014, 08:51:13 AM »
Of course it's possible. Let's see if you can help yourself a bit.
Here are the lines of code you need, plug them in where you need them.
Code: [Select]
(command "_.zoom" "_extents")
(command "_.draworder" (ssget "_X" '((0 . "~Insert"))) "" "_back")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: increase number of attribute block along a polyline
« Reply #30 on: August 06, 2014, 09:22:05 AM »
Replacing this line:
Code: [Select]
(setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))With:
Code: [Select]
(setq bl
  (ssname
    (ssget
      "_X"
      (list
        '(0 . "INSERT")
        '(66 . 1)
        '(-4 . "<,<,*")
        (list 10 (+ (car v) 1e-6) (+ (cadr v) 1e-6) 0.0)
        '(-4 . ">,>,*")
        (list 10 (- (car v) 1e-6) (- (cadr v) 1e-6) 0.0)
      )
    )
    0
  )
)
May solve all issues I have mentioned. But the program will probably be slower.

BTW: there actually is an entity in the center of the circle.

pedroantonio

  • Guest
Re: increase number of attribute block along a polyline
« Reply #31 on: August 06, 2014, 10:22:33 AM »
Thanks you roy_043 and ronjonp and the two solutions works fine

A) With zoom extend

Code: [Select]
(defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )

  (defun ListClockwise-p ( lst / z vlst )
    (vl-catch-all-apply 'minusp
      (list
        (if
          (not
            (equal 0.0
              (setq z
                (apply '+
                  (mapcar
                    (function
                      (lambda (u v)
                        (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
                      )
                    )
                    (setq vlst
                      (mapcar
                        (function
                          (lambda (a b) (mapcar '- b a))
                        )
                        (mapcar (function (lambda (x) (car lst))) lst)
                        (cdr (reverse (cons (car lst) (reverse lst))))
                      )
                    )
                    (cdr (reverse (cons (car vlst) (reverse vlst))))
                  )
                )
              ) 1e-6
            )
          )
          z
          (progn
            (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
            nil
          )
        )
      )
    )
  )

  (setq osm (getvar 'osmode))
  (setvar 'osmode 8)
  (prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
  (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
  (setq lw (ssname ss 0))
  (setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
  (if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
  (setq pt (getpoint "\nPick starting point : "))
  (setq n (length vl))
(command "_.zoom" "_extents")
(command "_.draworder" (ssget "_X" '((0 . "~Insert"))) "" "_back")
  (setq pr (getstring "\nSpecify prefix : "))
  (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)))))))
  (setq k 0)
  (repeat n
    (setq k (1+ k))
    (setq v (car vl))
    (setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))
    (setq att (entnext bl))
    (entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
    (entupd att)
    (setq vl (cdr vl))
  )
  (setvar 'osmode osm)
  (princ)
)


b) Change (setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))

Code: [Select]
(defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )

  (defun ListClockwise-p ( lst / z vlst )
    (vl-catch-all-apply 'minusp
      (list
        (if
          (not
            (equal 0.0
              (setq z
                (apply '+
                  (mapcar
                    (function
                      (lambda (u v)
                        (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
                      )
                    )
                    (setq vlst
                      (mapcar
                        (function
                          (lambda (a b) (mapcar '- b a))
                        )
                        (mapcar (function (lambda (x) (car lst))) lst)
                        (cdr (reverse (cons (car lst) (reverse lst))))
                      )
                    )
                    (cdr (reverse (cons (car vlst) (reverse vlst))))
                  )
                )
              ) 1e-6
            )
          )
          z
          (progn
            (prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
            nil
          )
        )
      )
    )
  )

  (setq osm (getvar 'osmode))
  (setvar 'osmode 8)
  (prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
  (setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
  (setq lw (ssname ss 0))
  (setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
  (if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
  (setq pt (getpoint "\nPick starting point : "))
  (setq n (length vl))
  (setq pr (getstring "\nSpecify prefix : "))
  (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)))))))
  (setq k 0)
  (repeat n
    (setq k (1+ k))
    (setq v (car vl))
(setq bl
  (ssname
    (ssget
      "_X"
      (list
        '(0 . "INSERT")
        '(66 . 1)
        '(-4 . "<,<,*")
        (list 10 (+ (car v) 1e-6) (+ (cadr v) 1e-6) 0.0)
        '(-4 . ">,>,*")
        (list 10 (- (car v) 1e-6) (- (cadr v) 1e-6) 0.0)
      )
    )
    0
  )
)
    (setq att (entnext bl))
    (entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
    (entupd att)
    (setq vl (cdr vl))
  )
  (setvar 'osmode osm)
  (princ)
)

Thank you ...  :-D