Jump to content

Recommended Posts

Posted

Hi all,

Looking for a LISP routine to draw double polyline like MLINE.

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • mostafa badran

    11

  • lucas3

    4

  • BIGAL

    3

  • JamCAD

    3

Top Posters In This Topic

Posted Images

Posted

Use the MLine command then convert to LWPolylines using Lee Mac's Multilines to Polylines lisp routine.

Posted
Use the MLine command then convert to LWPolylines using Lee Mac's Multilines to Polylines lisp routine.

Exactly I do this but it take a long time.

I think when I draw polyline directly is better.

Posted
(defun c:2l(/ ent1 ent2 ent3 ent4 wwdy str1 pt1 pt2 dis1 ag1 pt1u pt2u)
 (setq ent1 nil ent2 nil ent3 nil ent4 nil)
 (defun sk_mkl(p1 p2)
 (entmakex
   (list
     '(0 . "line")
     (cons 10 p1)
     (cons 11 p2)
     )
   )
 )
 (setq wwdy (getreal "\nPlease enter the spacing between the two lines:"))
 (if (= wwdy nil)(setq wwdy 6))
 (setq str1 (rtos wwdy 2 2))
 (prompt "\n  now dline width is: ")
 (prompt str1)
 (if(setq pt1 (getpoint "\n enter start point:"))
 (while (setq pt2 (getpoint pt1 "\n enter next point:"))
   (redraw)
   (if (and ent1 ent2)
     (setq ent3 ent1
     ent4 ent2))
   (setq dis1 (* 0.5 wwdy))
   (setq ag1 (angle pt1 pt2))
   (setq pt1u (polar pt1 (+ ag1 1.5708) dis1))
   (setq pt2u (polar pt2 (+ ag1 1.5708) dis1))
   (setq pt1d (polar pt1 (- ag1 1.5708) dis1))
   (setq pt2d (polar pt2 (- ag1 1.5708) dis1))
   (setq ent1(sk_mkl pt1u pt2u)
   ent2(sk_mkl pt1d pt2d)
   pt1 pt2
     )
   (setvar "FILLETRAD" 0.0)
   (command "FILLET"  ent1 ent3)
   (command "FILLET"  ent2 ent4)
   )
 )  
 (princ)
)

Posted
Exactly I do this but it take a long time.

I think when I draw polyline directly is better.

 

Take a long time? Do you mean the actual lisp routine runs slowly? Or that you want to effectivly reduce the steps of drawing the Mline, loading the lisp routine, and running the routine?

Posted
(defun c:2l(/ ent1 ent2 ent3 ent4 wwdy str1 pt1 pt2 dis1 ag1 pt1u pt2u)
 (setq ent1 nil ent2 nil ent3 nil ent4 nil)
 (defun sk_mkl(p1 p2)
 (entmakex
   (list
     '(0 . "line")
     (cons 10 p1)
     (cons 11 p2)
     )
   )
 )
 (setq wwdy (getreal "\nPlease enter the spacing between the two lines:"))
 (if (= wwdy nil)(setq wwdy 6))
 (setq str1 (rtos wwdy 2 2))
 (prompt "\n  now dline width is: ")
 (prompt str1)
 (if(setq pt1 (getpoint "\n enter start point:"))
 (while (setq pt2 (getpoint pt1 "\n enter next point:"))
   (redraw)
   (if (and ent1 ent2)
     (setq ent3 ent1
     ent4 ent2))
   (setq dis1 (* 0.5 wwdy))
   (setq ag1 (angle pt1 pt2))
   (setq pt1u (polar pt1 (+ ag1 1.5708) dis1))
   (setq pt2u (polar pt2 (+ ag1 1.5708) dis1))
   (setq pt1d (polar pt1 (- ag1 1.5708) dis1))
   (setq pt2d (polar pt2 (- ag1 1.5708) dis1))
   (setq ent1(sk_mkl pt1u pt2u)
   ent2(sk_mkl pt1d pt2d)
   pt1 pt2
     )
   (setvar "FILLETRAD" 0.0)
   (command "FILLET"  ent1 ent3)
   (command "FILLET"  ent2 ent4)
   )
 )  
 (princ)
)

Thanks Mr lucas3 for your reply. :o

