TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cadd4la on September 05, 2018, 04:35:12 PM

Title: Lisp help
Post by: cadd4la 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,
Title: Re: Lisp help
Post by: Dlanor 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.
Title: Re: Lisp help
Post by: CAB 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
Title: Re: Lisp help
Post by: cadd4la 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
Title: Re: Lisp help
Post by: Lee Mac 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.
Title: Re: Lisp help
Post by: cadd4la 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
Title: Re: Lisp help
Post by: Dlanor 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.
Title: Re: Lisp help
Post by: Lee Mac 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.
Title: Re: Lisp help
Post by: Dlanor 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:
Title: Re: Lisp help
Post by: cadd4la 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
Title: Re: Lisp help
Post by: Dlanor 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?
Title: Re: Lisp help
Post by: cadd4la 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,
Title: Re: Lisp help
Post by: Dlanor 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.
Title: Re: Lisp help
Post by: Dlanor 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.
Title: Re: Lisp help
Post by: CAB 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. )
Title: Re: Lisp help
Post by: BIGAL on November 12, 2018, 09:17:09 PM
My $0.05 I wrote a lisp that just asks for the offsets includes left and right by using a -ve the input is a simple string either space or a comma input.

eg 12.3,45,-12.3,56 or 123.3 46 52 -12.56 -52.68

It is split into a list of multiple offsets and just do it. The feet part could be added fairly simply by adding a defun that looks for the - and returns the correct string for the offset command.

This is an old one will try to find the newere version its at home.
Code: [Select]
(defun C:MULOFF ( / obj s off)
(vl-load-com)
(setq obj (entsel "\nSelectObject"))
(setq s (getpoint "\nPick Offset side"))
(while (/= (setq off (getreal "\nEnter offset or Enter to exit")) nil)
(vl-cmdf "_.offset" off obj s "")
(setq obj (entlast))
)
)
(c:muloff)
Title: Re: Lisp help
Post by: cadd4la on November 21, 2018, 03:47:24 PM
Dlanor,

Thank you so much for the code. I have a problem using the OD option for inches, for example when I type in 9 I get "An Error : bad argument type: numberp: nil occured." but if I type in 0-9 the code will work.

Regards,
Title: Re: Lisp help
Post by: cadd4la on November 21, 2018, 04:10:46 PM
CAB,

Thank you so much. Your code is great with just one thing that I don't care for, I have to enter the ' and " so 2'-3" and not just 2-3.

Regards,

Cadd4la
Title: Re: Lisp help
Post by: CAB on November 22, 2018, 09:44:14 AM
Well you could omit the "
(setq dist (getdist "\nEnter distance: "))
Enter distance: 3'-2

Title: Re: Lisp help
Post by: cadd4la on November 29, 2018, 10:23:41 AM
Cab,

Thank you for your reply

Cadd4la
Title: Re: Lisp help
Post by: cadd4la on November 29, 2018, 10:24:57 AM
BIGAL,

Thank you for your $0.05.

Regards,

Cadd4la