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,153 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,154 Views
29 Replies
Replies (29)
Message 2 of 30

ВeekeeCZ
Consultant
Consultant

We cannot enhance the ortho anyhow. You can rotate in by 45°by setting SNAPANG but that's all.

To fix tracking to all 45 multiples you need to set the polar tracking.

And since F10 turns the F8 off and vise versa, you don't need any other commands/keys than these two.

0 Likes
Message 3 of 30

Anonymous
Not applicable

Yeah, I know there's no command for it in autocad, but isn't it possible to make a lisp file with that command? 

0 Likes
Message 4 of 30

Kent1Cooper
Consultant
Consultant

This should do it [minimally tested]:

 

(defun C:PT45 () ; = Polar-angle Toggle to 45-degree increments only, and back to previous
  (if (equal (getvar 'polarang) (/ pi 4) 1e-4); currently at 45d increments
    (if polang (setvar 'polarang polang)); then -- set to prior value if present
    (progn ; else
      (setq polang (getvar 'polarang)); save current setting
      (setvar 'polarang (/ pi 4)); set to 45-degree increments
    ); progn
  ); if
  (princ)
); defun

 

If you call it for the first time  when you're already at 45-degree increments, it does nothing.  But if you call it when set to other increments, it saves the current value before setting it to 45.  Then when you call it again, and it finds there's a saved value, it resets that.

Kent Cooper, AIA
0 Likes
Message 5 of 30

Anonymous
Not applicable

Polarang only  changes the angel of the polar tracking. I need a command that acts exactly like ortho, but it also includes 45 degree angle. Ortho only allows the line to be locked at 90 and 180, but I need the line to lock at 45 degree increments instead of every 90. Is that possible? Thank you.

0 Likes
Message 6 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Polarang only  changes the angel of the polar tracking. I need a command that acts exactly like ortho, but it also includes 45 degree angle. Ortho only allows the line to be locked at 90 and 180, but I need the line to lock at 45 degree increments instead of every 90. Is that possible? Thank you.


Not as far as I know.  I was assuming you could use the Polar tracking jump-to-when-close version of sort-of "locking" onto the angles, but no, it won't prevent you from going in other directions when not close enough to one of the 45 multiples.

Kent Cooper, AIA
0 Likes
Message 7 of 30

Anonymous
Not applicable

Really? That command's not possible to create? I need something that locks on only 45 degree increments and doesn't allow me to go to any other angel. 

0 Likes
Message 8 of 30

Anonymous
Not applicable

For example if you press line and then type "<45" it locks on to the 45. I would like it if it locks on to every 45 degree, so 45, 90, 135, 180, so on. Would that be possible?

0 Likes
Message 9 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Really? That command's not possible to create? I need something that locks on only 45 degree increments and doesn't allow me to go to any other angel.


[30 degrees is the devil, I suppose....]

 

You can get 45- and 135- and 225- and 315-degree angles only, but without  the 90-degree multiples, if that's of any use to you, by changing SNAPANG to 45 and having Ortho mode on.

Kent Cooper, AIA
0 Likes
Message 10 of 30

Anonymous
Not applicable

I need those and the 90 degree increments. This command would not be possible to make as a lisp file?

0 Likes
Message 11 of 30

Kent1Cooper
Consultant
Consultant

It might be possible....  The only way I can imagine is by using (grread) to get the cursor location, and evaluate the angle between the previous point [such as the start point of a Line] and there, and if it falls between [for example] 22.5 and 67.5 degrees, change the SNAPANG System Variable to 45.  As the cursor is moved around, I think it could probably change that repeatedly.  The crosshairs angle would jump between orthogonal and 45 degrees as you drift around, so it could be a little peculiar, visually.  I may pursue that concept a little later.

Kent Cooper, AIA
0 Likes
Message 12 of 30

Anonymous
Not applicable

I never heard of grread. Yeah this looks complicated. I'll look into grread. Thank you.

0 Likes
Message 13 of 30

ВeekeeCZ
Consultant
Consultant

When you come back down to earth you can try this simple macro that toggles SNAPANG 0 to 45 and back. Seems to me like suitable solution for your need. 

 

'_.snapang $M=$(if,$(eq,$(getvar,snapang),0),45,0) 

 

But good luck with the grread! THIS Lee's site might help you a bit.

0 Likes
Message 14 of 30

Anonymous
Not applicable

Not sure what you mean by come back down to earth, but I already have my polar tracking at 45. I need that command.  I appreciate the link. I'll try to figure that command out. It would help so much having that. Thank you.

0 Likes
Message 15 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

I never heard of grread. Yeah this looks complicated. I'll look into grread. Thank you.



It was  kind of complicated to get the pieces together, but this seems to work.  It is written to draw Lines specifically, Locked to the 45-degree-Increment directions.  The same principle could be applied to a Polyline if of only line segments and without getting into options, and with some modification could probably be made into a function that could be applied in things like Move and Copy.

 

End the drawing of Lines with it by hitting Enter or space [or, really, with any typed character], not  with ESCape.  [You can hit ESCape, but will need to again, or hit another Enter -- there may be a way to get around that limitation.]

 

The trickiest part turned out to be that neither (grdraw) nor the picking of a point under (grread) honors Ortho mode, so I had to figure out how to calculate what the Ortho-ized position in relation to the previous point and the cursor would be.

 

(defun C:LL45I (/ done cur pt); = Lines Locked to 45-degree angle Increments
  (command "_.line" pause)
  (while (not done)
    (setq cur (grread T 13 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 ; Ortho-ized location
              (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))))
        ); grdraw
      ); cur=5 condition
      ((= (car cur) 3) (command pt)); picked a point -- use Ortho-ized one
      ((= (car cur) 2) (command "") (redraw) (setq done T))
        ; keyboard input [typically Enter/space, but any other than Esc]
    ); cond
  ); while
  (setvar 'snapang 0); return to normal
  (princ)
); defun

 

Another possible "improvement," if you think it would be one, would be to use (grdraw) or (grvecs) to add the extra crosshair directions  [an 8-armed cursor star], so that as with regular Ortho, all the locked-in directions would show in the crosshairs.  Then the look of the crosshairs wouldn't pop back and forth between the 45's and the 90's as you move the cursor around, the way it does in this routine, but that might be a bit much, visually.

Kent Cooper, AIA
0 Likes
Message 16 of 30

Anonymous
Not applicable

What would the command be to turn on the command?

0 Likes
Message 17 of 30

Anonymous
Not applicable

When I do the "_.line" command it only turns ortho on. 

0 Likes
Message 18 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

What would the command be to turn on the command?


The part immediately following  (defun C:  is always the command name, in this case LL45I [see the blue-initialed reason why in Message 15], but you can change that to any command name you like.  Do I assume correctly that you know how to put that code into a .lsp file and load it?

Kent Cooper, AIA
0 Likes
Message 19 of 30

Anonymous
Not applicable

Ok awesome thank you. Yeah I know how to load it and run lisp files. I've made a few very simple ones before that I use a lot. I see this works exactly how I want it to work, the only thing that's missing is the snap. It turns snap function off. Is there a way to turn on snap function with this?

0 Likes
Message 20 of 30

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... the only thing that's missing is the snap. It turns snap function off. Is there a way to turn on snap function with this?


If you're talking about positional  or grid  snap, it doesn't turn Snap off, and it remains on for me -- do you have it on when you begin?  I see a difficulty with that, however.  When you draw a vertical or horizontal Line with Snap on, then turn to one of the 45 angles, the Snap is still going to be "based" at the origin, in relation to which the end of the vertical or horizontal Line is not likely to be at some Snap-increment distance in the diagonal direction.  So the lengths at Snap positions along your diagonal direction are not going to be multiples of the Snap setting.  Should the routine change the SNAPBASE System Variable to be at the last point with every pick, so you can Snap clean distances?  [This is where Polar tracking at 45-degree increments is better -- because SNAPANGLE is not changed, Snap locations will still lie nicely along angled directions from other Snap locations, though of course lengths of diagonal Lines won't be snap-increment multiples.]

 

If you're talking about Object  snap, the Osnap icons don't show under (grread), but running modes are applied when you pick, if there's something Osnappable-to within the Aperture distance.  But do you want that?  It will almost always throw off your 8-direction-"orthogonal" Line angles.

Kent Cooper, AIA
0 Likes