Jump to content

How to use lisp to enter the angle of inclination of the line in degrees


Nikon

Recommended Posts

Added some convenience:

(defun c:11 (/ p0 ang dist)
 (defun 11error (errormsg /)
  (setvar "SNAPANG" old_snapang) ; reset variables
  (setvar "ORTHOMODE" old_orthomode)
  (setq *error* temperr) ; reset *error*
  (prompt "\nFunction Canelled.")
 )
 (vl-load-com)
 (setq p0  (getpoint "Pick the first point >")
       ang (angtof (rtos (getreal "Enter angle >")) 0)
 )
 (setq Old_snapang (getvar "SNAPANG")) ; to record what it was, might not be 0
 (setq old_orthomode (getvar "ORTHOMODE"))
 (setq temperr *error*)
  ;store *error* ; can wait till here to set error function, after recording old variables
 (setq *error* 11error)
 (setvar "SNAPANG" ang)
 (setvar "ORTHOMODE" 1)
 (setq dist (distance p0 (getpoint p0 "Pick a second point >")))
 (setvar "SNAPANG" Old_Snapang) ; moved this here, seto to old value (no assumption what it was)
 (setvar "ORTHOMODE" old_orthomode)
 (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist))))
 (setq *error* temperr) ; reset error
 (princ)
)

 

  • Like 2
Link to comment
Share on other sites

