Jump to content

Need help with gap line lisp


notredave

Recommended Posts

Good morning all,

Can someone help me with attached lisp routine to do 2 things:

(setq ar 0.0625); <~~~~~~~~~~~~~~~~~~~~~~ Set your size of gap here! I would like to be able to input exactly the size I want the gap to be. For instance, the gap of .0625 above gives me a 1/8" gap which I want. I want to be able to put .125 and not have to divide what I want by 2 to get my desired gap.

(defun myer (msg)                                          
  (setvar "osmode" OS)
  (setq att "***Resetting system variable was done***")
  (princ att)
)

After I finish with this lisp, I lose my osmode, which originally was set at 511. When I finish with this lisp, I have to always go back and set my osnaps back to what they were. I'm not sure if ablove is where you would reset this, I'm assuming which is a no no

 

Any help would be greatly appreciated it.

Thank you in advance,

David

 

 

GL.LSP

Link to comment
Share on other sites

Yes sir Tharwat, that would be a nice feature along with keeping my osmode intact or having it set back to what I have it set to originally. 

Link to comment
Share on other sites

Try the amended attachment. Will ask for the gap size and divide it by 2.

 

;;;|=====================================================================|;;;
;;;|   Gap Line Tool							 |;;;
;;;|provided by James Hodson, SDC Edmonton, Company, 2009		 |;;;
;;;|=====================================================================|;;;
;;;
;;;
(alert "Type GL to start, click a horizontal line to gap off of a vertical,
and click a vertical line to gap off of a horizontal

This runs again immediately if you hit space bar after your first two lines.

Happy Clicking!")

(defun c:gl (/ *error* sv_vals ar LINE1 LN P1 P2 AN LINE2 P3 P4 IN BPT1 PBT2)

  (defun *error* (msg)
    (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode 'clayer) sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
  );end_*error*
  
  (setq sv_vals (mapcar 'getvar  (list 'cmdecho 'osmode 'clayer)))
  (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode) '(0 0))
  
  (setq ar (/ (getreal "\nEnter Gap Size : ") 2))

  (while (not (setq ENT1 (car (entsel "\nSelect crossing line to break : "))))
    (princ "\nNull Selection please try again: ")
  )
  (setq LINE1 (entget ENT1))
  (setq LN (cdr (assoc 8 LINE1)))
  (setq P1 (trans (cdr (assoc 10 LINE1)) 0 1 ))
  (setq P2 (trans (cdr (assoc 11 LINE1)) 0 1 ))
  (setq AN (angle P1 P2))
  (while (not (setq ENT2 (car (entsel "\nSelect line to cross over : "))))
    (princ "\nNull Selection please try again: ")
  )
  (setq LINE2 (entget ENT2))
  (setq P3 (trans (cdr (assoc 10 LINE2))0 1))
  (setq P4 (trans (cdr (assoc 11 LINE2))0 1))
  (setq IN (inters P1 P2 P3 P4))
  (setq BPT1 (polar IN AN (* AR 1)))
  (setq BPT2 (polar IN (+ AN pi) (* AR 1)))
  (command "break" ENT1 BPT1 BPT2)
  (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode 'clayer) sv_vals)
  (setq *error* nil)   
  (princ)
)

 

Link to comment
Share on other sites

dlanorh, I just tried it out and it keeps my osmode intact but when I hit space bar to trim another line like it says in code:

This runs again immediately if you hit space bar after your first two lines.

It prompts me for gap size again. Thank you for replying.

Link to comment
Share on other sites

Opps @dlanorh  beat me to it but it seems is that my mods are different so I will post them anyway and hope that's okay with you. :)

[Not tested] and hopefully the codes would work as desired.

(defun c:gl (/ *error* vals ar s1 s2 e1 e2 ang p1 p2 p3 p4 ins bpt1 bpt2)
  (defun *error* (msg)
    (and vals (mapcar 'setvar '(OSMODE CMDECHO) vals))
    (princ "***Resetting system variable was done***")
  )
  (setq vals (mapcar 'getvar '(OSMODE CMDECHO)))
  (mapcar 'setvar '(OSMODE CMDECHO) '(0 0))
  (while
    (not
      (and (setq s1 (car (entsel "\nSelect crossing line to break: ")))
           (= (cdr (assoc 0 (setq e1 (entget s1)))) "LINE")
      )
    )
     (princ "\nNull Selection please try again: ")
  )
  (while
    (not
      (and (setq s2 (car (entsel "\nSelect line to cross over: ")))
           (= (cdr (assoc 0 (setq e2 (entget s2)))) "LINE")
      )
    )
     (princ "\nNull Selection please try again: ")
  )
  (if (and e1 e2 (setq ar (getdist "\nSpecify the GAp : ")))
    (progn (setq p1   (trans (cdr (assoc 10 e1)) 0 1)
                 p2   (trans (cdr (assoc 11 e2)) 0 1)
                 ang  (angle p1 p2)
                 p3   (trans (cdr (assoc 10 e2)) 0 1)
                 p4   (trans (cdr (assoc 11 e2)) 0 1)
                 ins  (inters p1 p2 p3 p4)
                 bpt1 (polar ins ang (* ar 1))
                 bpt2 (polar ins (+ ang pi) (* ar 1))
           )
           (and bpt1 bpt2 (command "break" e1 bpt1 bpt2))
    )
  )
  (*error* nil)
  (princ)
)

 

Edited by Tharwat
Link to comment
Share on other sites

16 minutes ago, notredave said:

dlanorh, I just tried it out and it keeps my osmode intact but when I hit space bar to trim another line like it says in code:

This runs again immediately if you hit space bar after your first two lines.

It prompts me for gap size again. Thank you for replying.

 

Quote

 

Hi,

Do you mean that you would like to ask the user for the input instead of having a static value?

 

 

Quote

Yes sir Tharwat, that would be a nice feature along with keeping my osmode intact or having it set back to what I have it set to originally. 

 

 

I thought that was what you wanted?

 

Try the attached. It saves the gap as a global so you can set once and press return to accept the default when asked again

 

;;;|=====================================================================|;;;
;;;|   Gap Line Tool							 |;;;
;;;|provided by James Hodson, SDC Edmonton, Company, 2009		 |;;;
;;;|=====================================================================|;;;
;;;
;;;
(alert "Type GL to start, click a horizontal line to gap off of a vertical,
and click a vertical line to gap off of a horizontal

This runs again immediately if you hit space bar after your first two lines.

Happy Clicking!")

(defun c:gl (/ *error* sv_vals ar LINE1 LN P1 P2 AN LINE2 P3 P4 IN BPT1 PBT2)

  (defun *error* (msg)
    (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode 'clayer) sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
  );end_*error*
  
  (setq sv_vals (mapcar 'getvar  (list 'cmdecho 'osmode 'clayer)))
  (if (not *mygap*) (setq *mygap* 0.0))
  
  (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode) '(0 0))
  
  (initget 6)
  (setq *mygap* (cond ( (getreal (strcat "\nEnter Gap Size <" (rtos *mygap* 2 3) "> : "))) (*mygap*)))
  
  (while (not (setq ENT1 (car (entsel "\nSelect crossing line to break : "))))
    (princ "\nNull Selection please try again: ")
  )
  (setq LINE1 (entget ENT1))
  (setq LN (cdr (assoc 8 LINE1)))
  (setq P1 (trans (cdr (assoc 10 LINE1)) 0 1 ))
  (setq P2 (trans (cdr (assoc 11 LINE1)) 0 1 ))
  (setq AN (angle P1 P2))
  (while (not (setq ENT2 (car (entsel "\nSelect line to cross over : "))))
    (princ "\nNull Selection please try again: ")
  )
  (setq LINE2 (entget ENT2))
  (setq P3 (trans (cdr (assoc 10 LINE2))0 1))
  (setq P4 (trans (cdr (assoc 11 LINE2))0 1))
  (setq IN (inters P1 P2 P3 P4))
  (setq BPT1 (polar IN AN (/ *mygap* 2)))
  (setq BPT2 (polar IN (+ AN pi) (/ *mygap* 2)))
  (command "break" ENT1 BPT1 BPT2)
  (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode 'clayer) sv_vals)
  (setq *error* nil)   
  (princ)
)

 

Edited by dlanorh
Link to comment
Share on other sites

Or maybe :

 

;;;|=====================================================================|;;;
;;;|   Gap Line Tool							 |;;;
;;;|provided by James Hodson, SDC Edmonton, Company, 2009		 |;;;
;;;|=====================================================================|;;;
;;;
;;;
(alert "Type GL to start, click a horizontal line to gap off of a vertical,
and click a vertical line to gap off of a horizontal

This runs again immediately if you hit space bar after your first two lines.

Happy Clicking!")

(defun c:gl (/ *error* sv_vals ar LINE1 LN P1 P2 AN LINE2 P3 P4 IN BPT1 PBT2)

  (defun *error* (msg)
    (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode 'clayer) sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
  );end_*error*
  
  (setq sv_vals (mapcar 'getvar  (list 'cmdecho 'osmode 'clayer)))
  
  (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode) '(0 0))

  (cond ( (not *mygap*) 
          (setq *mygap* 0.0)
          (initget 6)
          (setq *mygap* (cond ( (getreal (strcat "\nEnter Gap Size <" (rtos *mygap* 2 3) "> : "))) (*mygap*)))
        )  
  );end_cond
    
  (while (not (setq ENT1 (car (entsel "\nSelect crossing line to break : "))))
    (princ "\nNull Selection please try again: ")
  )
  (setq LINE1 (entget ENT1))
  (setq LN (cdr (assoc 8 LINE1)))
  (setq P1 (trans (cdr (assoc 10 LINE1)) 0 1 ))
  (setq P2 (trans (cdr (assoc 11 LINE1)) 0 1 ))
  (setq AN (angle P1 P2))
  (while (not (setq ENT2 (car (entsel "\nSelect line to cross over : "))))
    (princ "\nNull Selection please try again: ")
  )
  (setq LINE2 (entget ENT2))
  (setq P3 (trans (cdr (assoc 10 LINE2))0 1))
  (setq P4 (trans (cdr (assoc 11 LINE2))0 1))
  (setq IN (inters P1 P2 P3 P4))
  (setq BPT1 (polar IN AN (/ *mygap* 2)))
  (setq BPT2 (polar IN (+ AN pi) (/ *mygap* 2)))
  (command "break" ENT1 BPT1 BPT2)
  (mapcar '(lambda (x y) (setvar x y)) (list 'cmdecho 'osmode 'clayer) sv_vals)
  (setq *error* nil)   
  (princ)
)

 

  • Thanks 1
Link to comment
Share on other sites

dlanorh, that;s it! Thanks to you and Tharwat for all your help. I'm thrilled now and will make breaking wiring on my drawing a lot faster.

Thank you very much again,

David

Link to comment
Share on other sites

My $0.05 avoid initget,

 


(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (= *mygap* nil)(setq *mygap* 0.125))
(setq *mygap* (atof (nth 0 (AH:getvalsm (list "Gap value" "Enter gap value" 10 8 (rtos *mygap* 2 3 ))))))


 

This is the latest version of Multi getvals.lsp

 

image.png.78ac95ba5d7ea5c3dedeac3a8c554475.png

 

Multi GETVALS.lsp

Link to comment
Share on other sites

  • 5 weeks later...

BIGAL,

 

i can't get your lisp routine to work. I renamed it to linegap.lsp because a space can't be used loading multi getvals.lsp. When I load this lisp it outputs AH:GETVALSM. How do I execute this lisp after loaded?

 

Thank you very much,

David

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...