Drawing rectangles in sequence each connected by a polyline

Drawing rectangles in sequence each connected by a polyline

king
Enthusiast Enthusiast
470 Views
2 Replies
Message 1 of 3

Drawing rectangles in sequence each connected by a polyline

king
Enthusiast
Enthusiast

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                              ;;
;;----------------------------------------------------------------------;;
0 Likes
471 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

No style and layer management - you didn't post any.

 

(defun c:headwalls ( / f s e i l)

  (setvar 'hpdraworder 3)
  
  (while (setq f (getpoint "\nFirst point: "))
    
    (setq e (entlast))
    (command "_.mline" "_non" f) (while (> (getvar 'cmdactive) 0) (command pause))

    (if (not (equal e (setq e (entlast))))
      (progn
	(command "_.explode" e)
	(setq s (ssget "_p"))
	(foreach i '(0 1)
	  (setq l (append (list (trans (mapcar '/ (mapcar '+ (cdr (assoc 10 (entget (ssname s i)))) (cdr (assoc 11 (entget (ssname s i))))) '(2 2)) 0 1)) l)))
	(initcommandversion)
	(command "_.join" s "")
	(command "_.bhatch" "_s" "_l" "" "")
	(command "_.chprop""_l" "" "_la" "0" ""))))
  
  (if (setq l (cdr l))
    (while (cadr l)
      (command "_.pline" "_non" (car l) "_non" (cadr l) "")
      (setq l (cddr l))))
  (princ)
  )

 

0 Likes
Message 3 of 3

Kent1Cooper
Consultant
Consultant

Not really what you're after, but it's possible to draw a Polyline with its width toggling between a non-zero starting width and zero for each successive segment.  In simplest terms:

 

(defun C:plwt ; = PolyLine with Width Toggling
  (/ plw)
  (setq plw (getvar 'plinewid))
  (command "_.pline" pause)
  (while t (command pause "_width" 0 "" pause "_width" plw ""))
)

 

PLWT.gif

That results in a single object.  It requires the non-zero PLINEWID System Variable value to be in place first, but of course could be made to ask for it.

Kent Cooper, AIA
0 Likes