Jump to content

Need help creating a lisp routine.


fuqua

Recommended Posts

Hello All,

 

could someone make me a simple lisp routine that puts a multileader with 2 arrows each arrow needs to point to the start and endpoint of a polyline and prompt me to enter the label for the multileader plus the label needs to run 3 meters polar to the polyline. 

 

i have attached an example in which i have manually put n the multileader and rotate them so their are a bit parallel to the polyline.

 

 

WTE-001-CR99.dwg

image.png

Edited by fuqua
added screenshot
Link to comment
Share on other sites

  • 4 weeks later...
Posted (edited)
(defun c:ml2polyline ()
  (setq pline (car (entsel "\nSelect a polyline: ")))
  (if (not (eq (cdr (assoc 0 (entget pline))) "POLYLINE"))
    (progn
      (princ "\nSelected object is not a polyline.")
      (princ)
    )
    (progn
      (setq plineStart (cdr (assoc 10 (entget pline))))
      (setq plineEnd (cdr (assoc 11 (entget pline))))
      (if (not (and plineStart plineEnd))
        (progn
          (princ "\nError getting polyline coordinates.")
          (princ)
        )
        (progn
          (setq midPoint (polar plineStart (angle plineStart plineEnd) (/ (distance plineStart plineEnd) 2)))
          (command "_.MLEADER" plineStart "")
          (command ".leader" plineEnd "")
          (setq ml (entlast))
          (command ".leader" plineStart "")
          (setq ml2 (entlast))
          (command ".leader" plineEnd "")
          (setq ml3 (entlast))
          (setq angle (angle plineStart plineEnd))
          (command "_.rotate" ml "" plineStart angle)
          (command "_.rotate" ml2 "" plineStart angle)
          (command "_.rotate" ml3 "" plineEnd (+ angle pi))
          (princ "\nMultileader added successfully.")
        )
      )
    )
  )
  (princ)
)

 

ive have come up this much, but it doesnt work, when asked to select a polyline, i do so but then autocad says i have not selected a polyline ?!

 

where am i going wrong here does anyone have an idea?

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

Polylines can be lighweight (LW) or 3D so you need to say which one you want:

 

(if (not (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE"))

 

Tip: To check the type is entered correctly use this

 

(entget (car (entsel "Select entity")))

 

which will show the entity definition in the command bar, useful to check you are using the right things

Link to comment
Share on other sites

@Steven P Thank you, that did the trick. But it still has trouble placing a multileader, for some reason it places a leader? And it also doesn't display my intended behavious by placing an arrow at the start and end point and in the middle the text.

 

(defun c:ml ()
  ; Select a polyline
  (setq sel (entsel "\nSelect a polyline: "))
  (if (not sel)
    ; No selection made
    (progn
      (princ "\nNo selection made.")
      (princ)
    )
    ; Valid selection made
    (progn
      (setq pline (car sel))
      ; Check if the selected object is a polyline
      (if (not (eq (cdr (assoc 0 (entget pline))) "LWPOLYLINE"))
        ; Not a polyline
        (progn
          (princ "\nSelected object is not a polyline.")
          (princ)
        )
        ; Is a polyline
        (progn
          ; Get the polyline data
          (setq plineData (entget pline))
          ; Initialize a list to store the polyline coordinates
          (setq plineCoords '())
          ; Iterate through the polyline data and extract the coordinates
          (foreach data plineData
            (if (and (listp data) (eq (car data) 10))
              (setq plineCoords (append plineCoords (cdr data)))
            )
          )
          ; Get the start and end points of the polyline
          (setq plineStart (list (nth 0 plineCoords) (nth 1 plineCoords)))
          (setq plineEnd (list (nth (- (length plineCoords) 2) plineCoords) (nth (- (length plineCoords) 1) plineCoords)))
          ; Check if the start or end points are null
          (if (or (null plineStart) (null plineEnd))
            ; Error getting polyline coordinates
            (progn
              (princ "\nError getting polyline coordinates.")
              (princ)
            )
            ; Coordinates are valid
            (progn

              ; **Place the multileader with two leaders:**

              (command "_multileader" "Leader" plineStart plineEnd "Leader" plineEnd "Text" "M")
              (command "_multileaderstyle" "Annotative" "Yes" "Scale" 1)
              (command "_multileaderscale" 1)

              (princ "\nPolyline coordinates and multileader with two leaders successfully placed.")
            )
          )
        )
      )
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

(defun c:len_line (/ curve len_curve pt)
 (vl-load-com)
 (setq curve     (vlax-ename->vla-object (car (entsel "Select a polyline >")))
       len_curve (vlax-curve-getDistAtPoint curve (vlax-curve-getEndPoint curve))
       pt            (vlax-curve-getPointAtDist curve (/ len_curve 2))
 )
 (vl-cmdf "_leader" pt pause "" (strcat (rtos len_curve 2 2) " m") "")
)

 

Link to comment
Share on other sites

(defun c:mll (/ curve len_curve pts pte)
 (vl-load-com)
 (setq curve     (vlax-ename->vla-object (car (entsel "Select a polyline >")))
       len_curve (vla-get-Length curve)
       pts       (vlax-curve-getStartPoint curve)
       pte       (vlax-curve-getEndPoint curve)
 )
 (vl-cmdf "_mleader" pts pte (strcat (rtos len_curve 2 2) " m"))
)

 

Link to comment
Share on other sites

I think one solution is to take advantage of pline width, you can draw a short start and end section with width = 0 then say 0.5 then 0 for mid section then use Mtext with mask, will have a play.

image.thumb.png.ac60403fb68c87244bd6047733fb157d.png

 

Trying to find how you make a double arrow Mleader ?

Link to comment
Share on other sites

@BIGAL i thought about something similar, Unfortunately im obligated to use multileaders :(

 

@1958 Atleast its recognized as a multileader, but the 2nd arrow is not appearing. the behaviour is more to my liking, my script made a mess by askign me to select the begin and end point while the script had to find it itself. I am starting to wonder if this is possible at all?

Link to comment
Share on other sites

Pity, I do as BIgAl with one of my routines - was far easier to code for that application

Link to comment
Share on other sites

@BIGAL A dynamic block could put a multileader over a polyline? And look like what i have in my 1st post? If that works after i explode it and only the multileader remains i would be happy, but the block cannot remain. Like i said it must be a multileader because that is how our contractor wants it.

Link to comment
Share on other sites

Some one smarter than me will provide how to do a multi leader with two arrows. 

 

I have attached a Excel file that shows a normal mleader and the 2 line mleader. It can be seen that there is a second LEADER section with a leader line, as there is some entity data in there not really sure where you would add second leader linto a entmod. 

 

Did you ask who made the sample leaders for code or is it a case of costs money.

Double line leader.xlsx

Edited by BIGAL
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...