Author Topic: Renamber block attributes along polyline - help with a lisp  (Read 1836 times)

0 Members and 2 Guests are viewing this topic.

pedroantonio

  • Guest
Renamber block attributes along polyline - help with a lisp
« on: February 23, 2019, 11:46:43 AM »
Hi am using this lisp code to renumber block attributes along polyline. This code gives only one option, to start from umber 1 every time. I need to haqve the option to give the start number. For example to start from number 125 etc

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 "\n\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.   (repeat n
  55.     (setq k (1+ k))
  56.     (setq v (car vl))
  57.    (setq bl
  58.   (ssname
  59.     (ssget
  60.       "_X"
  61.       (list
  62.         '(0 . "INSERT")
  63.         '(66 . 1)
  64.         '(-4 . "<,<,*")
  65.         (list 10 (+ (car v) 1e-6) (+ (cadr v) 1e-6) 0.0)
  66.         '(-4 . ">,>,*")
  67.         (list 10 (- (car v) 1e-6) (- (cadr v) 1e-6) 0.0)
  68.       )
  69.     )
  70.     0
  71.   )
  72. )
  73.     (setq att (entnext bl))
  74.     (entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
  75.     (entupd att)
  76.     (setq vl (cdr vl))
  77.   )
  78.   (setvar 'osmode osm)
  79.   (princ)
  80. )
  81.  

Thanks

Dlanor

  • Bull Frog
  • Posts: 263
Re: Renamber block attributes along polyline - help with a lisp
« Reply #1 on: February 23, 2019, 12:43:41 PM »
Try replacing this

Code - Auto/Visual Lisp: [Select]
  1. (setq k 0)

with this

Code - Auto/Visual Lisp: [Select]
  1.       (initget 6)  
  2.       (setq k (1- (cond ( (getint (strcat "\nEnter Start Number <" (itoa 1) "> : "))) ( 1 ))))
  3.  

pedroantonio

  • Guest
Re: Renamber block attributes along polyline - help with a lisp
« Reply #2 on: February 24, 2019, 11:52:03 AM »
Thank you Dlanor