Lisp command that toggles from polar tracing to ortho w/45 degrees

Lisp command that toggles from polar tracing to ortho w/45 degrees

Anonymous
Not applicable
3,175 Views
29 Replies
Message 1 of 30

Lisp command that toggles from polar tracing to ortho w/45 degrees

Anonymous
Not applicable

Hello, I need a command that allows me to do ortho, but also include the 45 degree angles. Then I press the command again and it switches from that to regular polar tracking. Reason I need this is because it’s the easiest way to draw roof planes because most have 90 and 45 degree angles. Ortho only works with 90 degree angles, but I need it to lock on to every 45 degree angle.  Please help with this. Thank you!

0 Likes
3,176 Views
29 Replies
Replies (29)
Message 21 of 30

Anonymous
Not applicable

I'm not sure what grid or positional snap is. I'm talking about O snap, so for example. This command acts as if O snap is off, so say I do 3 sides of a triangle and it's off by a little bit, If i had osnap on I could snap that last line to the end of the first line and it still makes the full triangle. Or I could snap that to the mid point, but with this I can't snap on to the mid point or end point. Another example is if Ortho is on, the line goes vertical, if the mid point of a horizontal line is off, I can still snap to that mid point of the other line and it creates that line.  So Osnap would still be functioning. So essentially right now it acts as if Osnap is off, but I want it to act like osnap would be on. Would that be possible? Besides that I am extremely happy of how it works, it works perfectly. The Osnap thing would be the last thing that it would need and it would be perfect. Exactly how I'd want it to work.  I'm not sure what running modes are. 

0 Likes
Message 22 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I'm not sure what grid or positional snap is. I'm talking about O snap, so for example. This command acts as if O snap is off, so say I do 3 sides of a triangle and it's off by a little bit, If i had osnap on I could snap that last line to the end of the first line and it still makes the full triangle. Or I could snap that to the mid point, but with this I can't snap on to the mid point or end point. Another example is if Ortho is on, the line goes vertical, if the mid point of a horizontal line is off, I can still snap to that mid point of the other line and it creates that line.  So Osnap would still be functioning. So essentially right now it acts as if Osnap is off, but I want it to act like osnap would be on. Would that be possible? ....  I'm not sure what running modes are. 


About grid or positional Snap, read about the SNAP command, the SNAPMODE and SNAPSIZE System Variables, and related topics.

 

"Running" modes are the Object-snap modes that are in effect when Osnap is turned on.  That can be any combination of the possibilities [with a few exceptions] -- I prefer to have the END/MID/INT/PER combination running most of the time, and call for particular other ones only when needed.  Read about the OSMODE System Variable.

 

When I use the command, if I have Osnap on, though the little green icons don't appear under (grread) operation, still if I pick in the vicinity of an Osnappable location [within reach of the Osnap aperture -- read about the APERTURE System Variable], then the most applicable Osnap mode is  applied.  It doesn't act as if Osnap is off, except in the sense that it doesn't "preview" a location it's going to snap to, but it still snaps to it.

Kent Cooper, AIA
0 Likes
Message 23 of 30

Anonymous
Not applicable

Oh ok I see. Thank you very much! 

0 Likes
Message 24 of 30

Anonymous
Not applicable

I'm trying to add the feet, for example I press the command and then i click the point to start the line. Then I type in 62' and it cancels the command and doesn't allow me to write the distance I want the line at. Is there a way to get that functionality in it? 

0 Likes
Message 25 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I'm trying to add the feet, for example I press the command and then i click the point to start the line. Then I type in 62' and it cancels the command and doesn't allow me to write the distance I want the line at. Is there a way to get that functionality in it? 


I'll have to think about that....  Under (grread), any keyboard entry falls under where it says (= (car cur) 2), the 2 being the indicator that it's keyboard entry [rather than mouse movement (5) or pick (3)].  Currently, any keyboard entry ends it, as a simple way to "cover" Enter and space as possibilities, and that's why the instructions say you can type anything, not just Enter/space.  It also knows what character was typed, so it could be adjusted to end only with Enter or space specifically, and to recognize when the typed character is a number.  What I would need to ponder is how to then allow further numerical input, until you "register" that you're done with Enter, and combine that with the initial triggering character.  The calculating of the resulting point shouldn't be too hard.

 

But I can't work on that today -- maybe this evening.

Kent Cooper, AIA
0 Likes
Message 26 of 30

Anonymous
Not applicable

Yeah I see what you're saying. Makes sense. Take your time. Thank you so much for the help!

0 Likes
Message 27 of 30

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

@Anonymous wrote:

I'm trying to add the feet, for example I press the command and then i click the point to start the line. Then I type in 62' and it cancels the command and doesn't allow me to write the distance I want the line at. Is there a way to get that functionality in it? 


