Zoom affects LISP

Zoom affects LISP

andelo523
Enthusiast Enthusiast
1,745 Views
8 Replies
Message 1 of 9

Zoom affects LISP

andelo523
Enthusiast
Enthusiast

Hi everyone,

 

I'm kinda diving into the LISP programing, and I got to the point where I wanted to do some exercise with drawing specific symbols with Lines, Polylines, Arcs etc. I wrote a LISP for a Polyline Octagon, and it's working perfectly, but only when I do some serious zoom in. When I zoom out to much it draws something else. Does someone know why this occurs, and how can I fix this zooming issue?

 

(defun c:UMF8 (/ pt1)
(setq pt1 (getpoint "\nPick point: "))
(command "_ucs" pt1 "")
(command "_PLINE" "2.5,5" "5,2.5" "5,-2.5" "2.5,-5" "-2.5,-5" "-5,-2.5" "-5,2.5" "-2.5,5" "2.5,5" "")
(command "_ucs" "world" "")
(princ)
) ; end defun

 

Thanks in advance.

0 Likes
Accepted solutions (2)
1,746 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

That looks like the effect of having running Object Snap modes on.  Turn off Osnap [F3 key] and see whether it works as expected.  It can be built into the command if you like, including saving the current setting first, and restoring it at the end.

 

Also, it's far better to draw the Polyline this way:

 

(command "_PLINE" "2.5,5" "5,2.5" "5,-2.5" "2.5,-5" "-2.5,-5" "-5,-2.5" "-5,2.5" "-2.5,5" "_close")

 

because the way you have it, there are two vertices in the same place, which can cause trouble with certain operations.

Kent Cooper, AIA
0 Likes
Message 3 of 9

andelo523
Enthusiast
Enthusiast

Yes, it was indeed the Snap mode that caused the problem. I modified the LISP with osmode settings, to have some basic osnaps when picking the point, then turn it off while the LISP is creating the geometry, and then setting it back to my custom settings at the end.

 

(defun c:UMF8 (/ pt1)
(setvar 'osmode 31)
(setq pt1 (getpoint "\nPick point: "))
(command "_ucs" pt1 "")
(setvar 'osmode 0)
(command "_PLINE" "2.5,5" "5,2.5" "5,-2.5" "2.5,-5" "-2.5,-5" "-5,-2.5" "-5,2.5" "-2.5,5" "_close")
(setvar 'osmode 3583)
(command "_ucs" "world" "")
(princ)
) ; end defun

 

It works really great now. Thanks a lot Kent! 😊

Best Regards

 

0 Likes
Message 4 of 9

calderg1000
Mentor
Mentor

Regards @andelo523 

In a clean drawing your code will work fine, but in another with many entities around it, you will have problems with the object snap magnet activated. Temporary F3 is an option, otherwise you can do the same within code. Here I attach two ways to do it.

 

(defun c:UMF8 (/ pt1)
(setq pt1 (getpoint "\nPick point: "))
(command "_ucs" pt1 "")
(command "_PLINE" "NONE" "2.5,5" "NONE" "5,2.5" "NONE" "5,-2.5" "NONE" "2.5,-5" "NONE" "-2.5,-5" "NONE" "-5,-2.5" "NONE" "-5,2.5" "NONE" "-2.5,5" "NONE" "2.5,5" "C")
(command "_ucs" "world" "")
(princ)
) ; end defun


;;;------------------------------------------------------------------------------------------------------------
(defun c:UMF8B (/ pt1)
(setq pt1 (getpoint "\nPick point: "))
(setq o (getvar 'osmode))
(setvar 'osmode 0)
(command "_ucs" pt1 "")
(command "_PLINE" "2.5,5"  "5,2.5"  "5,-2.5"  "2.5,-5"  "-2.5,-5"  "-5,-2.5"  "-5,2.5"  "-2.5,5"  "2.5,5" "C")
(command "_ucs" "world" "")
(setvar 'osmode o)
(princ)
) ; end defun

 

 On the other hand, it is better to have a closed polyline; You can do them from the code with "C" or activate it from the properties box.


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

Here's another [slightly shorter] way you can do it:

 

(command "_.rectang" "-5,-5" "5,5" "_.chamfer" "_d" 2.5 "" "_.chamfer" "_p" "_last")

 

Kent Cooper, AIA
0 Likes
Message 6 of 9

andelo523
Enthusiast
Enthusiast

Yeah, that's a great idea too.

 

I have another question. What's the best/easiest way to make a selection set of every element that's been drawn within the LISP? For example when I draw some Lines together with arcs, then I would want to make a Polyline of the geometry.

 

I have this code, which is a corning point symbol, and it works.

 

(defun c:KRP (/ pt1 ss1 )
(setvar 'osmode 31)
(setq pt1 (getpoint "\nPick point: "))
(command "ucs" pt1 "")
(setvar 'osmode 0)
(command "_LINE" "1,0" "2,0" "" )
(command "_LINE" "0.5,-0.866" "1,-1.7321" "" )
(command "_LINE" "-0.5,-0.866" "-1,-1.7321" "" )
(command "_LINE" "-1,0" "-2,0" "" )
(command "_LINE" "-0.5,0.866" "-1,1.7321" "" )
(command "_LINE" "0.5,0.866" "1,1.7321" "" )
(command "_ARC" "2,0" "1.7321,-1" "1,-1.7321" "" )
(command "_ARC" "0.5,-0.866" "0,-1" "-0.5,-0.866" "" )
(command "_ARC" "-1,-1.7321" "-1.7321,-1" "-2,0" "" )
(command "_ARC" "-1,0" "-0.866,0.5" "-0.5,0.866" "" )
(command "_ARC" "-1,1.7321" "0,2" "1,1.7321" "" )
(command "_ARC" "0.5,0.866" "0.866,0.5" "1,0" "" )
(setvar 'osmode 3583)
(command "ucs" "world" "")
(princ)
) ; end defun

 

 

and here I have the code for making the poly, which I wanna do at the end. I just need to somehow get a selection set for it.

 

(command "_pedit" "_M" *selection set* "" "_J" "0" "")

 

 

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

Are you not getting trouble from the extra Enters "" at the ends of your Arc commands?  Giving it three points completes the command, so is the "" not calling up the previous [pre-this-routine] command?  Maybe you wouldn't notice if it was something like REDRAW....

 

There are at least two ways to do what you're looking for.  Both would start by making an empty selection at the beginning:

 

(setq ss (ssadd))

 

One approach is, following every drawing command, to add what was just drawn to the set:

 

(ssadd (entlast) ss)

 

The other way is to mark the latest drawn thing beforehand:

 

(setq elast (entlast))

 

then draw everything, then run a (while) loop looking for newer things than what's in the 'elast' variable -- as long as (entnext) returns something, add it to the selection.

Kent Cooper, AIA
0 Likes
Message 8 of 9

andelo523
Enthusiast
Enthusiast

To remove the "" from the Arc commands was good advice. It ran something in the background, and the LISP was kinda slow. When I removed it, the process switched to "turbo mode". 😁😄

 

So here's the code now, and it works like a charm!

(defun c:KRP (/ pt1 ss1 )
(setvar 'osmode 31)
(setq pt1 (getpoint "\nPick point: "))
(command "ucs" pt1 "")
(setvar 'osmode 0)
(setq ss1 (ssadd))
(command "_LINE" "1,0" "2,0" "" )
(ssadd (entlast) ss1)
(command "_LINE" "0.5,-0.866" "1,-1.7321" "" )
(ssadd (entlast) ss1)
(command "_LINE" "-0.5,-0.866" "-1,-1.7321" "" )
(ssadd (entlast) ss1)
(command "_LINE" "-1,0" "-2,0" "" )
(ssadd (entlast) ss1)
(command "_LINE" "-0.5,0.866" "-1,1.7321" "" )
(ssadd (entlast) ss1)
(command "_LINE" "0.5,0.866" "1,1.7321" "" )
(ssadd (entlast) ss1)
(command "_ARC" "2,0" "1.7321,-1" "1,-1.7321" )
(ssadd (entlast) ss1)
(command "_ARC" "0.5,-0.866" "0,-1" "-0.5,-0.866" )
(ssadd (entlast) ss1)
(command "_ARC" "-1,-1.7321" "-1.7321,-1" "-2,0" )
(ssadd (entlast) ss1)
(command "_ARC" "-1,0" "-0.866,0.5" "-0.5,0.866" )
(ssadd (entlast) ss1)
(command "_ARC" "-1,1.7321" "0,2" "1,1.7321" )
(ssadd (entlast) ss1)
(command "_ARC" "0.5,0.866" "0.866,0.5" "1,0" )
(ssadd (entlast) ss1)
(command "_pedit" "_M" ss1 "" "_J" "0" "")
(setvar 'osmode 3583)
(command "ucs" "world" "")
(princ)
) ; end defun

 

Thank you very much for your tipps. Like I said, I'm just getting started with the simple LISP programing, and don't have the knowledge yet to do more complex things. But every advice from the community is a great experience boost.. 😄👍

 

Have a nice day.

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

Having tried it and seen the result, I see that it's something you could have a routine draw as a Polyline directly, rather than drawing all the pieces and joining them together:

(command "_.pline" "1,0" "_w" 0 0
  "_a" "_d" "90" (polar '(0 0) (/ pi 3) 1)
  "_l" "@1<60"
  "_a" "_d" "150" (polar '(0 0) (* (/ pi 3) 2) 2)
  "_l" "@1<300"
  "_a" "_d" "210" "-1,0"
  "_l" "-2,0"
  "_a" "_d" "270" (polar '(0 0) (* (/ pi 3) 4) 2)
  "_l" "@1<60"
  "_a" "_d" "330" (polar '(0 0) (* (/ pi 3) 5) 1)
  "_l" "@1<300"
  "_a" "_d" "30" "2,0"
  "_l" "_close"
)

You could also make it into a Block [and WBLOCK that out to a drawing file for use elsewhere], and just INSERT it wherever you want one, which would be a memory saver if there are many of them.

Kent Cooper, AIA
0 Likes