That is what I want,I don't know if it possible to edit it to draw polyline?

Posted
Take a long time? Do you mean the actual lisp routine runs slowly? Or that you want to effectivly reduce the steps of drawing the Mline, loading the lisp routine, and running the routine?

yes j0nat as you said that effectively reduce the steps of drawing the Line, loading the lisp routine, and running the routine.

Posted
Thanks Mr lucas3 for your reply. :o

That is what I want,I don't know if it possible to edit it to draw polyline?

 

(defun c:2l(/ ent1 ent2 ent3 ent4  wwdy1 str1 pt1 pt2 dis1 ag1 pt1u pt2u sspl)
 (setq ent1 nil ent2 nil ent3 nil ent4 nil sspl nil)
 (defun sk_mkl(p1 p2)
 (entmakex
   (list
     '(0 . "line")
     (cons 10 p1)
     (cons 11 p2)
     )
   )
 )
 (setq cmd_old(getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (or  wwdy (setq wwdy 6))
 (if(setq wwdy1 (getreal (strcat "\nPlease enter the spacing between the two lines:<Current:"(rtos wwdy 2 3) ">:")))
   (setq wwdy wwdy1))  
 (setq str1 (rtos wwdy 2 2) sspl (ssadd))
 (prompt "\n  now dline width is: ")
 (prompt str1)
 (if(setq pt1 (getpoint "\n enter start point:"))
   (progn
 (while (setq pt2 (getpoint pt1 "\n enter next point:"))
   (redraw)
   (if (and ent1 ent2)
     (setq ent3 ent1
           ent4 ent2))
   (setq dis1 (* 0.5 wwdy))
   (setq ag1 (angle pt1 pt2))
   (setq pt1u (polar pt1 (+ ag1 1.5708) dis1))
   (setq pt2u (polar pt2 (+ ag1 1.5708) dis1))
   (setq pt1d (polar pt1 (- ag1 1.5708) dis1))
   (setq pt2d (polar pt2 (- ag1 1.5708) dis1))
   (setq ent1(sk_mkl pt1u pt2u)
         ent2(sk_mkl pt1d pt2d)
         pt1 pt2
     )
   (setvar "FILLETRAD" 0.0)
   (command "FILLET"  ent1 ent3)
   (command "FILLET"  ent2 ent4)
   (if(and ent1 ent2)
     (setq sspl(ssadd ent1 sspl)
           sspl(ssadd ent2 sspl)))
   (if(and ent3 ent4)
     (setq sspl(ssadd ent3 sspl)
           sspl(ssadd ent4 sspl)
         ))
   )
 
 (if (and sspl (> (sslength sspl) 2))
   (command "pedit" "m" sspl "" "j" "0.00" "")
   )
 )
 )
 (if cmd_old (setvar 'cmdecho cmd_old))
 (princ)
)

Posted
(defun c:2l(/ ent1 ent2 ent3 ent4  wwdy1 str1 pt1 pt2 dis1 ag1 pt1u pt2u sspl)
 (setq ent1 nil ent2 nil ent3 nil ent4 nil sspl nil)
 (defun sk_mkl(p1 p2)
 (entmakex
   (list
     '(0 . "line")
     (cons 10 p1)
     (cons 11 p2)
     )
   )
 )
 (setq cmd_old(getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (or  wwdy (setq wwdy 6))
 (if(setq wwdy1 (getreal (strcat "\nPlease enter the spacing between the two lines:<Current:"(rtos wwdy 2 3) ">:")))
   (setq wwdy wwdy1))  
 (setq str1 (rtos wwdy 2 2) sspl (ssadd))
 (prompt "\n  now dline width is: ")
 (prompt str1)
 (if(setq pt1 (getpoint "\n enter start point:"))
   (progn
 (while (setq pt2 (getpoint pt1 "\n enter next point:"))
   (redraw)
   (if (and ent1 ent2)
     (setq ent3 ent1
           ent4 ent2))
   (setq dis1 (* 0.5 wwdy))
   (setq ag1 (angle pt1 pt2))
   (setq pt1u (polar pt1 (+ ag1 1.5708) dis1))
   (setq pt2u (polar pt2 (+ ag1 1.5708) dis1))
   (setq pt1d (polar pt1 (- ag1 1.5708) dis1))
   (setq pt2d (polar pt2 (- ag1 1.5708) dis1))
   (setq ent1(sk_mkl pt1u pt2u)
         ent2(sk_mkl pt1d pt2d)
         pt1 pt2
     )
   (setvar "FILLETRAD" 0.0)
   (command "FILLET"  ent1 ent3)
   (command "FILLET"  ent2 ent4)
   (if(and ent1 ent2)
     (setq sspl(ssadd ent1 sspl)
           sspl(ssadd ent2 sspl)))
   (if(and ent3 ent4)
     (setq sspl(ssadd ent3 sspl)
           sspl(ssadd ent4 sspl)
         ))
   )
 
 (if (and sspl (> (sslength sspl) 2))
   (command "pedit" "m" sspl "" "j" "0.00" "")
   )
 )
 )
 (if cmd_old (setvar 'cmdecho cmd_old))
 (princ)
)

Thank you so much, but sometimes makes line and sometimes makes polyline sorry for inconvenience.:(

Posted
Thank you so much, but sometimes makes line and sometimes makes polyline sorry for inconvenience.:(

 

sometimes makes line and sometimes makes polyline ???what's meaning?

Posted
sometimes makes line and sometimes makes polyline ???what's meaning?

I mean when I used the lisp it's draw sometimes 2 line and sometimes draw 2 polyline.

sorry for my bad English.

Posted
I mean when I used the lisp it's draw sometimes 2 line and sometimes draw 2 polyline.

sorry for my bad English.

 

Convert Lines, Arcs and Splines to polylines [Yes/No]? y

Enter an option [Close/Open/Join/Width/Fit/Spline/Decurve/Ltype

gen/Reverse/Undo]: j

Join Type = Extend

Enter fuzz distance or [Jointype] :

12 segments added to 2 polylines

Posted
Convert Lines, Arcs and Splines to polylines [Yes/No]? y

Enter an option [Close/Open/Join/Width/Fit/Spline/Decurve/Ltype

gen/Reverse/Undo]: j

Join Type = Extend

Enter fuzz distance or [Jointype] :

12 segments added to 2 polylines

OK, thanks Mr lucas3 for your help.:)

Posted
Convert Lines, Arcs and Splines to polylines [Yes/No]? y

Enter an option [Close/Open/Join/Width/Fit/Spline/Decurve/Ltype

gen/Reverse/Undo]: j

Join Type = Extend

Enter fuzz distance or [Jointype] :

12 segments added to 2 polylines

I noticed when I press ESC button in the end of command it makes line, when I press Enter button it makes polyline.

thank Mr. for your effort.

Posted

A simpler alternative would be to draw a series of lines remember the end points then draw a pline offset as many times and L&R as required delete original pline as a finish, either pre-programmed offset or use +3 -3 for left & right 3 units.

 

(setq pt1 (getpoint))
(while etc
(setq pt2 (getpoint pt1)) ; rubber band appears
(setq pt1 pt2)
) ; end while

Posted

mostafa,

 

I created a quick lisp that will draw a multi line as normal. I then made a very slight modification to Lee Macs code to convert it to polylines. Unfortunately I couldn't get the mline to preview as it was being drawn. Once the lisp is loaded type mpline to start.

 

(defun c:mpline (/ pt1 pt2)
 (setq pt1 (getpoint "\nSelect first point: "))
 (progn
   (command "_.mline"
     "_non"
     pt1
     (progn
       (while (setq pt2 (getpoint pt1 "\nSelect next point:"))
  (command "non" pt2)
  (setq pt1 pt2)
       )
     )
     ""
   )
   (c:ml2pl)
 )
)
;;Below is a slightly modified version of Lee Macs Mline to Pline routine
;;--------------=={ Multilines to LWPolylines }==-------------;;
;;                                                            ;;
;;  Converts a selection of Multiline (MLINE) objects into    ;;
;;  LWPolylines.                                              ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2012 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url]       ;;
;;------------------------------------------------------------;;
;;  Version 1.1    -    10-06-2012                            ;;
;;------------------------------------------------------------;;
(defun c:ml2pl (/ *error* doc el en i s1 s2 val var )
   (defun *error* ( msg )
       (if val (mapcar 'setvar var val))
       (if doc (LM:endundo doc))
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )
   
   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         var '("CMDECHO" "PEDITACCEPT" "QAFLAGS")
         val  (mapcar 'getvar var)
   )
   (if (setq s1 (ssadd) s1 (ssadd (entlast)) ) ;;Line of code modified to select the mline just created
       (progn
           (LM:startundo doc)
           (mapcar 'setvar var '(0 1 0))
           (repeat (setq i (sslength s1))
               (setq en (ssname s1 (setq i (1- i)))
                     el (entlast)
                     s2 (ssadd)
               )
               (command "_.explode" en)
               (while (setq el (entnext el))
                   (ssadd el s2)
               )
               (command "_.pedit" "_M" s2 "" "_J" "" "")
               (setq s2 nil)
           )
           (mapcar 'setvar var val)
           (LM:endundo doc)
       )
   )
   (princ)
)
(defun LM:startundo ( doc )
   (LM:endundo doc)
   (vla-startundomark doc)
)
(defun LM:endundo ( doc )
   (while (= 8 (logand 8 (getvar 'undoctl)))
       (vla-endundomark doc)
   )
)
(vl-load-com)
(princ "\nType mpline to start\n")
(princ)

Posted

Lots of lines of code above look below 3 lines !!

 

Thinking about this out loud pick points then multiple plines at any offset +&-ve and any width in one go, why not !

enter 3 goes 3 right 0 width

enter 3,0.25 goes 3 width 0.25

enter -73,2.5 goes 73 left width 2.5

 

maybe this -73,5,0 goes left 73 width starts 5 ends 0

 

(princ "\nPick st pt enter to finish")
 (command "_pline")
 (while (= (getvar "cmdactive") 1 ) (command pause) )

Posted
mostafa,

 

I created a quick lisp that will draw a multi line as normal. I then made a very slight modification to Lee Macs code to convert it to polylines. Unfortunately I couldn't get the mline to preview as it was being drawn. Once the lisp is loaded type mpline to start.

 

(defun c:mpline (/ pt1 pt2)
 (setq pt1 (getpoint "\nSelect first point: "))
 (progn
   (command "_.mline"
     "_non"
     pt1
     (progn
       (while (setq pt2 (getpoint pt1 "\nSelect next point:"))
  (command "non" pt2)
  (setq pt1 pt2)
       )
     )
     ""
   )
   (c:ml2pl)
 )
)
;;Below is a slightly modified version of Lee Macs Mline to Pline routine
;;--------------=={ Multilines to LWPolylines }==-------------;;
;;                                                            ;;
;;  Converts a selection of Multiline (MLINE) objects into    ;;
;;  LWPolylines.                                              ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2012 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url]       ;;
;;------------------------------------------------------------;;
;;  Version 1.1    -    10-06-2012                            ;;
;;------------------------------------------------------------;;
(defun c:ml2pl (/ *error* doc el en i s1 s2 val var )
   (defun *error* ( msg )
       (if val (mapcar 'setvar var val))
       (if doc (LM:endundo doc))
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )
   
   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         var '("CMDECHO" "PEDITACCEPT" "QAFLAGS")
         val  (mapcar 'getvar var)
   )
   (if (setq s1 (ssadd) s1 (ssadd (entlast)) ) ;;Line of code modified to select the mline just created
       (progn
           (LM:startundo doc)
           (mapcar 'setvar var '(0 1 0))
           (repeat (setq i (sslength s1))
               (setq en (ssname s1 (setq i (1- i)))
                     el (entlast)
                     s2 (ssadd)
               )
               (command "_.explode" en)
               (while (setq el (entnext el))
                   (ssadd el s2)
               )
               (command "_.pedit" "_M" s2 "" "_J" "" "")
               (setq s2 nil)
           )
           (mapcar 'setvar var val)
           (LM:endundo doc)
       )
   )
   (princ)
)
(defun LM:startundo ( doc )
   (LM:endundo doc)
   (vla-startundomark doc)
)
(defun LM:endundo ( doc )
   (while (= 8 (logand 8 (getvar 'undoctl)))
       (vla-endundomark doc)
   )
)
(vl-load-com)
(princ "\nType mpline to start\n")
(princ)

Sorry for the delay thanks j0nat for your effort, it is a good idea to do this task thank you again.

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