Jump to content

Offset with list (like Multiple Offset on the appstore)


3dwannab

Recommended Posts

20 hours ago, BIGAL said:

Why not use a Mline then can draw walls as in plural. 

 

This is a make mline.

 

Nice, this would be handy for again. I'm modifying existing drawings and just thought it handier to delete the inner leafs and offset the correct thickness of wall while still mantaining the openings.

 

BTW, that program hangs my ACAD 2025 after I press enter for the final time.

Link to comment
Share on other sites

If you have multiple wall sizes that you use all the time you could make a list of lists with the wall sizes, I know I push my Multi radio buttons & Multi getvals lisp's, but using these would let you quickly choose preset wall sizes. The reason I mention Multi getvals.lsp as a second step is it allows you to change any of the values when setting the wall thickness.

 

You could do a custom dcl left side radio buttons right side edit box shows values that have been selected from the radio button.

 

Multi's posted many times here.

 

(setq walls (list (list "BRK-CAV-INNER-PLAS" 102.5 252.5 467.5 485.5)(list "STD-CAV" 102 180 270 288)))

 

  • Like 1
Link to comment
Share on other sites

Thanks @BIGAL, I just use the up key after running the command. It returns any last used values used for any given command like when there's no command active where it cycles through previous commands used.

 

You may of missed the bit were I said that makml hangs my autocad when pressing the last enter.

 

I'll test it on my work machine tomorrow.

Edited by 3dwannab
Link to comment
Share on other sites

I just tested the makml I just gave the mline a name then a description, say followed by 1, -1 , Enter, ML, line works ok.

 

 

Link to comment
Share on other sites

1 hour ago, BIGAL said:

I just tested the makml I just gave the mline a name then a description, say followed by 1, -1 , Enter, ML, line works ok.

 

 

Sorry. Busy day at work. Will test Tuesday when I get back. Enjoying the bank holiday here in Ireland  🍻 

Link to comment
Share on other sites

On 10/25/2024 at 10:58 PM, BIGAL said:

I just tested the makml I just gave the mline a name then a description, say followed by 1, -1 , Enter, ML, line works ok.

 

 

Tested on my work machine and the same issue. Entered in the same values as you.

 

Both cases are ACAD 2025.

Link to comment
Share on other sites

16 hours ago, BIGAL said:

I am using Bricscad V24 soon V25. 

 

Anybody else using 2025 that can maybe test I don't have 2025.

@BIGAL I tested with AutoCAD 2025 and it freezes up after the prompts. I had to use Task Manager to shut it down. I'm looking over your code, but I am not sure why it's hanging up yet.

Link to comment
Share on other sites

@BIGAL This seems to work. Looks like you had an invalid DXF code (72) for MLINESTYLE and the (71) code should be the number of elements. See below:

(defun c:makml ( / lst1 lst2 lst desc MLINE_STYLE_NAME off)
   (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 (+ 16 256))
		      (cons 3 desc)
		     '(62 . 256)
		      (cons 51 (/ pi 2.))
		      (cons 52 (/ pi 2.))
		      (cons 71 (length lst))
     )
  )
  (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")
    (Princ (strcat "\nMLINESTYLE \"" MLINE_STYLE_NAME "\" Created."))
  )
  (setvar 'cmlstyle MLINE_STYLE_NAME)
  (princ)
)

 

Link to comment
Share on other sites

@3dwannab

FWIW - Here is how I would re-write @BIGAL's code above to have some basic error handling to prevent an invalid MLINESTYLE from being created (Yes - I found out it will create an MLINESTYLE with no elements).

 

