Ryder76 Posted March 15, 2010 Posted March 15, 2010 There is a thread in the General area that I responded to about a routine for an electrical wire jumper. rkent posted a lisp that is almost what I need. I need to add a feature to the routine that would define the ltscale at .4072 in the beginning and then redfine it back to 1 at the end. If it would auto repeat that would be way cool. Any takers on this? Thanks in advance. JUMPER.LSP Quote
Lee Mac Posted March 15, 2010 Posted March 15, 2010 Hi Ryder, I have slightly modified your code in that the Arc Radius may be specified at the top of the code. I have also added an error handler (defun c:jumper (/ *error* A B1 B2 BDIS ENT OV P1 P2 VL) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and ov (mapcar (function setvar) vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq vl '("CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (while (and (mapcar (function setvar) vl '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (if (> a (/ pi 2.)) (command "_.arc" b1 "_E" b2 "_A" 180.) (command "_.arc" b2 "_E" b1 "_A" 180.))) (mapcar (function setvar) vl ov) (princ)) Let me know if this works for you Quote
ReMark Posted March 15, 2010 Posted March 15, 2010 What did I tell you Ryder? Want my next prediction? Quote
Ryder76 Posted March 15, 2010 Author Posted March 15, 2010 Big hugs Lee - I love it - you're the best! Predictions from a Quantum Mechanic are the best! Quote
Glen Smith Posted March 16, 2010 Posted March 16, 2010 I saw the other thread last night just before putting the kids to bed. I knew that I wanted to grab the code for work, but promptly forgot the thread name. This morning I remembered that I wanted the code and that Ryder had posted on the thread, so I searched on her name. And I find that Ryder has already asked Lee to put in an error handler and he has polished the code. I took the liberty of adding undo marks to the new code so each jumper can be undone rather than undoing the arc, then the break. Otherwise, I'm certain to get caught sometime with a broken wire and no arc to connect it. Thanks to all! (defun c:jumper (/ *error* A B1 B2 BDIS ENT OV P1 P2 VL doc) (setq bDis 0.1) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and ov (mapcar (function setvar) vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq vl '("CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (while (and (mapcar (function setvar) vl '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-startUndoMark doc) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (if (> a (/ pi 2.)) (command "_.arc" b1 "_E" b2 "_A" 180.) (command "_.arc" b2 "_E" b1 "_A" 180.))) (vla-EndUndoMark doc) (mapcar (function setvar) vl ov) (princ)) Quote
Lee Mac Posted March 16, 2010 Posted March 16, 2010 Tweaked as requested (defun c:jumper (/ *error* A B1 B2 BDIS DOC ENT OV P1 P2 UFLAG VL) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (while (and (mapcar (function setvar) vl '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq uFlag (not (vla-StartUndoMark doc))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq uFlag (vla-EndUndoMark doc))) (mapcar (function setvar) vl ov) (princ)) Quote
Glen Smith Posted March 17, 2010 Posted March 17, 2010 Thank you Lee, that works better than what I had. I have noticed that if I undo a jumper the OSNAPS are not set to the beginning values. I have always heard that phantom changes to your OSNAPS are often due to LISP's "misbehaving". But returning the OSNAPS has to be the last thing done in the LISP. How do you skip over returning the OSNAPS to the initial value, yet still allow the user to undo jumpers one at a time? Glen Quote
Lee Mac Posted March 17, 2010 Posted March 17, 2010 Ah yes - I suppose this is a workaround: (defun c:jumper (/ *error* A B1 B2 BDIS DOC ENT OV P1 P2 UFLAG VL) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) vl '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) IMO, I would not change the OSMODE to 32 and leave the user to make sure that Intersection is enabled - saves a lot of hassle. Quote
Ryder76 Posted March 17, 2010 Author Posted March 17, 2010 Tweaked as requested You are wonderful! Quote
Lee Mac Posted March 17, 2010 Posted March 17, 2010 You are wonderful! Thanks Ryder You might want to use the latest code posting, as we found a small glitch with the UndoMarks within the code - the UNDO caused the OSMODE to be set to the state it was before the first UndoMark. Hopefully the latest code resolves this issue. Quote
Glen Smith Posted March 25, 2010 Posted March 25, 2010 Lee, Is there a way to check if the line that is broken is a PLINE and if so, join the arc with the two segments created by the break? I often use PLINEs with a width greater than the default for my wires to set them apart from the other drawing elements. After using the jumper routine, I then have to go back through and do a PEDIT on each line and join them. This keeps the wire as a single entity in case of future moves, and also happily sets the width of the new arc to the same as the other segments of the PLINE. I know that this request is beyond my abilities. Glen Quote
alanjt Posted March 25, 2010 Posted March 25, 2010 (*error* nil) AHAHA. Welcome to the dark side. :wink: Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 AHAHA. Welcome to the dark side. :wink: Hahaha well, it just seemed easier in this case Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 Try this Glen, nothing fancy, and not much error trapping: (defun c:jumper (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq aEnt (entlast)) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) Quote
alanjt Posted March 25, 2010 Posted March 25, 2010 Hahaha well, it just seemed easier in this case Just giving you a hard time. Quote
stevesfr Posted March 25, 2010 Posted March 25, 2010 Try this Glen, nothing fancy, and not much error trapping: (defun c:jumper (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq aEnt (entlast)) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) Almost, the arc is a pline and continuous with the pline, but the program (for the arc) doesn't pick up the initial width of the pline that is broken and arc inserted. (more dark side !) S Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 This really is getting messy now... (defun c:jumper (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL O W) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq aEnt (entlast)) (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent)))))) (progn (setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent)))) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w))) (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) Quote
stevesfr Posted March 25, 2010 Posted March 25, 2010 This really is getting messy now... (defun c:jumper (/ *error* A AENT B1 B2 BDIS BENT DOC ENT OV P1 P2 UFLAG VL O W) (setq bDis 0.04072) ;; Arc Radius (Break Distance / 2.0 ) (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (and ov (mapcar (function setvar) vl ov)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")))) (princ)) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) vl '("PEDITACCEPT" "CMDECHO" "OSMODE") ov (mapcar (function getvar) vl)) (setvar "PEDITACCEPT" 1) (while (and (setq uFlag (not (vla-StartUndoMark doc))) (mapcar (function setvar) (cdr vl) '(0 32)) (setq p1 (getpoint "\nPick INTERSECTION: ")) (setq ent (entsel "\nPick LINE TO BREAK: "))) (setq p2 (osnap (cadr ent) "_nea") b1 (polar p1 (setq a (angle p1 p2)) bDis) b2 (polar p1 (+ pi a) bDis)) (setvar "OSMODE" 0) (command "_.break" b1 b2) (setq bEnt (entlast)) (if (> a (/ pi 2.)) (command "_.arc" b2 "_E" b1 "_A" 180.) (command "_.arc" b1 "_E" b2 "_A" 180.)) (setq aEnt (entlast)) (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (car ent)))))) (progn (setq w (vla-get-ConstantWidth (setq o (vlax-ename->vla-object ent)))) (command "_.pedit" "_M" bEnt aEnt ent "" "_J" "" "") (vla-put-ConstantWidth (vlax-ename->vla-object (entlast)) w))) (setq uFlag (vla-EndUndoMark doc))) (*error* nil) (princ)) not messy, just PERFECT... thanks for making EE's happy ! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.