Author Topic: Increment blocks  (Read 2870 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7531
Increment blocks
« on: January 27, 2005, 03:46:45 PM »
I know I've seen this somewhere but can't find it.....

What I'm looking for is a routine that will allow me to set a number to start numbering  from (5,6,7,) as well as set a prefix (A5,A6,A7,) for each. then be able to select blocks (one by one) with attributes in a certain order and the routine fills in the attribute with information in the order they were picked. (ie..first picked block is A5 second A6 and so on....).

The attribute tag name will always be LATERALID.

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Increment blocks
« Reply #1 on: January 27, 2005, 08:33:37 PM »
Something like this?
Code: [Select]

(defun c:lat# (/ ent entlist newnext newnum newpre next)
  (if (not *latnum*)(setq *latnum* 1))
  (if (not *latpre*)(setq *latpre* "A"))
  (setq newpre (getstring (strcat "\nLateral prefix (" *latpre* "): ")))
  (if (not (eq newpre ""))(setq *latpre* newpre))
  (setq newnum (getint (strcat "\nNumber to start with (" (itoa *latnum*) "): ")))
  (if newnum (setq *latnum* newnum))
  (while (setq ent (car (entsel "\nSelect next lateral: ")))
    (setq entlist (entget ent))
    (if (and (eq (cdr (assoc 0 entlist)) "INSERT")
    (= (cdr (assoc 66 entlist)) 1)
    )
      (progn
(setq next (entget (entnext ent)))
(setq newnext (subst (cons 1 (strcat *latpre* (itoa *latnum*))) (assoc 1 next) next))
(entmod newnext)
(entupd (cdr (assoc -1 newnext)))
(setq *latnum* (1+ *latnum*))
)
      )
    )
  (princ)
  )

ronjonp

  • Needs a day job
  • Posts: 7531
Increment blocks
« Reply #2 on: January 28, 2005, 09:06:25 AM »
Jeff,

You are the man. Thank you  :D  I really like the way it remembers where it was last. Thanks again.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Increment blocks
« Reply #3 on: January 28, 2005, 01:18:32 PM »
You're welcome, BUT......I should point out that I didn't include any error traps and the big thing is that if you select ANY block with attributes it will modify the first attribute in that block. Should probably add this to the (if (and .... portion:
Code: [Select]

(if (and (eq (cdr (assoc 0 entlist)) "INSERT")
        (= (cdr (assoc 66 entlist)) 1)
        (eq (cdr (assoc 2  entlist))) "YOURBLOCKNAME");;change this to suit
        )


Jeff

ronjonp

  • Needs a day job
  • Posts: 7531
Increment blocks
« Reply #4 on: January 28, 2005, 04:56:42 PM »
Jeff,

The program is great right now. tThe blocks I am selecting have 3 different names so it works out well. How did you force the first attribute to be filled out?

Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Increment blocks
« Reply #5 on: January 28, 2005, 05:19:05 PM »
Well, I just made the assumption that there is only one attribute in the block, so using (entnext ent) returns the first (and only in my assumption) attribute. If you need this to work with blocks that have multiple attributes it would need to be reworked to step through all of them looking for the one with the tagstring "LATERALID".