(defun c:MAKMLSTYLE (/ des i lst mle mln off)
   (setq mln (getstring "\nEnter a name of the MLINE Style: ")
         des (getstring t "Enter a Description for the MLINE Style:")
         des (if (= des "") mln des)
   )
   (while (setq off (getreal "\nEnter MLINE Offsets one value at a time, then ENTER to continue: " ))
      (setq lst (cons off lst))
   )
   (if (and (/= mln "") lst (> (length lst) 1))
      (progn
         (setq mle
            (list
               '(0 .   "MLINESTYLE")
               '(100 . "AcDbMlineStyle")
               (cons 2 mln)
               (cons 70 (+ 16 256))
               (cons 3 des)
               '(62 . 256)
               (cons 51 (/ pi 2.))
               (cons 52 (/ pi 2.))
               (cons 71 (setq i (length lst)))
            )
         )
         (repeat i
            (setq mle
               (append mle
                  (list
                     (cons 49 (nth (setq i (1- i)) lst))
                     (cons 62 256)
                     (cons 6 "BYLAYER")
                  )
               )
            )
         )
         (if (not (dictadd (cdar (dictsearch (namedobjdict) "ACAD_MLINESTYLE")) mln (entmakex mle)))
            (Alert (strcat "Unable to create MLINESTYLE \"" mln "\"\nThe Style May already Exist."))
            (progn
               (Princ (strcat "\nMLINESTYLE \"" mln "\" Created."))
               (setvar 'cmlstyle mln)
            )
         )
      )
      (progn
         (if (= mln "")(Princ "\nYou must provide a Name for the MLINESTYLE. "))
         (if (< (Length lst) 2)(princ "\nThe MLINESTYLE must have at least 2 elements."))
      )
   )
   (princ)
)

 

  • Like 1
Link to comment
Share on other sites

4 hours ago, pkenewell said:

FWIW - Here is how I would re-write

Cool, thanks @pkenewell. Here's a ml command that I modified from LeeMac original code. Allows you to set the scale and justification. I find this handier than the built in way because more often than not I use the standard ml style and pick the distance with this command to set the wall thickness and setting the justification every time is a must for me. Such a shame ACAD didn't write the program so the justification could be changed mid command.

 

;;------------------------=={ 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.                                                  ;;
;;----------------------------------------------------------------------;;
;;
;; Revision by 3dwannab 2023.01.24
;;  - Added - Changing the linetype of the mline to bylayer.
;;  - Added - Selects the new polyline after its creation.
;;  - Added - A scale prompt and the mline justification prompt before every mline. Value of ml scale is saved to the registry so it'll be remembered throughout your different ACAD sessions.
;;
;; Revision by 3dwannab 2024.10.24
;;  - Fixed - My code to select the new polylines. Didn't select all polylines when the mline was a closed one.
;;
;; Revision by 3dwannab 2024.10.29
;;  - Added - Current ML Style shown in scale prompt.
;;  - Change - getdis used for scale of ML scale.
;;

(defun c:ml (/ *error* ent obj regValMLScale ss1 ss2 ssnew val var var_osmode) 

  (defun *error* (msg) 
    (mapcar 'setvar var val)

    (setvar 'osmode var_osmode)

    (LM:endundo (LM:acdoc))
    (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) 
      (princ (strcat "\nError: " msg))
    )
    (princ)
  )

  (setq var_osmode (getvar "osmode"))

  (LM:startundo (LM:acdoc))
  (setq ent (entlast))

  ;; Get saved round off value from the registry or default to 1
  (setq regValMLScale (cond ((getenv "MPlineMLScaleValue")) (1)))

  ;; Prompt for integer value to round off to
  (setq regValMLScale (cond 
                        ((getdist
                           (strcat "\nCurrent style: "
                                   (getvar "cmlstyle")
                                   " / What Scale do you want the polyline? "
                                   "<"
                                   (vl-princ-to-string regValMLScale)

                                   ">: "
                           )
                         )
                        )
                        (regValMLScale)
                      )
  )
  ;; Set the registry value to the variable
  (setenv "MPlineMLScaleValue" (vl-princ-to-string regValMLScale))

  ;; Get new selection set of polylines after join operation
  (setq ssnew (ssget "X" '((0 . "LWPOLYLINE")))) ; Get all polylines again

  (vl-cmdf "_.mline" "s" regValMLScale "j")
  (while (= 1 (logand 1 (getvar 'cmdactive))) 
    (vl-cmdf "\\")
  )
  (if (not (eq ent (setq ent (entlast)))) 
    (progn 
      (setq var '(cmdecho peditaccept qaflags)
            val (mapcar 'getvar var)
            ss1 (ssadd)
      )
      (mapcar 'setvar var '(0 1 0))
      (vl-cmdf "_.explode" ent "")
      (while (setq ent (entnext ent)) (ssadd ent ss1))

      ;; Get a list of entities before the join operation
      (setq ss2 (ssget "X" '((0 . "LWPOLYLINE")))) ; Get all existing polylines

      (vl-cmdf "_.chprop" ss1 "" "_lt" "_bylayer" "")

      ;; Perform join operation on selected objects
      (vl-cmdf "_.pedit" "_m" ss1 "" "_j" "" "")

      ;; Get new selection set of polylines after join operation
      (setq ssnew (ssget "X" '((0 . "LWPOLYLINE")))) ; Get all polylines again

      ;; Compare and find the new polylines created by the join command
      (setq obj nil) ; Initialize a list for newly created polylines
      (if ssnew 
        (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ssnew))) 
          (if (not (ssmemb ent ss2))  ; If the entity wasn't in the old set
            (setq obj (cons ent obj)) ; Add the entity to the new polyline list
          )
        )
      )

      ;; Highlight the new polylines
      (if obj 
        (progn 
          (setq ssnew (ssadd)) ; Create a new selection set
          (foreach ent obj 
            (ssadd ent ssnew) ; Add each new polyline to the selection set
          )
          (sssetfirst nil ssnew) ; Highlight the new polylines
          (princ " \nMuliline created")
          (command "_.regen")
        )
        (princ " \nNo Muliline created")
      )
    )
  )

  (*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                              ;;
;;----------------------------------------------------------------------;;

; (c:ml) ;; Unblock for testing

 

Edited by 3dwannab
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...