Jump to content

Drawing rectangles in sequence each connected by a polyline


EYNLLIB

Recommended Posts

Currently I'm using a modified version of Lee Mac's Multi-Polyline to draw a multiline which is then converted into a closed polyline and hatched

I am wondering where I would begin to have each converted multiline connected by a polyline (see image) 

Essentially I am drawing a plan view of walls and headers, and want to make my workflow more efficient for adding in the headers automatically

 

 

Any help on a starting point would be much appreciated!

 

This is the code I'm working with so far;

 

;;------------------------=={ Multi-Polyline  }==-----------------------;;
;;                                                                      ;;
;;  This program enables the user to create objects with the appearance ;;
;;  of multilines, however, which are composed of standard polylines.   ;;
;;                                                                      ;;
;;  The program will invoke the standard AutoCAD MLINE command,         ;;
;;  allowing the user to construct the object with the real-time        ;;
;;  dynamic preview afforded by the MLINE command, with the resulting   ;;
;;  multiline automatically exploded & joined to form standard 2D       ;;
;;  polylines.                                                          ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright � 2010  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    2010-06-19                                      ;;
;;                                                                      ;;
;;  First release.                                                      ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2015-09-12                                      ;;
;;                                                                      ;;
;;  Program rewritten.                                                  ;;
;;----------------------------------------------------------------------;;

