Author Topic: offset, join then hatch lisp help please.  (Read 3393 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
offset, join then hatch lisp help please.
« on: March 10, 2017, 06:05:35 PM »
Hi

I have been working on a lisp this evening to offset a polyline, then join the ends, hatch internally then delete the line.
It seems to work well when the original polyline is open but when closed the wrong side of the offset line is hatched.
I'm surprised I managed to get as far with this as I have and am at a loss how to fix this issue.  Any help would be appreciated.
Thanks

Code - Auto/Visual Lisp: [Select]
  1. ;; bolted together from various sources.
  2. ;; copy line then offset the line, join ends, hatch and finally delete line.
  3. ;; pb 10/03/17
  4.  
  5.  
  6.  
  7.  
  8.    (defun c:HOFF (/ cl dist hi e p1)
  9.  
  10. (setq echo (getvar 'cmdecho))
  11. (setvar 'cmdecho 0)
  12.  
  13.       (setq cl (getvar "clayer"))
  14.       (if (setq dist (cond ((getreal (strcat "\n Specify offset distance <"
  15.                                            (rtos (if (not hi)
  16.                                                     (setq hi 0.5)
  17.                                                   )
  18.                                                   2
  19.                                                   2
  20.                                                   )
  21.                                             ">:"
  22.                                     )
  23.                             )
  24.                            )
  25.                            (t hi)
  26.                      )
  27.           )
  28.         (progn
  29.           (setq hi dist)
  30.           (if (not (tblsearch "LAYER" "CLASHING_HATCH"))
  31.             (entmakex '((0 . "LAYER")
  32.                         (100 . "AcDbSymbolTableRecord")
  33.                         (100 . "AcDbLayerTableRecord")
  34.                         (2 . "CLASHING_HATCH")
  35.                         (70 . 0)
  36.                         (62 . 140)
  37.                         (6 . "Continuous")
  38.                        )
  39.             )
  40.           )
  41.           (setvar 'clayer "CLASHING_HATCH")
  42.              (setq e (entsel "\nSelect object to offset: "))
  43. (command "._COPY" e "" "" "")
  44. (setq f (car e))
  45.                  (setq p1 (getpoint "\n Side to offset? "))    
  46.            
  47.              (command "_.offset" "_Layer" "_Current" dist f p1 "")
  48.  
  49.       (setvar "peditaccept" 1)
  50.       (command "pedit" "m" "l" e "" "j" "j" "a" "2" "")
  51.     );; progn
  52.  
  53.  
  54.         )
  55.        
  56.       )
  57.  
  58. ;;;;;;;;;;;;;;;;;;;
  59.  
  60. (setq EL (entlast))
  61. (command "_-boundary" pt "")
  62. (if (/= EL (entlast))
  63. (command "_-hatch" "_S" "_L" "" "_P" "ANSI31" "0.025" "90" "_T" "60" "_DR" "B" "_LA" "HATCH" "")
  64. )
  65.  
  66. (command "erase" EL "")
  67.  
  68. ;;;;;;;;;;;;;;;;;;;
  69.  
  70.  
  71. (setvar 'cmdecho echo)
  72.       (setvar "clayer" cl)
  73.       (princ)
  74.     )
  75.  
  76.  



ronjonp

  • Needs a day job
  • Posts: 7527
Re: offset, join then hatch lisp help please.
« Reply #1 on: March 10, 2017, 06:22:34 PM »
Give this a try:

Code - Auto/Visual Lisp: [Select]
  1. ;; bolted together from various sources.
  2. ;; copy line then offset the line, join ends, hatch and finally delete line.
  3. ;; pb 10/03/17
  4. (defun c:hoff (/ cl dist hi e p1 ss)
  5.   (setq echo (getvar 'cmdecho))
  6.   (setvar 'cmdecho 0)
  7.   (setq cl (getvar "clayer"))
  8.   (if (setq dist (cond ((getdist (strcat "\n Specify offset distance <"
  9.                                          (rtos (if (not hi)
  10.                                                  (setq hi 0.5)
  11.                                                )
  12.                                                2
  13.                                                2
  14.                                          )
  15.                                          ">:"
  16.                                  )
  17.                         )
  18.                        )
  19.                        (t hi)
  20.                  )
  21.       )
  22.     (progn (setq hi dist)
  23.            (if (not (tblsearch "LAYER" "CLASHING_HATCH"))
  24.              (entmakex '((0 . "LAYER")
  25.                          (100 . "AcDbSymbolTableRecord")
  26.                          (100 . "AcDbLayerTableRecord")
  27.                          (2 . "CLASHING_HATCH")
  28.                          (70 . 0)
  29.                          (62 . 140)
  30.                          (6 . "Continuous")
  31.                         )
  32.              )
  33.            )
  34.            (setvar 'clayer "CLASHING_HATCH")
  35.            (setq e (entsel "\nSelect object to offset: "))
  36.            (command "._COPY" e "" "" "")
  37.            (setq f (car e))
  38.            (setq p1 (getpoint "\n Side to offset? "))
  39.            (command "_.offset" "_Layer" "_Current" dist f p1 "")
  40.            (progn (setq b (entlast))
  41.                   (setvar "peditaccept" 1)
  42.                   (command "pedit" "m" "l" e "" "j" "j" "a" "2" "")
  43.            )
  44.            ;; progn
  45.     )
  46.   )
  47. ;;;;;;;;;;;;;;;;;;;
  48.   (setq el (entlast))
  49.   ;; Selection set of objects to hatch
  50.   (setq ss (ssadd))
  51.   (ssadd f ss)
  52.   (ssadd b ss)
  53.   (command "_-boundary" pt "")
  54.   (if (/= el (entlast))
  55.     (command "_-hatch" "_S" ss "" "_P" "ANSI31" "0.025" "90" "_T" "60" "_DR" "B" "_LA" "HATCH" "")
  56.   )
  57.   ;; (command "erase" el "")
  58.   ;; Put offset object on defpoints layer rather than erase
  59.   (entmod (subst '(8 . "defpoints") (assoc 8 (entget el)) (entget el)))
  60. ;;;;;;;;;;;;;;;;;;;
  61.   (setvar 'cmdecho echo)
  62.   (setvar "clayer" cl)
  63.   (princ)
  64. )


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: offset, join then hatch lisp help please.
« Reply #2 on: March 10, 2017, 06:53:56 PM »
After a cursory glance, I don't see that the variable 'pt' is defined.

Pad

  • Bull Frog
  • Posts: 342
Re: offset, join then hatch lisp help please.
« Reply #3 on: March 11, 2017, 04:10:59 AM »
Thanks Ron.  That works really well as it is.

I was thinking after Lee's comments that I should rename 'pt' to 'p1' but it works as is. 

One thing I cant seem to get to the bottom of is:

Command:  HOFF

 Specify offset distance <0.50>:
Select object to offset:
 Side to offset? Unknown command "HOFF".  Press F1 for help.



Unknown command "HOFF". - I expect my parenthesis is all over the place and causing this minor issue.

Thanks for all your help.

P

Pad

  • Bull Frog
  • Posts: 342
Re: offset, join then hatch lisp help please.
« Reply #4 on: March 11, 2017, 04:53:03 AM »
I have had a tinker by trial and error and I think the issues are sorted, except when the polyline is already closed as the lisp creates a copy which isn't required in this case.  I guess I need to check whether the polyline is closed before making the copy.

Also it now pops up a message:
Command:  HOFF

 Specify offset distance <0.50>:
Select object to offset:
 Side to offset?
Valid hatch boundary not found.
Command:

but works fine so happy to ignore the boundary error.

Code - Auto/Visual Lisp: [Select]
  1.     ;;https://www.theswamp.org/index.php?topic=52781.0   thanks Ron
  2.  
  3.     ;; bolted together from various sources.
  4.     ;; copy line then offset the line, join ends, hatch and finally delete line.
  5.     ;; pb 10/03/17
  6.  
  7.     (defun c:hoff (/ cl dist hi e p1 ss pt)
  8.       (setq echo (getvar 'cmdecho))
  9.       (setvar 'cmdecho 0)
  10.       (setq cl (getvar "clayer"))
  11.       (if (setq dist (cond ((getdist (strcat "\n Specify offset distance <"
  12.                                          (rtos (if (not hi)
  13.                                                  (setq hi 0.5)
  14.                                                )
  15.                                                2
  16.                                                2
  17.                                          )
  18.                                          ">:"
  19.                                  )
  20.                         )
  21.                        )
  22.                        (t hi)
  23.                  )
  24.           )
  25.         (progn (setq hi dist)
  26.            (if (not (tblsearch "LAYER" "CLASHING_HATCH"))
  27.              (entmakex '((0 . "LAYER")
  28.                          (100 . "AcDbSymbolTableRecord")
  29.                          (100 . "AcDbLayerTableRecord")
  30.                          (2 . "CLASHING_HATCH")
  31.                          (70 . 0)
  32.                          (62 . 140)
  33.                          (6 . "Continuous")
  34.                         )
  35.              )
  36.            )
  37.            (command "_-layer" "on" "CLASHING_HATCH" "")
  38.            (command "_-layer" "thaw" "CLASHING_HATCH" "")      
  39.            (setvar 'clayer "CLASHING_HATCH")
  40.            (setq e (entsel "\nSelect object to offset: "))
  41.            (command "._COPY" e "" "" "")
  42.            (setq f (car e))
  43.            (setq p1 (getpoint "\n Side to offset? "))
  44.            (command "_.offset" "_Layer" "_Current" dist f p1 "")
  45.            (progn (setq b (entlast))
  46.                   (setvar "peditaccept" 1)
  47.                   (command "pedit" "m" "l" e "" "j" "j" "a" "2" "")
  48.            )
  49.            ;; progn
  50.         )
  51.       )
  52.     ;;;;;;;;;;;;;;;;;;;
  53.       (setq el (entlast))
  54.       ;; Selection set of objects to hatch
  55.       (setq ss (ssadd))
  56.       (ssadd f ss)
  57.       (ssadd b ss)
  58.       (command "_-boundary" p1 "")
  59.       (if (/= el (entlast))
  60.         (command "_-hatch" "_S" ss "" "_P" "ANSI31" "0.025" "90" "_T" "60" "_DR" "B" "_LA" "HATCH" "")
  61.       )
  62.  
  63.       ;; (command "erase" el "")
  64.       ;; Put offset object on defpoints layer rather than erase  ;; pb i'm sticking them on a layer which gets deleted once a drawing if finalised
  65. ;;      (entmod (subst '(8 . "defpoints") (assoc 8 (entget el)) (entget el)))
  66.  
  67.     ;;;;;;;;;;;;;;;;;;;
  68.       (setvar 'cmdecho echo)
  69.       (setvar "clayer" cl)
  70. (command "_-layer" "off" "CLASHING_HATCH" "")
  71.       (princ)
  72.     )

Thanks
P

Pad

  • Bull Frog
  • Posts: 342
Re: offset, join then hatch lisp help please.
« Reply #5 on: March 11, 2017, 05:17:46 AM »
God I'm not so good at this.  I'm trying to make the fuzz factor for the pedit command,  1.1 times the offset (hi), afterwards I want to reset the fuzz factor back to 0.


Code - Auto/Visual Lisp: [Select]
  1. (setq fuzzf (rtos 1.1 2 2))
  2. (setq fuzz (rtos (* fuzzf hi) 2 2))
  3.  
  4.  
  5.                   (command "pedit" "m" "l" e "" "j" "j" "a" fuzz "")

I'm doing something wrong as whatever i try I keep getting 'bad argument type: numberp: "1.10"'

I'm done for today so will try again in a bit.
Cheers

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: offset, join then hatch lisp help please.
« Reply #6 on: March 11, 2017, 06:09:02 AM »
After using rtos, your variable 'fuzzf' holds a string value which cannot be multiplied by your numerical variable 'hi'.

In case this, unless you intend to reference the value elsewhere, the variable 'fuzzf' seems superfluous - I would therefore suggest:
Code - Auto/Visual Lisp: [Select]
  1. (setq fuzz (rtos (* 1.1 hi) 2 2))

Pad

  • Bull Frog
  • Posts: 342
Re: offset, join then hatch lisp help please.
« Reply #7 on: March 11, 2017, 06:18:50 AM »
Thanks Lee.

The only reason I split was to try and do simple steps one at a time.  I'm sure I tried it in a similar way to you're suggestion before splitting it.

Is the pedit fuzz factor held as a variable as I would like to reset it back to 0 afterwards?

Thanks again.
P

martinle

  • Newt
  • Posts: 22
Re: offset, join then hatch lisp help please.
« Reply #8 on: April 26, 2018, 02:34:46 PM »
Hello, I am currently looking for a way to reset command back to 0 after command pedit with fuzzy distance. can someone help me? :reallysad: