souvik Posted May 14, 2012 Posted May 14, 2012 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. Quote
fixo Posted May 14, 2012 Posted May 14, 2012 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'~ Quote
Lee Mac Posted May 14, 2012 Posted May 14, 2012 The series of lines between the Polylines can only be perpendicular to one of the Polylines, unless the Polylines are parallel. Quote
stevesfr Posted May 14, 2012 Posted May 14, 2012 Nice code Fatty ! ! I learn so much reading your codes ! ! Steve Quote
David Bethel Posted May 14, 2012 Posted May 14, 2012 You could also make a rulesurf between the 2 plines and then extract the point values. -David Quote
souvik Posted May 14, 2012 Author Posted May 14, 2012 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. Quote
bienda Posted April 22, 2014 Posted April 22, 2014 fixo Please help me in topic Thank you in advance Quote
Recommended Posts
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.