(defun c:mplb ( / *error* ent sel val var dict mstyle )

    (defun *error* ( msg )
        (mapcar 'setvar var val)
        (LM:endundo (LM:acdoc))
        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )

    ;; Open the MLINESTYLE dictionary
    (setq dict (vla-item 
                (vla-get-dictionaries 
                  (vla-get-activedocument (vlax-get-acad-object))
                ) 
                "ACAD_MLINESTYLE"
              )
    )
    ;; Check if the "BEARINGWALL" style exists
    (if (vl-catch-all-error-p 
          (setq mstyle (vl-catch-all-apply 'vla-item (list dict "BEARINGWALL")))
        )
      (progn
        (alert "The multiline style 'BEARINGWALL' was not found in the drawing.")
        (exit)
      )
      (setvar 'cmlstyle "BEARINGWALL")
    )

    ;; Start Undo
    (LM:startundo (LM:acdoc))
    
    ;; Set variables for hatch properties
    (setvar 'hpname "solid")
    (setvar 'hpscale 1)
    (setvar 'clayer "S - BEARING WALLS")
    
    
    (command "_.mline" "_J" "top" "")
    (setq ent (entlast))    

    
    (vl-cmdf "_.mline")
    (while (= 1 (logand 1 (getvar 'cmdactive)))
      (vl-cmdf "\\")
    )
    
    ;; Check if the multiline was exploded
    (if (not (eq ent (setq ent (entlast))))
      (progn
        ;; Save current variable values and set new values
        (setq var '(cmdecho peditaccept qaflags)
            val  (mapcar 'getvar var)
            sel  (ssadd)
        )
        (mapcar 'setvar var '(0 1 0))
        
        ;; Explode the multiline
        (vl-cmdf "_.explode" ent)
        
        ;; Add exploded entities to selection set
        (while (setq ent (entnext ent)) (ssadd ent sel))
        
        ;; Join the exploded entities
        (vl-cmdf "_.pedit" "_m" sel "" "_j" "" "")
            
            ;;; Create a new selection set for the joined polyline
            (setq sel2 (entlast))              
            (setvar 'HPASSOC 1) ; make hatches associative         
            ;; Add hatch to the joined polyline
            (vl-cmdf "_.bhatch" "_s" sel2 "" "")
            (setq hatchsel (entlast)) ; get the last created entity, which should be the hatch
            (vl-cmdf "_.chprop" hatchsel "" "_la" "S - SHADE" "") ; change the layer of the hatch to "S - SHADE"
            (vl-cmdf "_.DRAWORDER" hatchsel "" "_B" "")
        )
    )
          
    (*error* nil)
    (princ)
)

;; Start Undo  -  Lee Mac
;; Opens an Undo Group.
 
(defun LM:startundo ( doc )
    (LM:endundo doc)
    (vla-startundomark doc)
)
 
;; End Undo  -  Lee Mac
;; Closes an Undo Group.
 
(defun LM:endundo ( doc )
    (while (= 8 (logand 8 (getvar 'undoctl)))
        (vla-endundomark doc)
    )
)
 
;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object
 
(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)

(vl-load-com) (princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

 

 

1.png

Link to comment
Share on other sites

We work in 2D exclusively, but yes theoretically if the walls and headers are drawn via lisp that is what i'm looking for

Link to comment
Share on other sites

That is all 2D no solids just fools the eye to think its drawn in 3D, the walls are 4 lines, a big hint set thickness to say 2400 metric mm draw a line do vpoint 1,1,1 you will see a wall line. A "hide" shows true walls etc, can have windows as see through or solid. Use elevations in layouts so produce working dwg's.

 

Are you metric or imperial ?

 

 

Edited by BIGAL
Link to comment
Share on other sites

1 minute ago, BIGAL said:

That is all 2D no solids just fools the eye to think its drawn in 3D, the walls are 4 lines, a big hint set thickness to say 2400 metric mm draw a line do vpoint 1,1,1 you will see a wall line. A "hide" shows true walls etc, can have windows as see through or solid. Use elevations in layouts so produce working dwg's.

 

 

All I'd need is the 2d plan view like my image shows in the original post. Looking for a starting point in my code to draw the header polyline automatically between walls as i add them to the drawing

Link to comment
Share on other sites

Ok the hint draw the lines say 2 or 4 then pick left point and right point and draw your window frame breaking the original lines. You can use a dynamic block with a wipeout is another way. So no need to break wall.

Link to comment
Share on other sites

EYNLLIB,

Here is my suggestion for doing what you want.  I do not think you can easily modify Lee's routine to add a "line" header so I wrote a simple wrapper that should work for you.  I only tested it with Lee's ORIGINAL routine on his website but I would think it would work with your modified version.

For my test I set the multi-line justification to zero (centered) so the header (beam)  will be in the center of the wall.

To use this function:

1) Enter "wall-header" on the command line.

2) At the "start line" prompt enter J if you want to change the justification. Otherwise just click the start point of the wall.

3) Continue clicking points along the wall until your come to the point where you want the header. Click the point to end the wall then press <ENTER>.

4) At the prompt to select the end of the header just click the desired end point and a header will be drawn. 

5) The next prompt will be for the start of the wall so just click the end of the new header and continue to draw wall segments.

I could not think of a good way to stop this loop except to press <ESC> at the header end prompt. Perhaps someone can show me a better way.

; Routine to draw a multi-line wall with single line headers.
; Written: Jerry Fiedler - Feb 2024
; Multi-line routine Author:  Lee Mac, Copyright © 2010  -  www.lee-mac.com
(defun c:wall-header (/ ptS ptE)
	(while t
		(c:mpl)
		(setq ptS (getvar 'lastpoint))
		(setq ptE (getpoint ptS "\nEnd of header or ESC."))
		(entmake (list  
					(cons 0 "LINE")
					;(cons 8 headlyr)
					(cons 10 (trans ptS 1 0))
					(cons 11 (trans ptE 1 0)))
		)
	)

	(princ)
)

 

  • Like 1
Link to comment
Share on other sites

On 2/4/2024 at 2:43 PM, JerryFiedler said:

EYNLLIB,

Here is my suggestion for doing what you want.  I do not think you can easily modify Lee's routine to add a "line" header so I wrote a simple wrapper that should work for you.  I only tested it with Lee's ORIGINAL routine on his website but I would think it would work with your modified version.

For my test I set the multi-line justification to zero (centered) so the header (beam)  will be in the center of the wall.

To use this function:

1) Enter "wall-header" on the command line.

2) At the "start line" prompt enter J if you want to change the justification. Otherwise just click the start point of the wall.

3) Continue clicking points along the wall until your come to the point where you want the header. Click the point to end the wall then press <ENTER>.

4) At the prompt to select the end of the header just click the desired end point and a header will be drawn. 

5) The next prompt will be for the start of the wall so just click the end of the new header and continue to draw wall segments.

I could not think of a good way to stop this loop except to press <ESC> at the header end prompt. Perhaps someone can show me a better way.

; Routine to draw a multi-line wall with single line headers.
; Written: Jerry Fiedler - Feb 2024
; Multi-line routine Author:  Lee Mac, Copyright © 2010  -  www.lee-mac.com
(defun c:wall-header (/ ptS ptE)
	(while t
		(c:mpl)
		(setq ptS (getvar 'lastpoint))
		(setq ptE (getpoint ptS "\nEnd of header or ESC."))
		(entmake (list  
					(cons 0 "LINE")
					;(cons 8 headlyr)
					(cons 10 (trans ptS 1 0))
					(cons 11 (trans ptE 1 0)))
		)
	)

	(princ)
)

 

 

 

This works amazingly. Just had to update my mlstyle to work with a center justification, also modified to suit my needs slightly, thank you. see below for my modification

 

 

 

; Routine to draw a multi-line wall with single line headers.
; Written: Jerry Fiedler - Feb 2024, Modified by EYNLLIB - FEB 2024
; Multi-line routine Author:  Lee Mac, Copyright © 2010  -  www.lee-mac.com
(defun c:wh (/ ptS ptE *error*)
  (defun *error* (msg)
    (if (not (member msg '("Function cancelled" "quit / exit abort" nil)))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  )
  (while t
    (c:mplb)
    (setq ptS (getvar 'lastpoint))
    (setq ptE (getpoint ptS "\nEnd of header or ESC."))
    (if (not ptE) (exit))
    (entmake (list  
              (cons 0 "LWPOLYLINE")
              (cons 100 "AcDbEntity")
              (cons 100 "AcDbPolyline")
              (cons 90 2)
              (cons 70 0)
              (cons 8 "S - BEAMS")
              (cons 10 (trans ptS 1 0))
              (cons 10 (trans ptE 1 0))
              )
    )
  )

  (princ)
)

 

 

Edited by EYNLLIB
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi 

Yazılarınızı dıkkatlıce okudum kodlarda bazı karıstırdıgım noktalar oldu bunun için sizden isteğim bu lisp içeriğinin en son ki güncel halini lsp olarak gönderebilir misiniz.
şimdiden çok teşekkür ederim iyi çalışmalar

😀

Link to comment
Share on other sites

Google translation:

 

I read your articles carefully, there were some points in the codes that I confused, so I request you to send the latest version of this lisp content as lsp. Thank you very much in advance, good work

Link to comment
Share on other sites

5 hours ago, m.dolek.33.7 said:

Hi 

Yazılarınızı dıkkatlıce okudum kodlarda bazı karıstırdıgım noktalar oldu bunun için sizden isteğim bu lisp içeriğinin en son ki güncel halini lsp olarak gönderebilir misiniz.

Use together
or add to lisp mplb.lsp lisp wh.lsp
add to lisp MPlineV1-1.lsp lisp wall-header.lsp

 

wall-header_mpl.lsp wh_mplb.lsp

Edited by Nikon
Link to comment
Share on other sites

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...