Author Topic: Modifying Lee Mac's PolyTools "PJ" routine without success.  (Read 2647 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Re: Modifying Lee Mac's PolyTools "PJ" routine without success.
« Reply #15 on: August 29, 2022, 06:19:41 PM »

Edit: ...thought pattern.

Thanks for all the discussion. It helps seeing more accomplished ppl discuss varying ideas that us lesser beings might not ever see or understand.

I did question what lines 7 and 39 were doing. Totally as an assumption/guess I took it to mean if the variable exists as line 7 states, error, because it should really be as line 39 states. I certainly didn't take into account versions or platforms beyond my simple though pattern.

J. Logan 
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Modifying Lee Mac's PolyTools "PJ" routine without success.
« Reply #16 on: August 30, 2022, 04:06:03 PM »

Edit: ...thought pattern.

Thanks for all the discussion. It helps seeing more accomplished ppl discuss varying ideas that us lesser beings might not ever see or understand.

I did question what lines 7 and 39 were doing. Totally as an assumption/guess I took it to mean if the variable exists as line 7 states, error, because it should really be as line 39 states. I certainly didn't take into account versions or platforms beyond my simple though pattern.

J. Logan

Those lines (36, 37, 38) in Lee's code are a slightly modified version of a wonderful generic error handler skeleton ElpanovEvgeniy posted years ago. I didn't save the link but I'll paste the text below.

Essentially, what the code below does is gather up the variables and their initial values and store them in a list. This list is then evaluated later during the error handler run (very nice, clean system by ElpanovEvgeniy).

The discussion was (in a nut-shell):
Lee introduced a feature in his version. I questioned the need for that feature.

ElpanovEvgeniy's error hander:
Code: [Select]
In the beginning of function I establish a list of the necessary environment variables,
list variable always miscellaneous:
Code:
(SETQ
  ERROR-LST-
  '("AUTOSNAP" "OSMODE" "APERTURE" "HPSPACE" "HPASSOC"
    "MIRRTEXT" "AUPREC" "LUPREC" "DIMZIN" "cecolor") 
  ERROR-LST- (mapcar '(lambda (a) (list 'setvar a (getvar a))) ERROR-LST-)
  )

Function *error*
Code:
(defun *error* (msg)
  (MAPCAR 'eval ERROR-LST-))

It is a universal *error* function *smile*
« Last Edit: August 30, 2022, 04:20:36 PM by JohnK »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Modifying Lee Mac's PolyTools "PJ" routine without success.
« Reply #17 on: August 30, 2022, 05:26:07 PM »
The discussion was (in a nut-shell):
Lee introduced a feature in his version. I questioned the need for that feature.
Evgeniy's example contains the answer to the question
it will crash on Acad2000 ;)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Modifying Lee Mac's PolyTools "PJ" routine without success.
« Reply #18 on: August 30, 2022, 05:41:36 PM »
I did question what lines 7 and 39 were doing. Totally as an assumption/guess I took it to mean if the variable exists as line 7 states, error, because it should really be as line 39 states. I certainly didn't take into account versions or platforms beyond my simple though pattern.

Analysing lines 36-39:
Code - Auto/Visual Lisp: [Select]
  1. (setq var '(cmdecho peditaccept)
  2.       val  (mapcar 'getvar var)
  3. )
  4. (mapcar '(lambda ( a b c ) (if a (setvar b c))) val var '(0 1))

Here we have:
Code - Auto/Visual Lisp: [Select]
  1. ;; Define a variable storing a list of symbols (this could also be strings) representing system variables
  2. var '(cmdecho peditaccept)
Code - Auto/Visual Lisp: [Select]
  1. ;; Retrieve the current values of those system variables (some of which may be nil if the system variable doesn't exist)
  2. val  (mapcar 'getvar var)
Code - Auto/Visual Lisp: [Select]
  1. ;; Here, mapcar iterates over every item in the lists 'val', 'var' and (0 1)
  2. ;; Within the lambda function:
  3. ;;    'a' = Current system variable value (which may be nil if the system variable doesn't exist)
  4. ;;    'b' = System variable symbol
  5. ;;    'c' = New system variable value
  6. ;; Within the lambda function, the 'if' statement just says, if the system variable has a value (i.e. it exists), set it to this new value
  7. (mapcar '(lambda ( a b c ) (if a (setvar b c))) val var '(0 1))

Those lines (36, 37, 38) in Lee's code are a slightly modified version of a wonderful generic error handler skeleton ElpanovEvgeniy posted years ago.

For the record, the code is not a modification of any existing function...

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Modifying Lee Mac's PolyTools "PJ" routine without success.
« Reply #19 on: August 30, 2022, 06:48:38 PM »
Great post, Lee.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

jlogan02

  • Bull Frog
  • Posts: 327
Re: Modifying Lee Mac's PolyTools "PJ" routine without success.
« Reply #20 on: August 31, 2022, 03:54:27 PM »
Well done Lee. If I can understand that explanation, anyone can.

Thanks.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10