Jump to content

Recommended Posts

Posted

I need a lisp which will draw a series of polyline in between two bounding polyline. The series of polyline will be perpendicular with two bounding polyline. Please view the image.

 

Drawing1-Model.jpg

Posted

Here is a sample code to draw lines between

;; written by Fatty T.O.H. ()2005 * all rights removed
;; edited 5/14/12
;; draw perpendicular lines
;;load ActiveX library
(vl-load-com)
;;local defuns

;;//
(defun start (curve)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 (vlax-curve-getstartpoint curve
   )
 )
)
   )
 )
 )
;;//
(defun end (curve)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 (vlax-curve-getendpoint curve
   )
 )
)
   )
 )
 )
;;//
(defun pointoncurve (curve pt)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 pt
   )
 )
)
   )
 )
;;//
(defun paramatpoint (curve pt)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getparamatpoint curve
 pt
   )
 )
)
   )
 )
;;//
(defun distatpt (curve pt)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getdistatpoint curve
   (vlax-curve-getclosestpointto curve pt)
   )
 )
   )
   )
 )
;;//
(defun pointatdist (curve dist)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 (vlax-curve-getpointatdist curve dist)
   )
 )
)
   )
 )
;;//
(defun curvelength (curve)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getdistatparam curve
 (- (vlax-curve-getendparam curve)
    (vlax-curve-getstartparam curve)
   )
 )
 )
)
   )
 )
;;//
(defun distatparam (curve param)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getdistatparam curve
 param
 )
 )
   )
   )
 )
;;// written by VovKa (Vladimir Kleshev)
(defun gettangent (curve pt)

 (setq param (paramatpoint curve pt)
       ang ((lambda (deriv)
    (if (zerop (cadr deriv))
      (/ pi 2)
      (atan (apply '/ deriv))
    )
  )
   (cdr (reverse
   (vlax-curve-getfirstderiv curve param)
        )
   )
 )
)
 ang
 )
;;// main program
;;--------------------------------------------------;;
(defun c:DIP (/ *error* acsp adoc cnt div en en2 ent ent2 ip lastp leng ln lnum mul num pt rot sign start step)

 (defun *error* (msg)
     (vla-endundomark (vla-get-activedocument
             (vlax-get-acad-object))
      )
   (cond ((or (not msg)
       (member msg '("console break" "Function cancelled" "quit / exit abort"))
       )
   )
  ((princ (strcat "\nError: " msg)))
  )

   (princ)
   )

 (setq adoc (vla-get-activedocument (vlax-get-acad-object))
   acsp (vla-get-block (vla-get-activelayout adoc))
    )



(while (not
  (and
    (or
      (initget 6)
      (setq step (getreal "\nEnter step <25>: "))
      (if (not step)
 (setq step 25.)))
    ))
  (alert "\nEnter a step")
  )

(if (and
 (setq
   ent (entsel
  "\nSelect curve near to the start point >>"
  )
   )
(setq
   ent2 (entsel
  "\nSelect other curve  >>"
  )
   )
 )
  (progn
    (setq en (car ent)
   pt (pointoncurve en (cadr ent))
   leng (distatparam en (vlax-curve-getendparam en))
   en2 (car ent2)
   )
    (setq num (fix (/ leng step))
   )
    (setq div (fix (/ 100. step)
     )
   )
    (setq mul (- leng
   (* (setq lnum (fix (/ leng (* step div)))) (* step div))))
    (if (not (zerop mul))
      (setq lastp T)
      (setq lastp nil)
      )
    (if (> (- (paramatpoint en pt)
       (paramatpoint en (vlax-curve-getstartpoint en))
       )
    (- (paramatpoint en (vlax-curve-getendpoint en))
       (paramatpoint en pt)
       )
    )
      (progn
 (setq start leng
       sign  -1
       )
 )
      (progn
 (setq start (distatparam en (vlax-curve-getstartparam en))
       sign  1
       )
 )
      )

    (vla-startundomark
      (vla-get-activedocument (vlax-get-acad-object))
      )
    (setq cnt 0)
    (repeat (1+ num)
      (setq pt  (pointatdist en start)
     rot (gettangent en pt)
     )

(setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))
      (setq cnt   (1+ cnt)
     start (+ start (* sign step))
     )
      )

    (if lastp
      (progn
 (if (= sign -1)
   (progn
     (setq pt  (vlax-curve-getstartpoint en)
    rot (gettangent en pt)
    )
     )
   (progn
     (setq pt  (vlax-curve-getendpoint en)
    rot (gettangent en pt)
    )
     )
   )
(setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))

 )
      )

    )
  (princ "\nNothing selected")
  )
 (*error* nil)
(princ)
)
(prompt "\n   >>>   Type DIP to execute...")
(prin1)

 

~'J'~

Posted

The series of lines between the Polylines can only be perpendicular to one of the Polylines, unless the Polylines are parallel.

Posted

Nice code Fatty ! ! I learn so much reading your codes ! !

Steve

Posted

You could also make a rulesurf between the 2 plines and then extract the point values. -David

Posted
Here is a sample code to draw lines between

;; written by Fatty T.O.H. ()2005 * all rights removed
;; edited 5/14/12
;; draw perpendicular lines
;;load ActiveX library
(vl-load-com)
;;local defuns

;;//
(defun start (curve)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 (vlax-curve-getstartpoint curve
   )
 )
)
   )
 )
 )
