Elektrik Posted January 27, 2021 Share Posted January 27, 2021 Hi The lisp below creates line breaks and jumps for use in a wiring diagram, but I cannot enter length or height of that jump, like you can enter offset value. It is coded as 0.125 in the lisp. Could someone change it so that I could enter a value I want to use instead of a predetermined one? Thanks in advance. (defun C:LJ2 (/ pick ename c0 c1 c2 c3 ;| local variables |;) (setvar "cmdecho" 0) ; disable command echo (command "._undo" "_begin") ; start undo group (if (and (setq pick (entsel "\nSelect line to break: ")) ; select entity (setq ename (car pick)) ; get ename (eq (cdr (assoc '0 (entget ename))) "LINE") ; make sure it's a line? (not (redraw ename 3)) ; highlight entity (setq c0 (getpoint "\nSpecify intersection: ")) ; get intersection ) (progn (setq p0 (osnap (cadr pick) "_nearest")) ; make sure the pick is on object (setq c1 (polar c0 (angle p0 c0) 0.125)) (setq c2 (polar c0 (angle c0 p0) 0.125)) (command "._break" pick "_f" "_none" c1 "_none" c2) ; break (command "._arc" "_none" c1 "_C" "_none" c0 "_none" c2) ; draw arc (jump) ); progn ); if (command "._undo" "_end") ; clsoe undo group (setvar "cmdecho" 1) ; enable command echo (princ) ; quiet exit ); C:LJ2 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 27, 2021 Share Posted January 27, 2021 1 minute ago, Elektrik said: Hi The lisp below creates line breaks and jumps for use in a wiring diagram, but I cannot enter length or height of that jump, like you can enter offset value. It is coded as 0.125 in the lisp. Could someone change it so that I could enter a value I want to use instead of a predetermined one? Thanks in advance. Try this: (defun C:LJ2 (/ pick ename c0 c1 c2 c3 jump ;| local variables |;) (setvar "cmdecho" 0) ; disable command echo (command "._undo" "_begin") ; start undo group (if (and (setq pick (entsel "\nSelect line to break: ")) ; select entity (setq ename (car pick)) ; get ename (eq (cdr (assoc '0 (entget ename))) "LINE") ; make sure it's a line? (not (redraw ename 3)) ; highlight entity (setq c0 (getpoint "\nSpecify intersection: ")) ; get intersection (setq jump (getreal "\nSpecify Jump distance: ")) ) (progn (setq p0 (osnap (cadr pick) "_nearest")) ; make sure the pick is on object (setq c1 (polar c0 (angle p0 c0) jump)) (setq c2 (polar c0 (angle c0 p0) jump)) (command "._break" pick "_f" "_none" c1 "_none" c2) ; break (command "._arc" "_none" c1 "_C" "_none" c0 "_none" c2) ; draw arc (jump) ); progn ); if (command "._undo" "_end") ; clsoe undo group (setvar "cmdecho" 1) ; enable command echo (princ) ; quiet exit ); C:LJ2 1 Quote Link to comment Share on other sites More sharing options...
Elektrik Posted January 27, 2021 Author Share Posted January 27, 2021 (edited) 9 minutes ago, pkenewell said: Try this: (defun C:LJ2 (/ pick ename c0 c1 c2 c3 jump ;| local variables |;) (setvar "cmdecho" 0) ; disable command echo (command "._undo" "_begin") ; start undo group (if (and (setq pick (entsel "\nSelect line to break: ")) ; select entity (setq ename (car pick)) ; get ename (eq (cdr (assoc '0 (entget ename))) "LINE") ; make sure it's a line? (not (redraw ename 3)) ; highlight entity (setq c0 (getpoint "\nSpecify intersection: ")) ; get intersection (setq jump (getreal "\nSpecify Jump distance: ")) ) (progn (setq p0 (osnap (cadr pick) "_nearest")) ; make sure the pick is on object (setq c1 (polar c0 (angle p0 c0) jump)) (setq c2 (polar c0 (angle c0 p0) jump)) (command "._break" pick "_f" "_none" c1 "_none" c2) ; break (command "._arc" "_none" c1 "_C" "_none" c0 "_none" c2) ; draw arc (jump) ); progn ); if (command "._undo" "_end") ; clsoe undo group (setvar "cmdecho" 1) ; enable command echo (princ) ; quiet exit ); C:LJ2 Thanks, but it would be better if I could enter a value one time, and it would use it until I re-enter another one, like how offset command works. Also, if I could enter a height along with a length, it would be great. Edited January 27, 2021 by Elektrik Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 27, 2021 Share Posted January 27, 2021 2 hours ago, Elektrik said: Thanks, but it would be better if I could enter a value one time, and it would use it until I re-enter another one, like how offset command works. Also, if I could enter a height along with a length, it would be great. Try this then. (defun C:LJ2 (/ pick ename c0 c1 c2 c3 jump ;| local variables |;) (setvar "cmdecho" 0) ; disable command echo (command "._undo" "_begin") ; start undo group ; Set global values. (if (not *jdx*)(setq *jdx* 0.125)) (if (not *jdy*)(setq *jdy* 0.125)) (if (and (setq pick (entsel "\nSelect line to break: ")) ; select entity (setq ename (car pick)) ; get ename (eq (cdr (assoc '0 (entget ename))) "LINE") ; make sure it's a line? (not (redraw ename 3)) ; highlight entity (setq c0 (getpoint "\nSpecify intersection: ")) ; get intersection (if (setq jump (getreal (strcat "\nSpecify Jump distance <" (rtos *jdx* 2 4) "> : "))) (if (> jump 0.0)(setq *jdx* jump)(progn (princ "\nJump distance cannot be 0! Reverting to default.") T)) T ) (if (setq jump (getreal (strcat "\nSpecify Jump Height <" (rtos *jdy* 2 4) "> : "))) (if (> jump 0.0)(setq *jdy* jump)(progn (princ "\nJump Height cannot be 0! Reverting to default.") T)) T ) ) (progn (setq p0 (osnap (cadr pick) "_nearest")) ; make sure the pick is on object (setq c1 (polar c0 (angle p0 c0) *jdx*)) (setq c2 (polar c0 (angle c0 p0) *jdy*)) (command "._break" pick "_f" "_none" c1 "_none" c2) ; break (command "._arc" "_none" c1 "_C" "_none" c0 "_none" c2) ; draw arc (jump) ); progn ); if (command "._undo" "_end") (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 28, 2021 Share Posted January 28, 2021 Pkenewell would it be better to change (if (and (setq pick To a (while so can keep picking lines rather than having to type LJ2 or Enter to do another. Also maybe rather than pick intersection pick other line and use intersectwith for pt. Possibly no need for second pick as can use ssget "F" to find crossing lines for multiple do at once. Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 28, 2021 Share Posted January 28, 2021 @BIGAL Yes - there are allot of ways this code could be improved. However, I was not trying to rewrite the OPs program; I was only trying to add what was asked for in the existing code quickly, since I was at work and did not have time for an extensive rewrite. If you have time - feel free. Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 28, 2021 Share Posted January 28, 2021 (edited) 18 hours ago, BIGAL said: To a (while so can keep picking lines rather than having to type LJ2 or Enter to do another. @BIGAL Since your comment is baiting me to do a better program - Here you go. This uses Lee's LM:Selectif function to filter and provide missed / invalid pick error handling. This could still be made better, but this is all I have time for (indeed I spent too much time on it already). EDIT: I realized the jump distance settings didn't make sense the distances have to be the same for an ARC, if different y, then use an ELLIPSE. EDIT2: Added a feature to combine the jump lines and arcs into a polyline. Doesn't work with the ellipses however. Also changed the behavior so that the gap distance specified is for the gap from the intersecting line to one side of the arc, not the total width of the arc. I did this because the gap width and jump height are now equivalent when the values are the same (i.e. rad to rad. - not dia. to rad.). EDIT3: Realized that I had a redundant IF statement after the main WHILE loop - removed. EDIT4: Simplified to always use an ARC - I don't know what I was thinking with the Ellipse version! Now will always work if you want to join the resulting lines. EDIT5: Added Error looping to make sure settings values are not invalid and allows the user to correct without re-entering the program. EDIT6: Added undo mark into error handler. Corrected local variables (removed ones no longer used and added one). (defun c:JumpLine (/ pick oldecho jump c0 c1 c2 c3 p0 ss res *error*) ; Load Visual LISP and start and undo mark (vl-load-com) (defun *error* (msg) (if (not (wcmatch (strcase msg T) "*break*,*cancel*,*quit*,*exit*")) (princ (strcat "\nError: " msg "\n")) (princ "\nProgram Aborted.\n") ) (setvar "cmdecho" oldecho) (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object))) (princ) ) (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object))) ; Get value of cmdecho sysvar and toggle it off. (setq oldecho (getvar "cmdecho")) (setvar "cmdecho" 0) ; Set global values. (if (not *jdx*)(setq *jdx* 0.125)) (if (not *jdy*)(setq *jdy* 0.125)) (setq pick T) (while (setq pick (LM:selectif "\nSelect Line to Break [Exit/Settings]: <Exit> " (lambda ( x ) (wcmatch (cdr (assoc 0 (entget (car x)))) "LINE,LWPOLYLINE")) entsel '("Exit Settings") ) ) (cond ((= pick "Settings") (setq jump 0.0) (While (= Jump 0.0) (setq jump *jdx*) (if (and (setq jump (getreal (strcat "\nSpecify Jump gap distance for both sides <" (rtos *jdx* 2 4) "> : "))) (> jump 0.0)) (setq *jdx* jump) (if (= jump 0.0)(princ "\nInvalid Value - must be greater than 0.")) ) ) (setq jump 0.0) (While (or (= Jump 0.0)(>= jump (* 2 *jdx*))) (setq jump *jdy*) (if (and (setq jump (getreal (strcat "\nSpecify Jump Height <" (rtos *jdy* 2 4) "> : "))) (> jump 0.0) (< jump (* 2 *jdx*))) (setq *jdy* jump) (cond ((= jump 0.0)(princ "\nInvalid Value - must be greater than 0.")) ((>= jump (* 2 *jdx*))(princ "\nInvalid Value - must be less than 2X the gap.")) ) ) ) ) (( = Pick "Exit")(setq pick nil)) ((and ( = (type pick) 'LIST)(= (type (car pick)) 'ENAME)) (setq ss (ssadd (car pick))) (while (setq c0 (getpoint "\nSpecify intersection: ")) (setq p0 (osnap (cadr pick) "_nea") c1 (polar c0 (angle p0 c0) *jdx*) c2 (polar c0 (angle c0 p0) *jdx*) c3 (polar c0 (+ (angle p0 c0) (/ pi 2)) *jdy*) ) (command "._break" pick "_f" "_non" c1 "_non" c2); break (command "._arc" "_non" c1 "_non" c3 "_non" c2) (setq p0 (polar c1 (angle p0 c0) *jdx*) ss (ssadd (entlast) ss) pick (nentselp p0) ss (ssadd (car pick) ss) ) ) (Initget "Yes No") (if (or (setq res (getkword "\n Join jumps into a polyline? [Yes/No] <Yes>: ")) (not res)) (command "._pedit" "_Multiple" ss "" "_yes" "_Join" "" "") ) ) ) ) (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object))) (princ) ) ;;---------------------=={ Select if }==----------------------;; ;; ;; ;; Provides continuous selection prompts until either a ;; ;; predicate function is validated or a keyword is supplied. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; msg - prompt string ;; ;; pred - optional predicate function [selection list arg] ;; ;; func - selection function to invoke ;; ;; keyw - optional initget argument list ;; ;;------------------------------------------------------------;; ;; Returns: Entity selection list, keyword, or nil ;; ;;------------------------------------------------------------;; (defun LM:SelectIf ( msg pred func keyw / sel ) (setq pred (eval pred)) (while (progn (setvar 'ERRNO 0) (if keyw (apply 'initget keyw)) (setq sel (func msg)) (cond ( (= 7 (getvar 'ERRNO)) (princ "\nMissed, Try again.") ) ( (eq 'STR (type sel)) nil ) ( (vl-consp sel) (if (and pred (not (pred sel))) (princ "\nInvalid Object Selected.") ) ) ) ) ) sel ) Edited January 28, 2021 by pkenewell 1 Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 28, 2021 Share Posted January 28, 2021 Previous post edited - see above. Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 28, 2021 Share Posted January 28, 2021 Above post edited AGAIN. Starting to understand Marko Ribar's posts LOL - no offense meant Marko if you read this! Quote Link to comment Share on other sites More sharing options...
pkenewell Posted January 28, 2021 Share Posted January 28, 2021 New Latest version - updated yet again to this post: Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 28, 2021 Share Posted January 28, 2021 That is a great effort, added a couple more good options like error check makes it more bullet proof, something I don't do often enough. 1 Quote Link to comment Share on other sites More sharing options...
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.