Simple hatch on previously drawn object

Simple hatch on previously drawn object

murmanator
Advocate Advocate
1,286 Views
7 Replies
Message 1 of 8

Simple hatch on previously drawn object

murmanator
Advocate
Advocate

I want to do something seemingly simple but my lack of programming chops is not allowing me to get it. I need to draw a multiline with closed ends, then add a hatch to that. It works to add the hatch to the object manually after I draw it, is it possible to do this with LISP? I have tried a few different approaches none of which work. Here are some of my attempts:

 

(defun C:GUTTER ( )

(command "_-layer" "s" "PLUMBING" "") ;; CHANGE LAYER TO "PLUMBING"
(vl-cmdf "MLINE" "J" "Z" "S" "1" "ST" "GUTTER") ;; DRAW MULTILINE

(command "_-HATCH" ".PREVIOUS" "SOLID" "") ;; HATCH W/ SOLID
(princ)
)

 

(defun C:GUTTER ( / EL )

(command "_-layer" "s" "PLUMBING" "") ;; CHANGE LAYER TO "PLUMBING"
(vl-cmdf "MLINE" "J" "Z" "S" "1" "ST" "GUTTER") ;; DRAW MULTILINE

(setq EL (entlast))
(if (/= EL (entlast))
(command "_-hatch" "_S" "_L" "" "_P" "SOLID" "" "" "")
); end if
(princ)
)

 

(defun C:GUTTER ( )

(command "_-layer" "s" "PLUMBING" "") ;; CHANGE LAYER TO "PLUMBING"

(command

"_.MLINE" "J" "Z" "S" "1" "ST" "GUTTER"

"_.bhatch" "_advanced" "_associativity" "_yes" "" "_select" "_last" "" ""
)

(princ)
)

 

Thank you for reading.

Accepted solutions (2)
1,287 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Fixed the first one.

 

(defun c:gutter ()
  
  (command "_-layer" "m" "plumbing" "") ;; change layer to "plumbing"
  (command "mline" "j" "z" "s" "1" "st" "gutter") ;; draw multiline
  (while (> (getvar 'cmdactive) 0) (command pause))
  (command "_-hatch" "_select" "_last" "" "properties" "solid" "") ;; hatch w/ solid
  (princ)
  )
Message 3 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

Or, with Acad 2015 [I think] or newer:

 

(defun C:GUTTER ()

  (command "_-layer" "s" "PLUMBING" "") ;; CHANGE LAYER TO "PLUMBING"

  (command-s "_.MLINE" "J" "Z" "S" "1" "ST" "GUTTER"); will let you finish it before:

  (command "_.bhatch" "_advanced" "_associativity" "_yes" "" "_select" "_last" "" "")

  (princ)
)

Kent Cooper, AIA
Message 4 of 8

murmanator
Advocate
Advocate

Thanks guys, both of those look like they want to work but I keep getting "Unable to fill the boundary with solid." in the command line at the end. I swear I was able to manually hatch a multiline by selecting the object before but now its not working, either manually or via the lisp. Sorry I know this is not a lisp question but do you know if hatching a multiline is possible? It has the start and end lines so it looks like a closed object. Does the MLSTYLE settings have anything to do with it? Because Ive been tinkering with those since I started all this.

Message 5 of 8

murmanator
Advocate
Advocate

Well I must have done something goofy to the file I was working in to the multiline styles. I went into a new drawing and it seems to work now. Thanks guys always appreciate the help on here.

Message 6 of 8

Kent1Cooper
Consultant
Consultant

@murmanator wrote:

... do you know if hatching a multiline is possible? It has the start and end lines so it looks like a closed object. Does the MLSTYLE settings have anything to do with it? ....


Does your "GUTTER" MultiLine Style include the closed ends in its definition?

Kent1Cooper_0-1646081962406.png

When I use this Test Style with closed ends incorporated in it, I can Hatch the resulting MLine by object selection.  I can't if I use a Style without the end caps.  If I draw Lines across the ends, I can then Hatch by picking an internal point, but not by object selection of the Mline.

 

Kent Cooper, AIA
Message 7 of 8

murmanator
Advocate
Advocate

Thanks Kent. Yeah I do have the ends included. I must have inadvertently done something to either my mlstyles or hatch settings in my test file because it was not allowing me to hatch by selection ANY mlines. When I went to a new drawing it all worked fine.

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

You can make line styles on the fly so your gutter could be different widths, as well as linetype and colours.

 

; make mline 
; By alan H oct 2020
; Set to bylayer at moment
; Thanks to FIXO for original code

(defun c:makml ( / lst1 lst2 lst desc MLINE_STYLE_NAME )
(setq 	MLINE_STYLE_NAME (getstring "\nEnter mline name ")
		desc (getstring "\nEnter description ")
)
(while (setq off (getreal "\Enter offset Enter to finish " ))
	(setq lst (cons off lst))
)
(if (= desc nil)(setq desc MLINE_STYLE_NAME))
(setq lst1
	(list '(0 . "MLINESTYLE")
		'(100 . "AcDbMlineStyle")
		(cons 2 MLINE_STYLE_NAME)
		(cons 70 (+ 272))
		(cons 3 desc)
		'(62 . 256)
		'(51 . 1.5708)
		'(52 . 1.5708)
		'(71 . 4)
    '(72 . 4)
   	)
)
(setq x (length lst))
(repeat x
	(setq lst2 (list 
		(cons 49 (nth (setq x (- x 1)) lst))
		(cons 62 256)
		(cons 6 "BYLAYER")
		)
	)
	(setq lst1 (append lst1 lst2))
)
(if
	(not (dictadd
		(cdar (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
		MLINE_STYLE_NAME
		(entmakex lst1)
		)
	)
	(Alert "Impossible to create mline style\n perhaps this was exist earlier")
)
(setvar 'cmlstyle MLINE_STYLE_NAME)
(princ)
)
(c:makml)

 

0 Likes