+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default HELP: Lisp to hatch multiple closed polylines but result in individual hatch objects

    Registered forum members do not see this ad.

    Looking for a hatch lisp to window select multiple closed polylines & hatch them at once but result in individual hatch objects, base on current hatch settingd.

    Came across this code but was it unable to base on current hatch settings

    Code:
    (defun c:mhatch (/ ang do-it doc hatch oname pname scl space ss)
    (if (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
    (progn
    (setq scl (getvar "hpscale")
    ang (getvar "hpang")
    pname (getvar "hpname")
    hpassoc (if (= (getvar "hpassoc") 1)
    :vlax-true
    :vlax-false)
    doc (vla-get-activedocument
    (vlax-get-acad-object))
    space (if (= (getvar "cvport") 1)
    (vla-get-paperspace doc)
    (vla-get-modelspace doc)
    )
    )
    (vlax-for ent (vla-get-activeselectionset doc)
    (setq do-it nil
    oname (strcase (vla-get-objectname ent)))
    (cond ((vl-string-search "CIRCLE" oname)
    (setq do-it t)
    )
    ((and (vl-string-search "LINE" oname)
    (eq (vla-get-closed ent) :vlax-true)
    )
    (setq do-it t)
    )
    ((equal (vlax-curve-getstartpoint ent)
    (vlax-curve-getendpoint ent)
    1e-6)
    (setq do-it t)
    )
    )
    (if do-it
    (progn
    (setq hatch (vlax-invoke space 'addhatch acHatchObject pname hpassoc))
    (vlax-invoke hatch 'appendouterloop (list ent))
    (vlax-put hatch 'patternangle ang)
    (vlax-put hatch 'patternscale scl)
    (vla-evaluate hatch)
    )
    )
    )
    )
    )
    (princ)
    )
    Thanks

  2. #2
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,227

    Default

    Hi,

    I have just wrote this program and added to my Lisp-box

    Code:
    (defun c:Test  (/ h _doc ss)
    ;;;	Tharwat 20.01.2014	;;
      (princ "\n Select closed objects to hatch as per current hatch settings ")
      (if (setq _doc (vla-get-activedocument (vlax-get-acad-object))
                ss   (ssget '((-4 . "<OR")
                              (0 . "CIRCLE,ELLIPSE")
                              (-4 . "<AND")
                              (0 . "LWPOLYLINE")
                              (-4 . "&=")
                              (70 . 1)
                              (-4 . "AND>")
                              (-4 . "OR>"))))
    
        (vlax-for o  (vla-get-activeselectionset _doc)
          (setq h (vlax-invoke
                    (vla-get-block (vla-get-activelayout _doc))
                    'addhatch
                    acHatchObject
                    (getvar "hpname")
                    (if (= (getvar "hpassoc") 1)
                      :vlax-true
                      :vlax-false)))
          (vlax-invoke h 'appendouterloop (list o))
          (vlax-put h 'patternangle (getvar "hpang"))
          (vlax-put h 'patternscale (getvar "hpscale"))
          (vla-evaluate h)
          )
        )
      (princ)
      )(vl-load-com)

  3. #3
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default

    Hi Tharwat.

    Tested it & somehow it will not follow current setting which is non associative.

    When using the LISP to hatch, it still hatch as associative.

    Any advise on this?

    Thanks
    Last edited by vernonlee; 20th Jan 2015 at 01:17 pm.

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,227

    Default

    It seems that the parameter for the association is not making any sense with the use of the vlax-invoke function

    Try this instead and let me know

    Code:
    (defun c:Test  (/ soc h _doc ss)
    ;;;	Tharwat 20.01.2014	;;
      (princ
        "\n Select closed objects to hatch as per current hatch settings ")
      (if (setq _doc (vla-get-activedocument (vlax-get-acad-object))
                soc (if (= (getvar "hpassoc") 1)
                      :vlax-true
                      :vlax-false)
                ss   (ssget '((-4 . "<OR")
                              (0 . "CIRCLE,ELLIPSE")
                              (-4 . "<AND")
                              (0 . "LWPOLYLINE")
                              (-4 . "&=")
                              (70 . 1)
                              (-4 . "AND>")
                              (-4 . "OR>"))))
        (vlax-for o  (vla-get-activeselectionset _doc)
          (setq h (vlax-invoke
                    (vla-get-block (vla-get-activelayout _doc))
                    'addhatch
                    acHatchObject
                    (getvar "hpname")
                    soc))
          (vlax-invoke h 'appendouterloop (list o))
          (vla-put-AssociativeHatch h soc)
          (vlax-put h 'patternangle (getvar 'hpang))
          (vlax-put h 'patternscale (getvar 'hpscale))
          (vla-evaluate h)
          )
        )
      (princ)
      ) (vl-load-com)

  5. #5
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default

    Hi Tharwat.

    I now works.

    But i realised some of the polylines are not closed but look close (did not know there was such a thing), which the normal hatch command can select.

    Could you include those that can be selected by normal hatch command?

    Thanks
    Last edited by vernonlee; 20th Jan 2015 at 01:16 pm.

  6. #6
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,227

    Default

    Why you are quoting every reply ? just a simple reply is more than enough if you don't reply to a specific point , remove the two programs from your replies please to keep the thread 's representation looking good at least .

    Quote Originally Posted by vernonlee View Post
    Could you include those that can be selected by normal hatch command?
    Replace my selection set function with yours .

    eg.

    Code:
    (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
    with the highlighted codes ONLY .

    Code:
     (setq _doc (vla-get-activedocument (vlax-get-acad-object))
                soc (if (= (getvar "hpassoc") 1)
                      :vlax-true
                      :vlax-false)
                ss   (ssget '((-4 . "<OR")
                              (0 . "CIRCLE,ELLIPSE")
                              (-4 . "<AND")
                              (0 . "LWPOLYLINE")
                              (-4 . "&=")
                              (70 . 1)
                              (-4 . "AND>")
                              (-4 . "OR>")))
    )

  7. #7
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default

    Roger. Will clean up my previous post.

    Did the code replacement & i got this error when i load the lisp

    Code:
    ; error: malformed list on input
    my code after replacement is this


    Code:
    (defun c:Test  (/ soc h _doc ss)
    ;;;    Tharwat 20.01.2014    ;;
      (princ
        "\n Select closed objects to hatch as per current hatch settings ")
      (if (setq _doc (vla-get-activedocument (vlax-get-acad-object))
                soc (if (= (getvar "hpassoc") 1)
                      :vlax-true
                      :vlax-false)
                (setq ss (ssget '((0 . "LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
    )
        (vlax-for o  (vla-get-activeselectionset _doc)
          (setq h (vlax-invoke
                    (vla-get-block (vla-get-activelayout _doc))
                    'addhatch
                    acHatchObject
                    (getvar "hpname")
                    soc))
          (vlax-invoke h 'appendouterloop (list o))
          (vla-put-AssociativeHatch h soc)
          (vlax-put h 'patternangle (getvar 'hpang))
          (vlax-put h 'patternscale (getvar 'hpscale))
          (vla-evaluate h)
          )
        )
      (princ)
      ) (vl-load-com)

  8. #8
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,227

    Default

    No , Read this modification and compare it with your last reply .

    Code:
    (defun c:Test  (/ soc h _doc ss)
    ;;;    Tharwat 20.01.2014    ;;
      (princ
        "\n Select closed objects to hatch as per current hatch settings ")
      (if (setq _doc (vla-get-activedocument (vlax-get-acad-object))
                soc  (if (= (getvar "hpassoc") 1)
                       :vlax-true
                       :vlax-false)
                ss   (ssget '((0 . "LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")))
                )
        (vlax-for o  (vla-get-activeselectionset _doc)
          (setq h (vlax-invoke
                    (vla-get-block (vla-get-activelayout _doc))
                    'addhatch
                    acHatchObject
                    (getvar "hpname")
                    soc))
          (vlax-invoke h 'appendouterloop (list o))
          (vla-put-AssociativeHatch h soc)
          (vlax-put h 'patternangle (getvar 'hpang))
          (vlax-put h 'patternscale (getvar 'hpscale))
          (vla-evaluate h)
          )
        )
      (princ)
      )(vl-load-com)

  9. #9
    Super Member
    Using
    AutoCAD 2015
    Join Date
    Jul 2014
    Posts
    503

    Default

    Ok. I guess as much I did something wrong. Will compare them to see where I went wrong when I am back in office tomorrow & test the code as well. Will feedback then.


    Thanks again bro.

  10. #10
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,227

    Default

    Registered forum members do not see this ad.

    Good luck

Similar Threads

  1. Selecting objects within multiple selected closed polylines
    By Johnnytarno in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 25th Jan 2015, 01:00 pm
  2. Hatch multiple closed polylines in the same layer
    By gosma in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 14th Apr 2013, 09:55 pm
  3. Creating hatch boundries on multiple objects and individual lines.
    By Jonathan1321 in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 12th Feb 2013, 01:00 pm
  4. Hatch of Closed Polylines Offset From User Designated Points
    By doerner in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 16th Dec 2012, 07:15 am
  5. Hatch fill multiple closed polylines
    By Rambo, John J in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 5
    Last Post: 28th Oct 2008, 12:10 pm

Bookmarks

Posting Permissions

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