Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: A question about controlling Hatch Separation at Creation from within a LISP

  1. #1
    100 Club
    Join Date
    2006-12
    Posts
    106
    Login to Give a bone
    0

    Default A question about controlling Hatch Separation at Creation from within a LISP

    Hello,

    I routinely use a LSP to create hatches within multiple polylines, but I want the hatches to be separate entities from each other, so I either have to go into the Hatch command to create a dummy hatch with that option first, or I have to use the Hatchedit command to separate them afterwards. Is there a system variable that could be set from within the LSP that would automate the process?

    Thanks!

    EDIT: I've discovered an interesting twist: I found the system variable HPSEPARATE, and have added code to set it to "1" (draws separate hatches) within the LSP routine, but (setvar "hpseparate" "1") returns a load failure error. Additionally, even if I manually change hpseparate=1 before running the routine , (and confirming same), any hatch creation from the regular HATCH ribbon panel creates separate hatch objects, but running the command (if (= hy "Y") (command "HATCH" "WAVY2" ".2" "0" "p" "")) within the LSP still creates conjoined hatch objects, while the HPSEPARATE variable remains set to "1" after the routine exits...

    This one is turning my brain into gravy... Anybody have any ideas?
    Last edited by crbateman; 2019-03-16 at 03:36 PM.

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Hi,
    The value for the system variable HPSEPARATE must be an integer.

  3. #3
    100 Club
    Join Date
    2006-12
    Posts
    106
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Quote Originally Posted by Tharwat View Post
    Hi,
    The value for the system variable HPSEPARATE must be an integer.
    Isn't "1" an integer? I try to set it even before I execute the indicated HATCH command string. Tests before and after confirm that HPSEPARATE is indeed set to "1", but the hatches still end up conjoined... The fractional decimals within the HATCH command are for scale and rotation. They work fine. It's the creation of a single massive conjoined hatch that I'm trying to overcome.

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Quote Originally Posted by crbateman View Post
    Isn't "1" an integer?
    No it is not, as long as it is wrapped with double quotes then it becomes / called a string type.

  5. #5
    100 Club
    Join Date
    2006-12
    Posts
    106
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Quote Originally Posted by Tharwat View Post
    No it is not, as long as it is wrapped with double quotes then it becomes / called a string type.
    OK, I see what you mean... I removed the quotes, and that takes care of the load error, but the odd behavior remains... In a drawing session, with HPSEPARATE set (and confirmed) to 1, the generic ribbon HATCH command creates separate hatch objects, as it should, but when I run my LSP routine, the resulting hatch objects are contiguous, despite another (getvar "HPSEPARATE") returning 1, indicating that the variable remains set to provide separate hatches...

    This is not a deal-breaker, as I can always just run a HATCHEDIT to break them into separates, but I am kinda curious why I have to go to the trouble to do that...

    Thanks for your continuing help!

  6. #6
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP


  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Can you upload a sample drawing a long with your codes to allow me to take a close look ?

  8. #8
    100 Club
    Join Date
    2006-12
    Posts
    106
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Quote Originally Posted by Tharwat View Post
    Can you upload a sample drawing a long with your codes to allow me to take a close look ?
    Yes... Here it is. In the sample drawing, the top row of plines is unprocessed, the second row is hatched using the ribbon HATCH command (resulting in separate hatch objects), and the third row is processed using the POLY_AREA command from the attached LSP routine (resulting in the single hatch object). Tests for HPSEPARATE both before and after the routine runs return a value of 1.

    I think you may have to substitute a stock hatch pattern for WAVY2 in my HATCH command call...

    Enjoy!

    simplesample1.dwg
    POLY_AREA.LSP
    Last edited by crbateman; 2019-03-17 at 04:10 PM.

  9. #9
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    You did not iterate through each polyline to have them hatched separately so I did modify the codes a bit and added a few as well but you need to change the hatch pattern that suits your needs and I went with the pattern with ANSI31 in shown in the codes below:

    Code:
    (vl-load-com)
    (defun c:test (/ js nb ent dxf_ent ptlst hy n pt_ins val_txt lst)
      (setvar "clayer" "irr-drip-text")
      (setvar "hplayer" "irr-drip-hatch")
      (princ "\nSelect closed polylines")
      (setq js (ssget (list '(0 . "*POLYLINE")
                            '(-4 . "<AND")
                            '(-4 . "<NOT")
                            '(-4 . "&")
                            '(70 . 120)
                            '(-4 . "NOT>")
                            '(-4 . "&")
                            '(70 . 1)
                            '(-4 . "AND>")
                            (cons 67
                                  (if (eq (getvar "CVPORT") 1)
                                    1
                                    0
                                  )
                            )
                            (cons 410
                                  (if (eq (getvar "CVPORT") 1)
                                    (getvar "CTAB")
                                    "Model"
                                  )
                            )
                      )
               )
      )
      (cond (js
             (repeat (setq nb (sslength js))
               (setq ent     (ssname js (setq nb (1- nb)))
                     dxf_ent (entget ent)
                     ptlst   (mapcar
                               'cdr
                               (vl-remove-if-not '(lambda (x) (= (car x) 10)) dxf_ent)
                             )
                     n       (float (length ptlst))
                     pt_ins  (list (/ (apply '+ (mapcar 'car ptlst)) n)
                                   (/ (apply '+ (mapcar 'cadr ptlst)) n)
                             )
                     val_txt (rtos (vlax-get-property
                                     (vlax-ename->vla-object ent)
                                     "Area"
                                   )
                                   2
                                   0
                             )
                     lst     (cons ent lst)
               )
               (entmake
                 (list '(0 . "TEXT")
                       '(100 . "AcDbEntity")
                       (cons 67
                             (if (eq (getvar "CVPORT") 1)
                               1
                               0
                             )
                       )
                       (cons 410
                             (if (eq (getvar "CVPORT") 1)
                               (getvar "CTAB")
                               "Model"
                             )
                       )
                       (cons 8 (getvar "CLAYER"))
                       '(100 . "AcDbText")
                       (cons 10 pt_ins)
                       (cons 40 (getvar "TEXTSIZE"))
                       (cons 1 val_txt)
                       (cons 50 (+ pi (angle '(0 0 0) (getvar "UCSYDIR"))))
                       '(41 . 1.0)
                       '(51 . 0.0)
                       (cons 7 (getvar "TEXTSTYLE"))
                       '(71 . 0)
                       '(72 . 1)
                       (cons 11 pt_ins)
                       (cons 210 (trans '(0 0 1) 1 0 T))
                       '(100 . "AcDbText")
                       '(73 . 2)
                 )
               )
             )
            )
      )
      (prin1)
      (if (and lst
               (progn (initget "Yes No")
                      (setq hy (cond ((getkword "\nHatch? Y/N < Yes >: "))
                                     ("Yes")
                               )
                      )
               )
               (= hy "Yes")
          )
        (foreach obj lst
          (command "_.-hatch" "S" obj "" "P" "ANSI31" 0.2 0.0 "")
        )
      )
      (princ)
    )

  10. #10
    100 Club
    Join Date
    2006-12
    Posts
    106
    Login to Give a bone
    0

    Default Re: A question about controlling Hatch Separation at Creation from within a LISP

    Quote Originally Posted by Tharwat View Post
    You did not iterate through each polyline to have them hatched separately so I did modify the codes a bit and added a few as well but you need to change the hatch pattern that suits your needs and I went with the pattern with ANSI31 in shown in the codes below:

    Code:
    (vl-load-com)
    (defun c:test (/ js nb ent dxf_ent ptlst hy n pt_ins val_txt lst)
      (setvar "clayer" "irr-drip-text")
      (setvar "hplayer" "irr-drip-hatch")
      (princ "\nSelect closed polylines")
      (setq js (ssget (list '(0 . "*POLYLINE")
                            '(-4 . "<AND")
                            '(-4 . "<NOT")
                            '(-4 . "&")
                            '(70 . 120)
                            '(-4 . "NOT>")
                            '(-4 . "&")
                            '(70 . 1)
                            '(-4 . "AND>")
                            (cons 67
                                  (if (eq (getvar "CVPORT") 1)
                                    1
                                    0
                                  )
                            )
                            (cons 410
                                  (if (eq (getvar "CVPORT") 1)
                                    (getvar "CTAB")
                                    "Model"
                                  )
                            )
                      )
               )
      )
      (cond (js
             (repeat (setq nb (sslength js))
               (setq ent     (ssname js (setq nb (1- nb)))
                     dxf_ent (entget ent)
                     ptlst   (mapcar
                               'cdr
                               (vl-remove-if-not '(lambda (x) (= (car x) 10)) dxf_ent)
                             )
                     n       (float (length ptlst))
                     pt_ins  (list (/ (apply '+ (mapcar 'car ptlst)) n)
                                   (/ (apply '+ (mapcar 'cadr ptlst)) n)
                             )
                     val_txt (rtos (vlax-get-property
                                     (vlax-ename->vla-object ent)
                                     "Area"
                                   )
                                   2
                                   0
                             )
                     lst     (cons ent lst)
               )
               (entmake
                 (list '(0 . "TEXT")
                       '(100 . "AcDbEntity")
                       (cons 67
                             (if (eq (getvar "CVPORT") 1)
                               1
                               0
                             )
                       )
                       (cons 410
                             (if (eq (getvar "CVPORT") 1)
                               (getvar "CTAB")
                               "Model"
                             )
                       )
                       (cons 8 (getvar "CLAYER"))
                       '(100 . "AcDbText")
                       (cons 10 pt_ins)
                       (cons 40 (getvar "TEXTSIZE"))
                       (cons 1 val_txt)
                       (cons 50 (+ pi (angle '(0 0 0) (getvar "UCSYDIR"))))
                       '(41 . 1.0)
                       '(51 . 0.0)
                       (cons 7 (getvar "TEXTSTYLE"))
                       '(71 . 0)
                       '(72 . 1)
                       (cons 11 pt_ins)
                       (cons 210 (trans '(0 0 1) 1 0 T))
                       '(100 . "AcDbText")
                       '(73 . 2)
                 )
               )
             )
            )
      )
      (prin1)
      (if (and lst
               (progn (initget "Yes No")
                      (setq hy (cond ((getkword "\nHatch? Y/N < Yes >: "))
                                     ("Yes")
                               )
                      )
               )
               (= hy "Yes")
          )
        (foreach obj lst
          (command "_.-hatch" "S" obj "" "P" "ANSI31" 0.2 0.0 "")
        )
      )
      (princ)
    )
    That does the trick! It had not occurred to me to process each polyline individually, as I already had a selection set with all of them (produced by using the P (Previous) option in the HATCH command), but I have tested yours on a drawing with literally hundreds of them, and it only adds a brief few seconds of application time...

    Thanks for the help! You guys that think in terms of code always leave me SMH...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 2016-04-13, 06:09 PM
  2. Controlling Visibilty States With Lisp
    By sovby254640 in forum AutoLISP
    Replies: 6
    Last Post: 2013-08-06, 12:16 PM
  3. Walls created over Room Separation Lines join, or option to delete the Separation Line.
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2011-11-18, 01:52 PM
  4. Controlling Drawing Order associated with Hatch
    By Matt Mercer in forum AutoCAD General
    Replies: 8
    Last Post: 2007-02-27, 10:40 AM
  5. Room Separation Question
    By dgreen.49364 in forum Revit Architecture - General
    Replies: 6
    Last Post: 2006-03-25, 01:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •