Jump to content

Recommended Posts

Posted (edited)

Is it possible to use lisp to shade selected outlines (several at once) with separates hatchings Solid?
There are many polylines (rectangles) that need to be filled with separates hatchings...

How can this be applied to multiple outlines:
(vl-cmdf "_.-hatch" "_s" r "" "_p" "SOLID" "" "" "") 

separates HATCH Solid.png

Edited by Nikon
  • Nikon changed the title to Fill in several outlines with separates hatchings
Posted

 

 

image.png.c295b9e8a4cd1418c946db41cb00257f.png

 

 

just use toggle 'Create separate hatches'

 

 

  • Thanks 1
Posted
1 minute ago, rlx said:

just use toggle 'Create separate hatches'

I know this, but I have a lot of outlines in my drawing, and it takes a very long time to highlight each of them...

Posted
(defun c:t1 ( / al ss )
  (setq al (vla-get-activelayout (vla-get-ActiveDocument (vlax-get-acad-object))))
  (if (setq ss (ssget "_X" (list '(0 . "LWPOLYLINE"))))
    (vlax-for o (setq s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
      (setq h (vla-addhatch (vlax-get al 'block) acHatchPatternTypePredefined "SOLID" :vlax-true))
      (vlax-invoke h 'AppendOuterLoop (list o))(vlax-invoke h 'Evaluate)
    )
  )
  (princ)
)

(defun c:t2 ( / al ss)
  (setq al (vla-get-activelayout (vla-get-ActiveDocument (vlax-get-acad-object))))
  (princ "\nSelect objects to apply solid hatch to : ")
  (if (setq ss (ssget (list '(0 . "LWPOLYLINE"))))    
    (vlax-for o (setq s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
      (setq h (vla-addhatch (vlax-get al 'block) acHatchPatternTypePredefined "SOLID" :vlax-true))
      (vlax-invoke h 'AppendOuterLoop (list o))(vlax-invoke h 'Evaluate)
    )
  )
  (princ)
)

 

  • Like 3
Posted (edited)
17 hours ago, rlx said:
(defun c:t2 ( / al ss)
  (setq al (vla-get-activelayout (vla-get-ActiveDocument (vlax-get-acad-object))))
  (princ "\nSelect objects to apply solid hatch to : ")
  (if (setq ss (ssget (list '(0 . "LWPOLYLINE"))))    
    (vlax-for o (setq s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
      (setq h (vla-addhatch (vlax-get al 'block) acHatchPatternTypePredefined "SOLID" :vlax-true))
      (vlax-invoke h 'AppendOuterLoop (list o))(vlax-invoke h 'Evaluate)
    )
  )
  (princ)
)

@rlx thank you very much!!! It will help me a lot.

Edited by Nikon
Posted

Post a dwg. Should be able to use Hatchb.lsp to make a boundary and get the points of the boundary, if its more than 4 vertices or small sides are different lengths then it's not really a pline shape.

  • Thanks 1
Posted (edited)
12 hours ago, BIGAL said:

Post a dwg. Should be able to use Hatchb.lsp to make a boundary and get the points of the boundary, if its more than 4 vertices or small sides are different lengths then it's not really a pline shape.

I am trying to convert (using the program SOLID_PLINE_HATCH_TO_PLINE) the created hatches into a polyline with global width=hatching width, but an entry is displayed on the command string:
"The outline of the hatching is formed not only by a polyline".

If the hatching is created by the autocad command, then the SOLID_PLINE_HATCH_TO_PLINE program works...

PL_HATCH.dwg Solid_pline_hatch_to_pline.fas.rar

Edited by Nikon
Posted (edited)

Sorry no help to existing code  if your using a FAS file. I use Bricscad mostly now and fas is not supported.

 

This is close to what you want, I have not looked at color of hatch but that could be added. Change layer name, the rectang around the hatch is erased, the hatch is still there on Hatch layer, again could be erased.

 

You were lucky did the d1 d2 bit yesterday for another post.

 

; https://www.cadtutor.net/forum/topic/90914-fill-in-several-outlines-with-separates-hatchings/
; Convert a rectang to a pline with width.
: By Alan H Sep 2024

(defun C:Rect2pl  ( / sspl co-ord x mp1 mp2 d1 d2)

(command "-layer" "M" "HATCH2" "")

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(setq sspl (ssget (list (cons 0 "LWPOLYLINE")(cons 410 (getvar 'ctab)))))
(setvar 'clayer "HATCH2")
(repeat (setq x (sslength sspl))
 (setq plent (ssname sspl (setq x (1- x))))
 (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
 (setq d1 (distance (car co-ord)(cadr co-ord)))
 (setq d2 (distance (cadr co-ord)(caddr co-ord)))
 (if (< d1 d2)
 (progn
  (setq mp1 (mapcar '* (mapcar '+ (nth 0 co-ord) (nth 1 co-ord)) '(0.5 0.5)))
  (setq mp2 (mapcar '* (mapcar '+ (nth 2 co-ord) (nth 3 co-ord)) '(0.5 0.5)))
  (command "pline" mp1 "W" d1 d1 mp2 "")
 )
 (progn
  (setq mp1 (mapcar '* (mapcar '+ (nth 1 co-ord) (nth 2 co-ord)) '(0.5 0.5)))
  (setq mp2 (mapcar '* (mapcar '+ (nth 3 co-ord) (nth 0 co-ord)) '(0.5 0.5)))
  (command "pline" mp1 "W" d2 d2 mp2 "")
 )
 )
 (command "erase" plent "")
)

(princ)
)

 

Edited by BIGAL
  • Like 1
Posted (edited)

Mr. @BIGAL This is an amazing program!!!  I couldn't find this solution for a long time... Thanks a lot! 

A very good start to the day! Thanks for Rect2pl.

Edited by Nikon
Posted

No worries as I had solved already the shortest side it was easy to do. :beer:

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...