I'll have to think about that.... maybe this evening.


Well, I think this does it:

(defun C:LL45I (/ cmde done cur pt); = Lines Locked to 45-degree angle Increments
  (setq cmde (getvar 'cmdecho))
  (command "_.line" pause)
  (setvar 'cmdecho 0)
  (prompt "\nNext point or <exit>: ")
  (while (not done)
    (setq cur (grread T 12 0))
    (cond
      ((= (car cur) 5); move cursor
        (setvar 'snapang ; nearest 45-degree increment to cursor location
          (* (/ pi 4) (fix (+ (/ (angle (getvar 'lastpoint) (cadr cur)) (/ pi 4)) 0.5)))
        ); setvar
        (redraw); eliminate previous rubber-band
        (grdraw ; rubber-band
          (getvar 'lastpoint) ; from
          (setq pt
            (inters
              (getvar 'lastpoint) (polar (getvar 'lastpoint) (getvar 'snapang) 1)
              (cadr cur) (polar (cadr cur) (+ (getvar 'snapang) (/ pi 2)) 1)
              nil
            ); inters
          ); setq
          (cdr (assoc 62 (tblsearch "layer" (getvar 'clayer)))); current Layer's color
        ); grdraw
      ); cur=5 condition
      ((= (car cur) 3) (command pt)); picked a point -- use Ortho-ized one
      ((= (car cur) 2) ; keyboard entry
        (cond
          ((member (cadr cur) '(13 32)); Enter or space
            (command "") (redraw) (setq done T); finish
          ); Enter/space condition
          ((< 48 (cadr cur) 58); 1 to 9
            ; [assuming distance entry will not start with 0, nor be negative]
            (command
              "_none"
              (polar
                (getvar 'lastpoint)
                (getvar 'snapang)
                (distof (strcat (chr (cadr cur)) (getstring (chr (cadr cur)))))
              ); polar
            ); command
          ); numerical character condition
          (T (prompt "\nInvalid input.")); go back to (while)
        ); cond [which character]
      ); keyboard-entry condition
    ); cond [which input method]
    (prompt "\nNext point or <exit>: ")
  ); while
  (setvar 'snapang 0); return to normal
  (setvar 'cmdecho cmde)
  (princ)
); defun

There's a little quirky aspect to it when you type in a distance.  The (grread) reacts immediately upon striking any keyboard character, and it knows what that one character is.  It then uses that single character as a prompt, so you see it again at the command line, and you continue to type [if additional character(s)], and it puts together that first character with what you typed subsequently, and converts that overall string into the distance.  But something about that operation means that there's a little bit of a half-space-ish width after the first character as prompt, before whatever more you type in [if anything].  Don't be thrown by that -- it seems to work correctly.

 

I also had it turn off command echoing, and provide the shortened next-point prompt, so you don't see the Undo/Close options of LINE's standard prompt.  The oddity about that is that every time you move the cursor even a little, (grread) kicks in again, and that prompt is put up again.  So if you type something other than Enter or space or a non-zero number, the Invalid-input prompt goes in, but with any movement of the cursor, it moves up and quickly out of view.  So if you hit a key that's invalid, you may not notice the prompt to that effect fly by, but carry on.  Maybe later I'll think about having it recognize U and C for Undo and Close options.

 

As usual, it could use *error* handling to ensure resetting the System Variables, but that can be added easily enough if it works for you otherwise.

Kent Cooper, AIA
0 Likes
Message 28 of 30

Anonymous
Not applicable

Ok, this works perfect, but this time the Osnap thing doesn't work. I put my cursor close to the mid point and also tried putting it on the end point, but it doesn't snap to that. 

0 Likes
Message 29 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... the Osnap thing doesn't work. I put my cursor close to the mid point and also tried putting it on the end point, but it doesn't snap to that. 


I found it sometimes does and sometimes doesn't, and eventually realized why.  When you pick, the LINE command is being fed the calculated locked-to-45-increment-directions location, that is, the end of the locked-direction rubber-band line -- it is not  being fed the cursor  location.  If Osnap is on, it is snapping to the closest Osnappable place to that calculated location [if there is one], which will sometimes, but only  sometimes, be the same as the closest Osnappable location to the where the cursor is.

 

I'm not sure there's any way to overcome that and  keep the locked-to-45's operation.  But if I think of anything, I'll be back, and others feel free to jump in if you know of a way.

Kent Cooper, AIA
Message 30 of 30

Anonymous
Not applicable

Hmm, that's interesting. I'll keep on checking this. Thank you very much though. This is such a huge help. The tool is so useful. 

0 Likes