Author Topic: Help with double offset and hatch lisp  (Read 1795 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help with double offset and hatch lisp
« on: May 21, 2021, 03:46:01 AM »
Hi . This code begin with an option .Double offset (0.5 -0.5) and  (2.0  -2.0). I try to write it as (a -a) , i dont know if is wrong.

Then i want to select the layer 1 polylines and  add a hatch between of then . The hatch must be in Layer1 with lw 0.05 and type ANSI31 with scale 0.1

The code is

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / a sel int ent )
  2.  (princ "\n")(princ "\n")(princ "\n")
  3.            (initget "1 2")
  4.            (setq
  5.              l
  6.               (cond
  7.                 ((getkword
  8.                    "\n SELECT OFFSET:
  9.                        1. OFFSET 0.5
  10.                        2. OFFSET 2.0
  11.                     "
  12.                  )
  13.                 )
  14.                 ("1")
  15.               )
  16.            )
  17.  
  18. (if (eq l "1")
  19.         (setq a 0.5)
  20.        )
  21. (if (eq l "2")
  22.         (setq a 2.0)
  23.        )
  24. )
  25.         (COMMAND "_layer" "_m" "LAYER1" "_c" "93" "" "_lw" "0.30" "" "")
  26.       (and (or (tblsearch "LAYER" "LAYER2")
  27.              (alert "Layer name < LAYER2 >  was not found in this drawing to continue!")
  28.              )
  29.                 (princ "\nSelect polygon <LAYER2 > to offset on two sides: ")
  30.          (setq int -1 sel (ssget "_X" '((0 . "LINE,*POLYLINE")(8 . "LAYER2"))))
  31.          (while (setq int (1+ int) ent (ssname sel int))
  32.            (foreach off '(a -a)
  33.              (vla-put-layer (car (vlax-invoke (vlax-ename->vla-object ent) 'offset off)) "LAYER1")
  34.              )
  35.            )
  36.     (princ)
  37.     ) (vl-load-com)
  38. )
  39.  

Can any one help ?
Thanks
« Last Edit: May 21, 2021, 10:09:52 AM by PM »

kpblc

  • Bull Frog
  • Posts: 396
Re: Help with double offset and hatch lisp
« Reply #1 on: May 21, 2021, 03:52:40 AM »
Change
Code - Auto/Visual Lisp: [Select]
  1. (foreach off '(a -a)
to
Code - Auto/Visual Lisp: [Select]
  1. (foreach off (list a -a)
Sorry for my English.

PM

  • Guest
Re: Help with double offset and hatch lisp
« Reply #2 on: May 21, 2021, 10:02:37 AM »
Hi kpblc. I did the change  but the code is not working as double offset but only like one side offset. The other problem is how to add hatch inside the double offset.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / a sel int ent )
  2.  (princ "\n")(princ "\n")(princ "\n")
  3.            (initget "1 2")
  4.            (setq
  5.              l
  6.               (cond
  7.                 ((getkword
  8.                    "\n SELECT OFFSET:
  9.                       1. OFFSET 0.5
  10.                       2. OFFSET 2.0
  11.                    "
  12.                  )
  13.                 )
  14.                 ("1")
  15.               )
  16.            )
  17.  
  18. (if (eq l "1")
  19.         (setq a 0.5)
  20.        )
  21. (if (eq l "2")
  22.         (setq a 2.0)
  23.        )
  24. )
  25.         (COMMAND "_layer" "_m" "LAYER1" "_c" "93" "" "_lw" "0.30" "" "")
  26.           (and (or (tblsearch "LAYER" "LAYER2")
  27.              (alert "Layer name < LAYER2 >  was not found in this drawing to continue!")
  28.              )
  29.               (princ "\nSelect polygon < LAYER2 > to offset on two sides: ")
  30.          (setq int -1 sel (ssget "_X" '((0 . "LINE,*POLYLINE")(8 . "LAYER2"))))
  31.          (while (setq int (1+ int) ent (ssname sel int))
  32.                (foreach off (list a -a)
  33.              (vla-put-layer (car (vlax-invoke (vlax-ename->vla-object ent) 'offset off)) "LAYER1")
  34.              )
  35.            )
  36.     (princ)
  37.                
  38.     )
  39.  );end defun
  40.  
  41.  

Any options ?????

Thanks


« Last Edit: May 21, 2021, 10:27:38 AM by PM »

PM

  • Guest
Re: Help with double offset and hatch lisp
« Reply #3 on: May 21, 2021, 11:02:15 AM »
I did a stupid solution but i dont know how to add the hatch

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / a sel int ent )
  2.  (princ "\n")(princ "\n")(princ "\n")
  3.            (initget "1 2")
  4.            (setq
  5.              l
  6.               (cond
  7.                 ((getkword
  8.                    "\n SELECT OFFSET:
  9.                       1. OFFSET 0.5
  10.                       2. OFFSET 2.0
  11.                    "
  12.                  )
  13.                 )
  14.                 ("1")
  15.               )
  16.            )
  17.  
  18. (if (eq l "1")
  19.         (c:test1)
  20.        )
  21. (if (eq l "2")
  22.         (c:test2)
  23.        )
  24.     (princ)
  25.                
  26.     )
  27.  );end defun
  28.  
  29. (defun c:test1 ( / a sel int ent )
  30.         (COMMAND "_layer" "_m" "LAYER1" "_c" "93" "" "_lw" "0.30" "" "")
  31.           (and (or (tblsearch "LAYER" "LAYER2")
  32.              (alert "Layer name < LAYER2 >  was not found in this drawing to continue!")
  33.              )
  34.               (princ "\nSelect polygon < LAYER2 > to offset on two sides: ")
  35.          (setq int -1 sel (ssget "_X" '((0 . "LINE,*POLYLINE")(8 . "LAYER2"))))
  36.          (while (setq int (1+ int) ent (ssname sel int))
  37.                    (foreach off '(0.5 -0.5)
  38.              (vla-put-layer (car (vlax-invoke (vlax-ename->vla-object ent) 'offset off)) "LAYER1")
  39.              )
  40.            )
  41.     (princ)
  42.                
  43.     )
  44.  );end defun
  45.  
  46.  
  47. (defun c:test2 ( / a sel int ent )
  48.         (COMMAND "_layer" "_m" "LAYER1" "_c" "93" "" "_lw" "0.30" "" "")
  49.           (and (or (tblsearch "LAYER" "LAYER2")
  50.              (alert "Layer name < LAYER2 >  was not found in this drawing to continue!")
  51.              )
  52.               (princ "\nSelect polygon < LAYER2 > to offset on two sides: ")
  53.          (setq int -1 sel (ssget "_X" '((0 . "LINE,*POLYLINE")(8 . "LAYER2"))))
  54.          (while (setq int (1+ int) ent (ssname sel int))
  55.                    (foreach off '(2.00 -2.00)
  56.              (vla-put-layer (car (vlax-invoke (vlax-ename->vla-object ent) 'offset off)) "LAYER1")
  57.              )
  58.            )
  59.     (princ)
  60.                
  61.     )
  62.  );end defun
  63.  
  64.  
  65.  

kpblc

  • Bull Frog
  • Posts: 396
Re: Help with double offset and hatch lisp
« Reply #4 on: May 21, 2021, 01:31:54 PM »
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun t1 (/ selset offset_value loops hatch layer)
  3.   (if (and (= (type
  4.                 (setq selset (vl-catch-all-apply
  5.                                (function
  6.                                  (lambda ()
  7.                                    (ssget '((0 . "*POLYLINE") (8 . "layer2") (-4 . "<OR") (70 . 1) (70 . 129) (-4 . "OR>")))
  8.                                  ) ;_ end of lambda
  9.                                ) ;_ end of function
  10.                              ) ;_ end of vl-catch-all-apply
  11.                 ) ;_ end of setq
  12.               ) ;_ end of type
  13.               'pickset
  14.            ) ;_ end of =
  15.            (= (type (setq offset_value
  16.                            (vl-catch-all-apply
  17.                              (function (lambda ()
  18.                                          (initget "1 2")
  19.                                          (cond ((getkword "\nSelect offset value [1 - offset 0.5/2 - ossfet 2.0] <1> : "))
  20.                                                (t "1")
  21.                                          ) ;_ end of cond
  22.                                        ) ;_ end of lambda
  23.                              ) ;_ end of function
  24.                            ) ;_ end of vl-catch-all-apply
  25.                     ) ;_ end of setq
  26.               ) ;_ end of type
  27.               'str
  28.            ) ;_ end of =
  29.       ) ;_ end of and
  30.            (setq layer (vla-add (vla-get-layers adoc) "Layer1"))
  31.            (vla-put-color layer 93)
  32.            (vla-put-lineweight layer aclnwt030)
  33.            (setq offset_value (cond ((= (atoi offset_value) 1) 0.5)
  34.                                     ((= (atoi offset_value) 2) 2.0)
  35.                               ) ;_ end of cond
  36.                  loops        (mapcar (function
  37.                                         (lambda (ent)
  38.                                           (vl-sort (mapcar (function (lambda (x)
  39.                                                                        (setq x (car (vlax-safearray->list (vlax-variant-value x))))
  40.                                                                        (vla-put-layer x (vla-get-name layer))
  41.                                                                        x
  42.                                                                      ) ;_ end of lambda
  43.                                                            ) ;_ end of function
  44.                                                            (list (vla-offset (vlax-ename->vla-object ent) offset_value)
  45.                                                                  (vla-offset (vlax-ename->vla-object ent) (- offset_value))
  46.                                                            ) ;_ end of list
  47.                                                    ) ;_ end of mapcar
  48.                                                    (function (lambda (a b) (> (vla-get-area a) (vla-get-area b))))
  49.                                           ) ;_ end of vl-sort
  50.                                         ) ;_ end of lambda
  51.                                       ) ;_ end of function
  52.                                       ((lambda (/ tab item)
  53.                                          (repeat (setq tab  nil
  54.                                                        item (sslength selset)
  55.                                                  ) ;_ end setq
  56.                                            (setq tab (cons (ssname selset (setq item (1- item))) tab))
  57.                                          ) ;_ end of repeat
  58.                                        ) ;_ end of lambda
  59.                                       )
  60.                               ) ;_ end of mapcar
  61.            ) ;_ end of setq
  62.            (foreach item loops
  63.              (setq hatch (vla-addhatch
  64.                            (vla-get-modelspace adoc)
  65.                            achatchpatterntypepredefined
  66.                            "ANSI31"
  67.                            :vlax-false
  68.                            achatchobject
  69.                          ) ;_ end of vla-AddHatch
  70.              ) ;_ end of setq
  71.              (vla-appendouterloop
  72.                hatch
  73.                (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (car item)))
  74.              ) ;_ end of vla-appendouterloop
  75.              (vla-appendinnerloop
  76.                hatch
  77.                (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (cadr item)))
  78.              ) ;_ end of vla-appendinnerloop
  79.              (vla-evaluate hatch)
  80.              (vla-update hatch)
  81.              (vla-put-layer hatch (vla-get-name layer))
  82.            ) ;_ end of foreach
  83.            (vla-endundomark adoc)
  84.     ) ;_ end of progn
  85.   ) ;_ end of if
  86.   (princ)
  87. ) ;_ end of defun
  88.  
Sorry for my English.

PM

  • Guest
Re: Help with double offset and hatch lisp
« Reply #5 on: May 21, 2021, 03:26:42 PM »
Thank you  kpblc

PM

  • Guest
Re: Help with double offset and hatch lisp
« Reply #6 on: May 21, 2021, 03:54:49 PM »
Hi  kpblc a last question. How to change pattetn scale to 0.1 and hatch linetype bylayer ?

Thanks
« Last Edit: May 21, 2021, 03:58:07 PM by PM »

PM

  • Guest
Re: Help with double offset and hatch lisp
« Reply #7 on: May 22, 2021, 02:37:23 AM »
Thans  kpblc i  fix it  :smitten: :smitten: :smitten:


ScottMC

  • Newt
  • Posts: 191
Re: Help with double offset and hatch lisp
« Reply #9 on: May 23, 2021, 06:33:03 PM »
Just tried it and VLIDE'd to understand the oops.. NOT yet

Corrected by removing: 103, 106, 132,133,134 and adding
 
(command "-bhatch" "S" "L" "" "") at the end. oldies still work!

   Thanks Much Lee - you keep me thinkin
« Last Edit: May 23, 2021, 11:05:46 PM by ScottMC »