47 minutes ago, Nikon said:
(defun c: 35 .........
(defun c: 50 ........
(defun c: 68 ..........

You can continue the list of angles

 

I have over 100 lisps in automatic download.
Opening files in AutoCAD takes a little longer, 
that's why I'm trying to make simple codes using macros...

 

Speed is always a compromise between loading and running the automation and doing it manually. For example if I had routines that I used once a year that took 1/10th second to load each then it might not be optimistic to load them on every drawing. If I had routines that I used in virtually every drawing then even that 1/10th second each it is well worth loading them,

 

BigAl usually has to hand or in his memory a line that loads a LISP on command, so you could type in '30' if the command isn't loaded then it is loaded. Makes opening drawings quicker (I think you need the LISPs in a trusted file location?).

  • Like 1
Link to comment
Share on other sites

28 minutes ago, 1958 said:

Added some convenience:

(defun c:11 (/ p0 ang dist)
 (defun 11error (errormsg /)
  (setvar "SNAPANG" old_snapang) ; reset variables
  (setvar "ORTHOMODE" old_orthomode)
  (setq *error* temperr) ; reset *error*
  (prompt "\nFunction Canelled.")
 )
 (vl-load-com)
 (setq p0  (getpoint "Pick the first point >")
       ang (angtof (rtos (getreal "Enter angle >")) 0)
 )
 (setq Old_snapang (getvar "SNAPANG")) ; to record what it was, might not be 0
 (setq old_orthomode (getvar "ORTHOMODE"))
 (setq temperr *error*)
  ;store *error* ; can wait till here to set error function, after recording old variables
 (setq *error* 11error)
 (setvar "SNAPANG" ang)
 (setvar "ORTHOMODE" 1)
 (setq dist (distance p0 (getpoint p0 "Pick a second point >")))
 (setvar "SNAPANG" Old_Snapang) ; moved this here, seto to old value (no assumption what it was)
 (setvar "ORTHOMODE" old_orthomode)
 (entmakex (list (cons 0 "LINE") (cons 10 p0) (cons 11 (polar p0 ang dist))))
 (setq *error* temperr) ; reset error
 (princ)
)

 

 

There is a slightly more optimised way to set and reset variables once you get more than about 2 or 3:

 

;;Include near the beginnin of the code: 
  (setq vars '("CMDECHO" "NOMUTT" "SNAPANG")) ;; Variables to change as a list
  (setq old_Vars (mapcar 'getvar vars))       ;; get existing variable values
  (mapcar 'setvar vars '(0 1 1))              ;; set variables to new values (in order of the list above)


;;Reset the variables
  (mapcar 'setvar vars old_Vars)

 

Change to suit. 

  • Like 2
Link to comment
Share on other sites

54 minutes ago, Steven P said:

BigAl usually has to hand or in his memory a line that loads a LISP on command, so you could type in '30' if the command isn't loaded then it is loaded. Makes opening drawings quicker (I think you need the LISPs in a trusted file location?).

I've been worried about the question for a long time: 
how can I upload lisps by name from some list (for example, in dwg), 
and not add rarely used ones to the startup...

Link to comment
Share on other sites

1 hour ago, Nikon said:

1958, please explain what convenience? They seem to work the same way...

 

open up bother versions in their own notepad or similar and compare them side by side - a good way to learn, spot the difference and consider what was done and why? 

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Nikon said:

1958, please explain what convenience? They seem to work the same way...

In the latter option, the dotted line indicates the direction along a given angle, rather than following the cursor.😀

I apologize, but I and the author of the topic are Russian speakers, so I will repeat the answer in Russian.

В последнем варианте пунктирная линия указывает направление по заданному углу, а не бегает за курсором. 😀

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Steven P said:

There is a slightly more optimised way to set and reset variables once you get more than about 2 or 3

Thanks a lot for the tip! There are many things I don't know yet, I'm still learning, although I will soon be 66 years old.🙂

  • Like 2
Link to comment
Share on other sites

 

On 28.12.2023 at 19:02, 1958 said:

В последнем варианте пунктирная линия указывает направление по заданному углу, а не бегает за курсором

Да, это действительно так.

 

 

 

Edited by Nikon
Link to comment
Share on other sites

 

(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("ZZZ"))
(autoload "COVER" '("COVER"))
(autoload "DIMFLIP" '("DIMFLIP"))
(autoload "DRAWXFALL" '("DRAWXFALL"))
(autoload "DRAWPIPE" '("DRAWPIPE"))
(autoload "EDITRL" '("EDITRL"))

Load on demand is easy just put in a startup lisp that is automatically loaded.

 

Thinking some more though easier to put in a menu as an option. Load a lisp with all the defuns in it.

 

I would make something like type A30 on command line and it runs a lisp that splits the A & 30. Look at attached code it does circles, fillet, offset etc F123 C345. Again load as required, if only every now and then.

 

image.png.7b352f9bd9b699184720024197d97d31.png

 

fillet reactor.lsp

 

 

 

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

For Nikon you can not use "." in the value you need to use "-" so F123-45 will work. The "." is  a valid character in the input and gets treated different to a decimal point.

 

So A30 would set the snapang to 30, then ask for pt1 pt2. If you get stuck just ask, can have 26 functions A-Z, C, O & F used.

  • Confused 1
Link to comment
Share on other sites

On 29.12.2023 at 03:26, BIGAL said:
(autoload "COPY0" '("COPY0"))

When I type in the command line (autoload "11" '("11"))
; error: too many arguments

How to make lisp load and immediately start executing the command.
 

Edited by Nikon
Link to comment
Share on other sites

I think:

 

(autoload "<fileName>" '("<LISP Name 1>" "<LISPName 2>")) ; where <LISPName x> are LISPs contained in <filename>

 

The file should be saved in your trusted locations, no need to include the extension '.LSP' I think, might be wrong

Edited by Steven P
  • Thanks 1
Link to comment
Share on other sites

Another alternative is create load of small LISPs in a single file, where the LISP name is what you want, and take away the "c:" prefix from the actual LISP to use - should be fairly fool proof if not the most elegant. Load this file at start-up

 

(defun c:testthis ( / )
  (load "....filepath....\\a.lsp" "a.lsp Failed to Load") ;;Using full path and not variable
  (testthis)
)

 

  • Thanks 1
Link to comment
Share on other sites

On 29.12.2023 at 13:16, Steven P said:
(autoload "<fileName>" '("<LISP  

If the name is lisp - "11" and the call command is also  "11"

(_autoload "<11>" '("<11>")) 

; error: too many arguments
Or like this:   

(_autoload "11.lsp" '("<11>")) 

; error: too many arguments

Edited by Nikon
Link to comment
Share on other sites

3 hours ago, Steven P said:
(autoload "<fileName>" '("<LISP 
(defun c:testthis ( / )
 (load "C:\Program Files\Autodesk\AutoCAD 2015\Support \\a.lsp" "a.lsp Failed to Load") ;;Using full path and not variable
 (testthis)
)

Command: LOAD
; error: too few arguments

? ? ?

Link to comment
Share on other sites

Got to apply these to your own circumstances.

 

The < > are just to highlight what is expected so it <Filename> might be replaced be "11"

 

The second option should work if you replace the details with your specific LISP file name instead of a.lsp. You might need to use double \\ instead of single in the file path

  • Thanks 1
Link to comment
Share on other sites

The last line in the 11.lsp needs to be (c:11) this will run it once it is loaded. From then if needing to do again typing 11 will run it. 

 

(defun c:11 ( / .....
.....
..
)
(c:11)

I think it would be easier though to have a menu option to do snapang line the menu can have a sub menu with all the angles. You can then use the menu for next or type the angle. Use ^c^c^p(if (not 11)(load "11")) 11 in the menu.

 

Happy to help making a menu you can see how many options we had. Most of the menu's used a Load function. 

 

Edited by BIGAL
  • Thanks 1
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...