Why after appload a lisp I found on this forum lsp is not working ?

Why after appload a lisp I found on this forum lsp is not working ?

ugrin
Enthusiast Enthusiast
1,559 Views
11 Replies
Message 1 of 12

Why after appload a lisp I found on this forum lsp is not working ?

ugrin
Enthusiast
Enthusiast

I was looking for a way to reverse pline direction in Land Desktop 2009 and found rdir.lsp on this forum. I got exited for a moment but after I appload the lsp and get a message : rdir.lsp successfully loaded...When I try to run it I get ...no function definition: RDIR. I'm coping the code bellow and apologize for doing it since is not mine. I'm new to LISP and just got interested in it but my first encounter is not helping to get me excited :). Thanks in advance guys .

 

; reverse the polyline direction

(defun getcodelist (code lista / item lout)
(while (setq item (assoc code lista))
(setq lista (cdr (member item lista)) lout (cons item lout)))
lout)

(defun dxfn (code name)
(cdr (assoc code (entget name))))

(defun listrotate (n lista)
(repeat n (setq lista (cdr (append lista (list (car lista)))))))

(defun c:PR (/ poly vt lvt lvt2 new old ed closed polygen arcgen
l_10 l_40 l_41 l_42 i n item ss a e )

(command "undo" "be")
(princ "\nPR - Reverses the direction of a PLINE, ARC or LINE")
(princ "\nLisp Routine Downloaded from Autocad User Group")
(setq ss (cadr (ssgetfirst)))
(if ss (progn
(setq a -1)
(while (< (setq a (1+ a)) (sslength ss))
(setq e (ssname ss a))
(if (or (= (dxfn 0 e) "ARC") (= (dxfn 0 e) "LINE") (= (dxfn 0 e)
"POLYLINE") (= (dxfn 0 e) "LWPOLYLINE"))
(setq a (1+ a))
(ssdel e ss)))
(if (= 0 (sslength ss)) (setq ss nil))
(if ss (progn
(princ "\nFound ") (princ (itoa (sslength ss)))
(princ (if (= 1 (sslength ss)) " entity" " entities"))
(princ " already selected.\nOk to reverse ")
(princ (if (= 1 (sslength ss)) " this entity" " these entities"))
(setq a (substr (strcase (getstring "? (type 'n' to select new
entities) [y/n] <y> ")) 1 1))
(if (= "N" a) (setq ss nil))))))
(if (not ss) (progn
(sssetfirst nil nil)
(princ "\nSelect ARCs, LINEs or POLYLINEs to reverse")
(setq ss (ssget '((0 . "ARC,LINE,POLYLINE,LWPOLYLINE"))))
(if ss (progn
(princ "\nFound ") (princ (itoa (sslength ss)))
(princ (if (= 1 (sslength ss)) " entity" " entities"))

;SECTION REMARKED OUT TO AVOID PROMPT
;(princ "\nOk to reverse ")
;(princ (if (= 1 (sslength ss)) " this entity" " these entities"))
;(setq a (substr (strcase (getstring "? [y/n] <y> ")) 1 1))
;(if (= "N" a) (setq ss nil))
))))

(setq a -1 polygen nil arcgen 0)
(while (and ss (< (setq a (1+ a)) (sslength ss)))
(setq poly (ssname ss a) arc_check nil)
(if (= (dxfn 0 poly) "ARC") (progn
(setq arc_check T)
(command "pedit" poly "" "")
(if (or (entget poly) (and (/= "LWPOLYLINE" (dxfn 0 (entlast))) (/=
"POLYLINE" (dxfn 0 (entlast)))))
(princ "\nCouldn't convert ARC to PLINE")
(setq poly (entlast) arcgen (1+ arcgen)))))
(cond ((= (dxfn 0 poly) "POLYLINE")
(if (/= 128 (logand 128 (dxfn 70 poly))) (progn
(if (not arc_check) (setq polygen T))
(setq ed (entget poly))
(setq ed (subst (cons 70 (logior 128 (cdr (assoc 70 ed))))
(assoc 70 ed) ed))
(entmod ed) (entupd poly)))
(setq closed (= (dxfn 70 poly) 1) vt (entnext poly))
(while (/= (dxfn 0 vt) "SEQEND")
(if (/= 16 (dxfn 70 vt))
(setq lvt (cons (list (dxfn 10 vt) (dxfn 42 vt)) lvt)))
(setq vt (entnext vt)))
(if closed
(setq lvt (cons (last lvt) lvt)
lvt (reverse (cdr (reverse lvt)))))
(setq lvt2 (cdr (append lvt (list (car lvt))))
lvt (mapcar '(lambda (a b) (list (car a) (- (cadr
b)))) lvt lvt2)
lvt2 nil)
(setq vt (entnext poly))
(while (/= (dxfn 0 vt) "SEQEND")
(if (/= 16 (dxfn 70 vt)) (progn
(setq ed (entget vt)
old (assoc 10 ed)
new (cons 10 (caar lvt))
ed (subst new old ed)
old (assoc 42 ed)
new (cons 42 (cadr (car lvt)))
ed (subst new old ed)
lvt (cdr lvt))
(entmod ed)))
(setq vt (entnext vt)))
(entupd poly))
((= (dxfn 0 poly) "LWPOLYLINE")
(if (/= 128 (logand 128 (dxfn 70 poly))) (progn
(if (not arc_check) (setq polygen T))
(setq ed (entget poly))
(setq ed (subst (cons 70 (logior 128 (cdr (assoc 70 ed))))
(assoc 70 ed) ed))
(entmod ed) (entupd poly)))
(setq ed (entget poly)
lvt (member (assoc 10 ed) ed)
lvt (reverse (cdr (reverse lvt)))
l_10 (getcodelist 10 lvt)
l_41 (getcodelist 41 lvt)
l_41 (mapcar '(lambda (a) (cons 40 (cdr a))) l_41)
l_41 (listrotate 1 l_41)
l_40 (getcodelist 40 lvt)
l_40 (mapcar '(lambda (a) (cons 41 (cdr a))) l_40)
l_40 (listrotate 1 l_40)
l_42 (getcodelist 42 lvt)
l_42 (mapcar '(lambda (a) (cons 42 (- (cdr a)))) l_42)
l_42 (listrotate 1 l_42)
n (length l_10)
i -1)
(while (< (setq i (1+ i)) n)
(setq lvt2 (append lvt2 (list (nth i l_10) (nth i l_41)
(nth i l_40) (nth i
l_42)))))
(setq lvt (reverse ed))
(while (setq item (assoc 10 lvt))
(setq lvt (cdr (member item lvt))))
(setq lvt (reverse lvt) lvt2 (append lvt lvt2 (list (assoc
210 ed))))
(entmod lvt2)
(entupd poly))
((= (dxfn 0 poly) "LINE")
(setq ed (entget poly) e (cdr (assoc 10 ed)))
(setq ed (subst (cons 10 (cdr (assoc 11 ed))) (assoc 10 ed)
ed))
(setq ed (subst (cons 11 e) (assoc 11 ed) ed))
(entmod ed)
(entupd poly))
))
(sssetfirst nil nil)
(if (< 0 arcgen) (princ (strcat "\n" (itoa arcgen) "ARC" (if (= 1 arcgen)
" was" "s were")
"converted to " (if (= 1 arcgen) "a
PLINE" "PLINEs"))))

(command "undo" "e")
(princ))

(princ)

0 Likes
Accepted solutions (3)
1,560 Views
11 Replies
Replies (11)
Message 2 of 12

Todd_Rogers
Mentor
Mentor

Why don't you just use the REVERSE command?

Todd Rogers
Civil Administration
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 3 of 12

ugrin
Enthusiast
Enthusiast

In 2009 the REVERSE command doesn't exist. I wish it did. They are other ways around but I was just looking for quickest way and also want to learn more about LISP. 

0 Likes
Message 4 of 12

jmayo-EE
Mentor
Mentor

The OP is working with LDD... 😮

John Mayo

EESignature

0 Likes
Message 5 of 12

ugrin
Enthusiast
Enthusiast

Sorry but I have no clue what you're saying John ? 🙂

0 Likes
Message 6 of 12

Ranjit_Singh
Advisor
Advisor
Accepted solution

@ugrin wrote:

.........rdir.lsp successfully loaded...When I try to run it I get ...no function definition: RDIR. ....


The lisp works fine for me. The command to call is PR and not rdir  (that is just the name of the lisp file)

When we didn't have the reverse command (in 2009 and older versions), one would explode the pline and rotate any one straight segment 180 degrees (about it's midpoint) and then join the segments back together. Give that a try, although calling PR should work.

Message 7 of 12

jmayo-EE
Mentor
Mentor

I replied to Todd. The OP is you, the original poster, LDD is Land Desktop and yes no reverse command going back that far.

 

You may have better luck posting this here,

https://forums.autodesk.com/t5/autocad-civil-3d-customization/bd-p/190

 

John Mayo

EESignature

0 Likes
Message 8 of 12

ugrin
Enthusiast
Enthusiast
Accepted solution

Thanks Rahnjit.Singh,

You nailed. Now I have to figure out where You see the command to call . You made my life a whole lot easier. have a great day.

0 Likes
Message 9 of 12

Ranjit_Singh
Advisor
Advisor

The command name is typically preceded with a c: Give a ctrl+f in the rdir.lsp file and search for defun c:

Message 10 of 12

ugrin
Enthusiast
Enthusiast

Next step 🙂 ... Is there a way to auto loaded every time I load my 2009 and work with any drawing or I'm gonna have to load it manually if I want to use it with the specific drawing? And thanks again for your quick response and help .

0 Likes
Message 11 of 12

Ranjit_Singh
Advisor
Advisor
Accepted solution

@ugrin wrote:

Next step 🙂 ... Is there a way to auto loaded every time I load my 2009 and work with any drawing or I'm gonna have to load it manually if I want to use it with the specific drawing? And thanks again for your quick response and help .


Short answer. Yes. Read Autodesk Knowledge Network article.

Moderators may want to move this thread to the Visual Lisp forums.

 

Message 12 of 12

ugrin
Enthusiast
Enthusiast

Thanks man. Really appreciated . Have a good day.

0 Likes