Author Topic: Lisp help  (Read 5855 times)

0 Members and 1 Guest are viewing this topic.

cadd4la

  • Newt
  • Posts: 27
Lisp help
« on: September 05, 2018, 04:35:12 PM »
Can someone please help me combine this lisp to have multiple distances by the use of a list of distances

For example, if I wanted this lisp to offset 6" I type "OD" and a list of distance comes up and then select 6. instead of having a code for each one of the distances I need.

Code: [Select]
(defun C:OD (/ ss pt)
;;(prompt "Select object to offset: ")
(setq ss (ssget "+.:E:S" '((0 . "lwpolyline,line,spline,circle,ellipse"))))
(setq pt (getpoint "Specify point on side to offset: "))
(command "offset" "12" ss pt "")
(initget "Yes No")
(setq RO (getkword "\nDelete original? [Yes/No] <N>: "))
(if (= RO "Yes")
(command "erase" ss "")
)

Thanks,
Windows 10 x64 - AutoCAD 2023

Dlanor

  • Bull Frog
  • Posts: 263
Re: Lisp help
« Reply #1 on: September 05, 2018, 05:58:48 PM »
A list of distances may help.

However by making a small change, try this
Code: [Select]
(defun OD (dist / ss pt RO)
;;(prompt "Select object to offset: ")
(setq ss (ssget "+.:E:S" '((0 . "lwpolyline,line,spline,circle,ellipse"))))
(setq pt (getpoint "Specify point on side to offset: "))
(command "offset" dist ss pt "")
(initget "Yes No")
(setq RO (getkword "\nDelete original? [Yes/No] <N>: "))
(if (= RO "Yes")
(command "erase" ss "")
);end_defun
  )

It's now changed into a function that has to be typed on the command line like this : (OD 6)  The brackets are needed.

Replace the red 6 with the distance you require. If you want something different don't hesitate to ask.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Lisp help
« Reply #2 on: September 05, 2018, 07:24:07 PM »
More to look at:
-------------   Offset  -----------------
Advanced Offset to both side by VVA <Vladimir Azarko>
Offset selected object to both side and change (optional) layer of new object to current
http://www.theswamp.org/index.php?topic=23069.0
http://www.theswamp.org/index.php?topic=30650.0  Dynamic Offset by LeeMac
http://www.theswamp.org/index.php?topic=39645.msg449444#msg449444
http://www.theswamp.org/index.php?topic=32743.0 VLA-Offset using Point Selection
http://www.theswamp.org/index.php?topic=24688.0 Staggered Multiple Offset by RonJonp
http://www.theswamp.org/index.php?topic=6209.0 Here is a nice example of Offset by Jürg Menzi
http://www.theswamp.org/index.php?topic=23921.0 Offset direction discussion
http://www.theswamp.org/index.php?topic=21933.msg266096#msg266096 Offset Segments by Gile
http://www.theswamp.org/index.php?topic=27636.0  Array
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadd4la

  • Newt
  • Posts: 27
Re: Lisp help
« Reply #3 on: October 30, 2018, 03:35:22 PM »
Dlanor, thank you so much for taking a pass at the code, however, I have the following problem when I use the code.

Command: OD
; error: too few arguments
Windows 10 x64 - AutoCAD 2023

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Lisp help
« Reply #4 on: October 30, 2018, 04:37:40 PM »
I have the following problem when I use the code.

Command: OD
; error: too few arguments

It's now changed into a function that has to be typed on the command line like this : (OD 6)  The brackets are needed.

Replace the red 6 with the distance you require.

cadd4la

  • Newt
  • Posts: 27
Re: Lisp help
« Reply #5 on: November 02, 2018, 02:27:31 PM »
Sorry, stilling have a problem.

I type in (OC6) and it doesn't work.  can't have a space between the C and 6.

Thanks,

Cadd4la
Windows 10 x64 - AutoCAD 2023

Dlanor

  • Bull Frog
  • Posts: 263
Re: Lisp help
« Reply #6 on: November 02, 2018, 02:42:33 PM »
Sorry, stilling have a problem.

I type in (OC6) and it doesn't work.  can't have a space between the C and 6.

Thanks,

Cadd4la

You can have a space between the c and the 6 if you type (OC 6) because it is a function and autocad recognises the opening bracket and waits for a closing bracket ignoring the space. It works for me in 2012

Still waiting for a list of distances.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Lisp help
« Reply #7 on: November 02, 2018, 03:37:50 PM »
I type in (OC6) and it doesn't work.  can't have a space between the C and 6.

It's now changed into a function that has to be typed on the command line like this : (OD 6)  The brackets are needed.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Lisp help
« Reply #8 on: November 02, 2018, 07:09:54 PM »
I type in (OC6) and it doesn't work.  can't have a space between the C and 6.

It's now changed into a function that has to be typed on the command line like this : (OD 6)  The brackets are needed.

I can't believe I missed that.  :uglystupid2:

cadd4la

  • Newt
  • Posts: 27
Re: Lisp help
« Reply #9 on: November 05, 2018, 04:13:41 PM »
Dlanor,

Here is the list I would like to offset inches from 1" up to 36"

also, I need to offset feet from 1' to 50' along with the inches in-between i.e 1'-1", 1'-2", etc. Not sure if you would have the code be (OD1-2) for feet and have the inches (OOD6) I can fill in the list of distances myself once I get your code.

Thanks, for all your help.

Cadd4la
Windows 10 x64 - AutoCAD 2023

Dlanor

  • Bull Frog
  • Posts: 263
Re: Lisp help
« Reply #10 on: November 05, 2018, 04:58:49 PM »
What are your primary drawing units feet or inches? Does this change? The reason I'm asking is that this is will probably require a small dialog as the range is somewhat larger than I anticipated, also an offset of 3' is the same as 36" so why the inches?

cadd4la

  • Newt
  • Posts: 27
Re: Lisp help
« Reply #11 on: November 07, 2018, 08:35:50 PM »
Dlanor,

No real reason to have both 36" and 3'. My primary drawing units are in inches but I don't what to have to remember if I what to offset 9'-8" I have to enter (OD 116), I would like to enter (OD 9-8) and if I want 4" I use (OOD 4).

The code should be in inches but the dialog list should be 9'-8".

Thanks,
Windows 10 x64 - AutoCAD 2023

Dlanor

  • Bull Frog
  • Posts: 263
Re: Lisp help
« Reply #12 on: November 08, 2018, 04:15:59 AM »
Dlanor,

No real reason to have both 36" and 3'. My primary drawing units are in inches but I don't what to have to remember if I what to offset 9'-8" I have to enter (OD 116), I would like to enter (OD 9-8) and if I want 4" I use (OOD 4).

The code should be in inches but the dialog list should be 9'-8".

Thanks,

OK. That will help simplify everything.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Lisp help
« Reply #13 on: November 08, 2018, 01:06:23 PM »
Attached are a lisp file and a dcl file, I've minimally tested it.

Both routines use dynamic prompt and mode, and this is reset on exit. The option to delete the original uses this, and it will appear at the cursor allowing options to be selected with the mouse.

The lisp contains 2 command options :

ODD Type this to run the dialog version. This uses the dcl file which must be placed somewhere in the AutoCAD "Support File Search Path". The dialog is simple, select the Feet/Inches and choose whethers to select offset side or both sides. This option remembers the last input.

OD Type this to run the command line version. Unfortunately I cannot make your wish of (OD 6-7) come true as the argument is not passed. You are dropped into a prompt for the distance. This requires a string so now you can enter 6-7 or 6-7T  (distance 6' 7") the T on the end is optional and controls whether the offset side is by selection (absent) or both sides (T). When entering in feet and inches you must separate using the "-".  You can also enter in inches e.g. (28 or 28T) for 28". This is similar to entering in feet where the absence of the "-" denotes distance in inches.

Any feedback or changes welcome.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Lisp help
« Reply #14 on: November 09, 2018, 03:12:05 PM »
So what is wrong with this?
At the command line enter OD  3'-2"   
OD<space>then your number, yes you need ' for feet
Code - Auto/Visual Lisp: [Select]
  1. (defun c:od (/ dist ss pt)  
  2.   (setq dist (getdist "\nEnter distance: "))  (prompt "Select object to offset: ")
  3.   (setq ss (ssget "+.:E:S" '((0 . "lwpolyline,line,spline,circle,ellipse"))))
  4.   (setq pt (getpoint "Specify point on side to offset: "))
  5.   (command "offset" dist ss "_non" pt "")
  6.   (initget "Yes No")
  7.   (if (= "Yes" (getkword "\nDelete original? [Yes/No] <N>: "))
  8.     (command "erase" ss "")
  9.   )
  10. )
« Last Edit: November 22, 2018, 09:43:01 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.