I'm using a variation on a problem that was kindly solved for me to do another task and it works on testing but fails with a restart with this error
PROGRAM ABORTED bad argument type: lentityp nil
Also how on earth do you link to a dwg file so I can show the dwg file I am using as a test bed?
;Increment Selected Circuits
(defun restore () ;restore variables
(setq *error* olderr)
(princ)
)
(defun trap (er) ;error trapping
(princ "\nOOPS PROGRAM ABORTED ")
(princ er)
(setq *error* olderr)
(princ)
)
(defun c:incst (/ ss ct sl e1 e2 ck stc inc)
(graphscr)
(setq olderr *error*
*error* trap)
(setq inc (getint "\nEnter Circuit Increment: ")
stc (getint "\nEnter Starting Circuit: "))
(if (setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))
(progn
(setq sl(sslength ss)
ct 0)
(repeat sl
(setq e1 (ssname ss ct))
(setq ck 2)
(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "CIRCUIT")
(progn
(setq attchk (ascii (substr (cdr (assoc 1 e2)) 1 1))
cct (atoi (cdr (assoc 1 e2))))
(if (and (< attchk 58)(<= stc cct))
(progn
(setq addup (+ (atoi (cdr (assoc 1 e2))) inc))
(setq inc2 (itoa addup))
(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)
)
(if (= (cdr (assoc 2 e2)) "TCIRCUIT")
(progn
(setq attchk (ascii (substr (cdr (assoc 1 e2)) 1 1))
cct (atoi (cdr (assoc 1 e2))))
(if (and (< attchk 58)(<= stc cct))
(progn
(setq addup (+ (atoi (cdr (assoc 1 e2))) inc))
(setq inc2 (itoa addup))
(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)
)
)
(setq ct (+ ct 1))
)))
(princ ct)
(princ " Circuits were incremented by:")
(princ inc)
(princ " Starting from:")
(princ stc)
(restore)
)
I also got this strange message in AutoCAD 2015 and wandering what it means?
Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Solved by hmsilva. Go to Solution.
@Anonymous wrote:
...
Also how on earth do you link to a dwg file so I can show the dwg file I am using as a test bed?
...
Hi rodb,
would be useful if you attach a sample dwg, to do that, if you reply to this message, at the bottom of the reply "screen" you'll have a browse button to attach a file.
If you can't attach a .dwg file, try to attach as a zip file.
Henrique
Thank you it does always fail as a dwg file, so am attaching as zip now. This type of drawing is what keeps giving me problems. When I want to change attributes in a dwg that also contain blocks without attributes, especially these polylines drawn on one layer and then blocked and inserted on another layer. I need to do that so I can have the option of freezing a set of blocks created on the same layer but inserted on another.
Let's see if I understand your goal.
Your goal is to renumber all blocks with attributes having a CIRCUIT and TCIRCUIT tag, starting from a given number with a given increment, correct?
At your test dwg I can't find the TCIRCUIT tag, and I can't also understand if the TCIRCUIT new numeration is made together with the CIRCUIT, or is done separately,
i.e.
TCIRCUIT 1
TCIRCUIT 2
CIRCUIT 3
TCIRCUIT 4
CIRCUIT 5
or
TCIRCUIT 1
TCIRCUIT 2
CIRCUIT 1
TCIRCUIT 3
CIRCUIT 2
EDIT: if possible attach a sample dwg with the before and after, for better understanding.
Henrique
Let me start by saying it works fine if the blocked polylines are not there as did the blocks with the Object attribute. The block next to the polylines stores the circuit number for the polyline which illustrates an Led strip light) and its length, wattage, control etc. The dwg will contain blocks with CIRCUIT and TCIRCUIT that need to be updated with the same incremented circuit number. The circuit attribute is extracted and placed in a grid on the drawing but I don't want the TCIRCUIT attribute numbers extracted and placed on the grid, but do want them visiable on the drawing. I'll make another dwg with the TCIRCUIT blocks as well.
rodb, I haven't seen yet the second dwg, but would be something like this???
(defun c:incst (/ ADDUP ATTCHK CCT CT E1 E2 INC INC2 SL SS STC) (if (and (setq inc (getint "\nEnter Circuit Increment: ")) (setq stc (getint "\nEnter Starting Circuit: ")) (setq ss (ssget "X" '((0 . "INSERT") (66 . 1)))) );; and (progn (setq sl (sslength ss) ct 0 ) (repeat sl (setq e1 (ssname ss ct)) (setq e1 (entnext e1)) (while (not (equal (cdr (assoc 0 (setq e2 (entget e1)))) "SEQEND")) (if (and (wcmatch (cdr (assoc 2 e2)) "CIRCUIT,TCIRCUIT") (setq attchk (ascii (substr (cdr (assoc 1 e2)) 1 1))) (setq cct (atoi (cdr (assoc 1 e2)))) (and (< attchk 58) (<= stc cct)) ) (progn (setq addup (+ cct inc)) (setq inc2 (itoa addup)) (setq e2 (subst (cons 1 inc2) (assoc 1 e2) e2)) (entmod e2) (entupd e1) ) ) (setq e1 (entnext e1)) ) (setq ct (+ ct 1)) ) (princ ct) (princ " Circuits were incremented by:") (princ inc) (princ " Starting from:") (princ stc) ) ) (princ) )
HTH
Henrique
"Let me start by saying it works fine if the blocked polylines are not there as did the blocks with the Object attribute. "
No, it would always raise an error because with
(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
you would supply the test function (not (equal ck "SEQEND")) the last processed entity, not the next one to test if not the "SEQEND" and when you try to extract the tag with (= (cdr (assoc 2 e2)) "CIRCUIT") it would raise an error because "SEQEND" don´t have the dxf 2...
Here it is your original code, revised
;Increment Selected Circuits (defun restore ();restore variables (setq *error* olderr) (princ) ) (defun trap (er);error trapping (princ "\nOOPS PROGRAM ABORTED ") (princ er) (setq *error* olderr) (princ) ) (defun c:incst (/ addup attchk ss cct ct sl e1 e2 ck stc inc inc2) (graphscr) (setq olderr *error* *error* trap ) (if (and (setq inc (getint "\nEnter Circuit Increment: "))
(setq stc (getint "\nEnter Starting Circuit: "))
(setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))
) (progn (setq sl (sslength ss) ct 0 ) (repeat sl (setq e1 (ssname ss ct)) (setq e1 (entnext e1) e2 (entget e1) ck (cdr (assoc 0 e2)) ) (while (not (equal ck "SEQEND")) (if (= (cdr (assoc 2 e2)) "CIRCUIT") (progn (setq attchk (ascii (substr (cdr (assoc 1 e2)) 1 1)) cct (atoi (cdr (assoc 1 e2))) ) (if (and (< attchk 58) (<= stc cct)) (progn (setq addup (+ (atoi (cdr (assoc 1 e2))) inc)) (setq inc2 (itoa addup)) (setq e2 (subst (cons 1 inc2) (assoc 1 e2) e2)) (entmod e2) (entupd e1) ;(setq ctr (+ ctr 1)) ) ) ) ) (if (= (cdr (assoc 2 e2)) "TCIRCUIT") (progn (setq attchk (ascii (substr (cdr (assoc 1 e2)) 1 1)) cct (atoi (cdr (assoc 1 e2))) ) (if (and (< attchk 58) (<= stc cct)) (progn (setq addup (+ (atoi (cdr (assoc 1 e2))) inc)) (setq inc2 (itoa addup)) (setq e2 (subst (cons 1 inc2) (assoc 1 e2) e2)) (entmod e2) (entupd e1) ;(setq ctr (+ ctr 1)) ) ) ) ) (setq e1 (entnext e1) e2 (entget e1) ck (cdr (assoc 0 e2)) ) ) (setq ct (+ ct 1)) ) ) ) (princ ct) (princ " Circuits were incremented by:") (princ inc) (princ " Starting from:") (princ stc) (restore) )
hope that helps
Henrique
Oh can't wait to try that, it helps so much to explain why it won't work as well as sort it out. I love the power of lisp but have never properly understood it. Will report back as soon as I have tried it.
Yes it works perfectly, thank you so much. I have to impliment the solution to some other programs that are a bit more complicated because the circuit number is prefixed by letters like MS45 etc.
@Anonymous wrote:
Yes it works perfectly, thank you so much.
You're welcome, rodb
Glad I could help!
@Anonymous wrote:
I have to impliment the solution to some other programs that are a bit more complicated because the circuit number is prefixed by letters like MS45 etc.
If your prefix will always be "@...@#...#" maybe you can use something like
(defun split (str / i pre suf) (if (wcmatch str "@*#") (progn (setq i 0 suf str ) (while (wcmatch suf "@*") (setq suf (substr suf (setq i (1+ i)))) ) (setq pre (substr str 1 i)) (list pre suf) ) ) )
_$ (split "ABC123")
("ABC" "123")
HTH
Henrique
Well here are the two programs I made with an option to pick the fittings and they seem to work ok even if there are the blocked polylines. So I was going to convert them to ssget "X" because it can be difficult to pick all the right fittings in a complex drawing and mostly you do want to increment or decrement from a certain circuit. It does seem to work reducing the circuit numbers as well by just putting minus in front of the starting circuit. So if you are in the mood for this? I will also have a go using the normal circuit program you fixed for me.
;Increment Selected PTB Circuits only
(defun restore () ;restore variables
(setq *error* olderr)
(princ)
)
(defun trap (er) ;error trapping
(princ "\nOOPS PROGRAM ABORTED ")
(princ er)
(setq *error* olderr)
(princ)
)
(defun c:incptbcircuit (/ ss ct sl e1 e2 ck inc)
(graphscr)
(setq olderr *error*
*error* trap)
(setq inc (getint "\nEnter Circuit Increment: "))
(prompt "\nPick your Blocks..")
(setq ss (ssget '((0 . "insert")))
sl (sslength ss)
ct 0
ctr 0)
(repeat sl
(setq e1 (ssname ss ct))
(setq ck 2)
(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "CIRCUIT")
(progn
(setq attchk (substr (cdr (assoc 1 e2)) 1 3))
(if (= attchk "PTB")
(progn
(setq cir (atoi (substr (cdr (assoc 1 e2)) 4)))
(setq newcir (itoa(+ cir inc)))
(setq inc2 (strcat attchk newcir))
;(setq addup (+ (atoi (cdr (assoc 1 e2))) inc))
;(setq inc2 (itoa addup))
;(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)
)
(if (= (cdr (assoc 2 e2)) "TCIRCUIT")
(progn
(setq attchk (substr (cdr (assoc 1 e2)) 1 3))
(if (= attchk "PTB")
(progn
(setq cir (atoi (substr (cdr (assoc 1 e2)) 4)))
(setq newcir (itoa(+ cir inc)))
(setq inc2 (strcat attchk newcir))
;(setq addup (+ (atoi (cdr (assoc 1 e2))) inc))
;(setq inc2 (itoa addup))
;(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)
)
)
(setq ct (+ ct 1))
)
(princ ctr)
(princ " Circuits were incremented by: ")
(princ inc)
(restore)
)
;Increment Selected MS Circuits only
(defun restore () ;restore variables
(setq *error* olderr)
(princ)
)
(defun trap (er) ;error trapping
(princ "\nOOPS PROGRAM ABORTED ")
(princ er)
(setq *error* olderr)
(princ)
)
(defun c:incmscircuit (/ ss ct sl e1 e2 ck inc)
(graphscr)
(setq olderr *error*
*error* trap)
(setq inc (getint "\nEnter Circuit Increment: "))
(prompt "\nPick your Blocks..")
(setq ss (ssget '((0 . "insert")))
sl (sslength ss)
ct 0
ctr 0)
(repeat sl
(setq e1 (ssname ss ct))
(setq ck 2)
(while (not (equal ck "SEQEND"))
(setq e1 (entnext e1)
e2 (entget e1)
ck (cdr (assoc 0 e2)))
(if (= (cdr (assoc 2 e2)) "CIRCUIT")
(progn
(setq attchk (substr (cdr (assoc 1 e2)) 1 2))
(if (= attchk "MS")
(progn
(setq cir (atoi (substr (cdr (assoc 1 e2)) 3)))
(setq newcir (itoa(+ cir inc)))
(setq inc2 (strcat attchk newcir))
;(setq addup (+ (atoi (cdr (assoc 1 e2))) inc))
;(setq inc2 (itoa addup))
;(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)
)
(if (= (cdr (assoc 2 e2)) "TCIRCUIT")
(progn
(setq attchk (substr (cdr (assoc 1 e2)) 1 2))
(if (= attchk "MS")
(progn
(setq cir (atoi (substr (cdr (assoc 1 e2)) 3)))
(setq newcir (itoa(+ cir inc)))
(setq inc2 (strcat attchk newcir))
;(setq addup (+ (atoi (cdr (assoc 1 e2))) inc))
;(setq inc2 (itoa addup))
;(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(setq e2 (subst (cons 1 inc2)(assoc 1 e2)e2))
(entmod e2)
(entupd e1)
(setq ctr (+ ctr 1))
)
)
)
)
)
(setq ct (+ ct 1))
)
(princ ctr)
(princ " Circuits were incremented by: ")
(princ inc)
(restore)
)
@Anonymous wrote:
Well here are the two programs I made with an option to pick the fittings and they seem to work ok even if there are the blocked polylines. So I was going to convert them to ssget "X" because it can be difficult to pick all the right fittings in a complex drawing and mostly you do want to increment or decrement from a certain circuit. It does seem to work reducing the circuit numbers as well by just putting minus in front of the starting circuit.
rodb,
don´t you want to have the "Enter Starting Circuit" option?
Henrique
They both work very well except for reporting "23 Circuits were incremented by:10 Starting from:13" although there are only 4 circuits involved. I'll go through the lisp and see if I can find out why. They are much more compact and elegant than my attempts were so far, very nice to see, thank you!!!