Jump to content

Lisp routine for the widths of perpendicular lines


bsimpson

Recommended Posts

Hi,

 

For the new year see if you can have a go at.

 

The widths of multiple lines drawn at a spacing x along a polyline that interesect another line that runs in the same direction.

 

The distance measured from the perpendiclar snap of the interesection to the polyline to the intersection of the other line must be placed in an ascii file along with the cumulative spacing increment.

 

thanks

B Simpson.

Link to comment
Share on other sites

Perhaps this?

 

 ; Incremental Measurement Between Two Lines/Polylines

 ; by Lee McDonnell  ~  17.01.2009

 ; [Assumes Polylines have only 2 Vertices]

(defun c:mspc (/ oFile cCurve cCurvel dCurve dCurvel mSpc sPt ePt cAng nlist dis i pdis pt wpt wDis)
 (vl-load-com)
 (if (setq oFile (open (getfiled "Create a Text File" "C:\\" "txt" 9) "w"))
   (progn
     (if (and (setq cCurve (car (entsel "\nSelect First Curve  > ")))
          (member (cdr (assoc 0 (setq cCurvel (entget cCurve)))) '("LINE" "LWPOLYLINE"))
          (setq dCurve (car (entsel "\nSelect Curve to Measure To  > ")))
          (member (cdr (assoc 0 (setq dCurvel (entget cCurve)))) '("LINE" "LWPOLYLINE")))
   (progn
     (initget 7)
     (setq mSpc (getreal "\nSpecify Measurement Increment:  "))
     (cond    ((= "LINE" (cdr (assoc 0 cCurvel)))
        (setq sPt  (cdr (assoc 10 cCurvel))
              ePt  (cdr (assoc 11 cCurvel))
              cAng (angle sPt ePt)))
       ((= "LWPOLYLINE" (cdr (assoc 0 cCurvel)))
        (foreach x cCurvel
          (if (eq 10 (car x))
            (setq nlist (cons (cdr x) nlist))))
        (setq nlist (reverse nlist)
              sPt   (nth 0 nlist)
              ePt   (nth 1 nlist)
              cAng  (angle sPt ePt))))
     (setq    dis  (distance sPt ePt) i 0 pdis 0)
     (while (<= pdis dis)
       (setq pdis (* i mSpc)
         pt   (polar sPt cAng pdis)
         wpt  (vlax-curve-getClosestPointTo dCurve pt T)
         wDis (distance wpt pt))
       (write-line (strcat (rtos (car pt) 2 2) "," (rtos (cadr pt) 2 2) "\t" (rtos wDis 2 2)) oFile)
       (setq i (1+ i)))
     (close oFile))
   (princ "\n<!> No Curve Selected, or this isn't a Line/Polyline <!> ")))
   (princ "\n<!> No File Selected <!> "))
 (princ))

Link to comment
Share on other sites

Thanks Lee,

 

This is a 2D situation.

 

The lisp routine written gave an error with my computer the error was *cancel*

 

I would presume that it is the version of AutoCAD. The version I am using is AutoCAD 14.

 

Hopefully the routine can be edited to suite.

 

regards

bsimpson

Link to comment
Share on other sites

Well there probably is a work-around without using VL commands, but obviously, when you have the VL commands at your disposal, I have never really opted for the Common LISP approach.

 

I used the Vlax-Curve-GetClosestPointTo, as, in a 2D problem with two straight lines, the closest point will always be the perpendicular to one of the lines, but to make this happen in Common LISP is somewhat more of a challenge.

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