;;//
(defun end (curve)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 (vlax-curve-getendpoint curve
   )
 )
)
   )
 )
 )
;;//
(defun pointoncurve (curve pt)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 pt
   )
 )
)
   )
 )
;;//
(defun paramatpoint (curve pt)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getparamatpoint curve
 pt
   )
 )
)
   )
 )
;;//
(defun distatpt (curve pt)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getdistatpoint curve
   (vlax-curve-getclosestpointto curve pt)
   )
 )
   )
   )
 )
;;//
(defun pointatdist (curve dist)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getclosestpointto curve
 (vlax-curve-getpointatdist curve dist)
   )
 )
)
   )
 )
;;//
(defun curvelength (curve)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getdistatparam curve
 (- (vlax-curve-getendparam curve)
    (vlax-curve-getstartparam curve)
   )
 )
 )
)
   )
 )
;;//
(defun distatparam (curve param)
 (vl-catch-all-apply (function (lambda()
 (vlax-curve-getdistatparam curve
 param
 )
 )
   )
   )
 )
;;// written by VovKa (Vladimir Kleshev)
(defun gettangent (curve pt)

 (setq param (paramatpoint curve pt)
       ang ((lambda (deriv)
    (if (zerop (cadr deriv))
      (/ pi 2)
      (atan (apply '/ deriv))
    )
  )
   (cdr (reverse
   (vlax-curve-getfirstderiv curve param)
        )
   )
 )
)
 ang
 )
;;// main program
;;--------------------------------------------------;;
(defun c:DIP (/ *error* acsp adoc cnt div en en2 ent ent2 ip lastp leng ln lnum mul num pt rot sign start step)

 (defun *error* (msg)
     (vla-endundomark (vla-get-activedocument
             (vlax-get-acad-object))
      )
   (cond ((or (not msg)
       (member msg '("console break" "Function cancelled" "quit / exit abort"))
       )
   )
  ((princ (strcat "\nError: " msg)))
  )

   (princ)
   )

 (setq adoc (vla-get-activedocument (vlax-get-acad-object))
   acsp (vla-get-block (vla-get-activelayout adoc))
    )



(while (not
  (and
    (or
      (initget 6)
      (setq step (getreal "\nEnter step <25>: "))
      (if (not step)
 (setq step 25.)))
    ))
  (alert "\nEnter a step")
  )

(if (and
 (setq
   ent (entsel
  "\nSelect curve near to the start point >>"
  )
   )
(setq
   ent2 (entsel
  "\nSelect other curve  >>"
  )
   )
 )
  (progn
    (setq en (car ent)
   pt (pointoncurve en (cadr ent))
   leng (distatparam en (vlax-curve-getendparam en))
   en2 (car ent2)
   )
    (setq num (fix (/ leng step))
   )
    (setq div (fix (/ 100. step)
     )
   )
    (setq mul (- leng
   (* (setq lnum (fix (/ leng (* step div)))) (* step div))))
    (if (not (zerop mul))
      (setq lastp T)
      (setq lastp nil)
      )
    (if (> (- (paramatpoint en pt)
       (paramatpoint en (vlax-curve-getstartpoint en))
       )
    (- (paramatpoint en (vlax-curve-getendpoint en))
       (paramatpoint en pt)
       )
    )
      (progn
 (setq start leng
       sign  -1
       )
 )
      (progn
 (setq start (distatparam en (vlax-curve-getstartparam en))
       sign  1
       )
 )
      )

    (vla-startundomark
      (vla-get-activedocument (vlax-get-acad-object))
      )
    (setq cnt 0)
    (repeat (1+ num)
      (setq pt  (pointatdist en start)
     rot (gettangent en pt)
     )

(setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))
      (setq cnt   (1+ cnt)
     start (+ start (* sign step))
     )
      )

    (if lastp
      (progn
 (if (= sign -1)
   (progn
     (setq pt  (vlax-curve-getstartpoint en)
    rot (gettangent en pt)
    )
     )
   (progn
     (setq pt  (vlax-curve-getendpoint en)
    rot (gettangent en pt)
    )
     )
   )
(setq ln (vlax-invoke-method acsp 'addline (setq ip (vlax-3d-point pt))(vlax-3d-point(pointoncurve en2 pt))))

 )
      )

    )
  (princ "\nNothing selected")
  )
 (*error* nil)
(princ)
)
(prompt "\n   >>>   Type DIP to execute...")
(prin1)

 

~'J'~

 

 

Thanks fixo for the nice code. Thank you.

Posted

Glad you got it to working,

Cheers :)

 

~'J'~

Posted

Thanks Steve,

Glad I could help,

Regards,

 

~'J'~

  • 1 year later...

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