I tried to make my subject as descriptive and specific as possible. Basically, in a drawing I will have a polyline. I have created the LISP routine (code below, .lsp file attached) that will insert a specific block on that polyline, then create an Arraypath from that block along the polyline.
(defun c:CONELINE2 (/ dist1 cur_lay obj) (setvar "CMDECHO" 0) ;remember current layer and set the current layer to CONE (setq cur_lay (getvar "clayer")) (setvar "clayer" "CONE") ;insert the cone-p block (command "._insert" "cone-p" (getpoint) "1" "1" (getpoint)) ;user-input for cone spacing (setq dist1 (getdist "\nEnter Distance: ")) ;create arraypath with cone and polyline (command "._arraypath" (entsel) "" (entsel) "" "" "" "F" dist1 "" "") ;revert layer back to original current layer (setvar "clayer" cur_lay) )
It works, but my issue is this... I have to first pick the point of the block insertion, and then define the rotation of the block. Then I have to select the block and the polyline and enter the cone spacing. It is a lot of steps which I think could be done with fewer user inputs. What I would love is to be able to select the polyline and then enter the cone spacing distance (the dist1 variable), then the LISP routine does the rest, place the first block at the beginning of the polyline, aligned with the polyline, and then create the arraypath using the already selected polyline and the block without any further user-input. I've inserted a drawing with a polyline and the proper block (cone-p), and I've also attached the current LISP file. I would appreciate any help that anyone could give. This should be a fairly easy task, but I'm stumped. I can't even get the arraypath command to use the last placed object instead of having to select the block manually.
Thank you
Chad Martinell
Senior Transportation Engineer/CAD Manager
Transportation & Energy Solutions, Inc.
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Something like this perhaps.
Fully untested, I don't have AutoCAD in this laptop...
(defun c:CONELINE2 (/ ANG CUR_LAY DIST1 ENDPT INSPT LEN PATH PICKPT SEL STARTPT) (vl-load-com) ;; user-input select path and for cone spacing (if (and (setq sel (entsel "\nSelect a LwPolyline to Insert Cones: ")) (setq dist1 (getdist "\nEnter the Distance Between Cones: ")) );; and ;; if the test expressions are true ;; start the insertion process, ;; if not, exits the code... (progn (setvar "CMDECHO" 0) ;remember current layer and set the current layer to CONE (setq cur_lay (getvar "clayer")) (setvar "clayer" "CONE") ;; sets the variable pickpt with the second list element from the entsel function (setq pickpt (cadr sel) ;; sets the variable path with the first list element from the entsel function path (car sel) ;; find the polyline length len (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path)) ;; find the strat point startpt (vlax-curve-getStartPoint path) ;; find the end point endpt (vlax-curve-getEndPoint path) );; setq ;; test if the pick point is closer from the start (if (< (distance startpt pickpt) (distance endpt pickpt)) ;; if close to start, stores the startpt as inspt and the insertion angle (setq inspt startpt ang (* (/ (angle inspt (vlax-curve-getPointAtDist path 0.001)) pi) 180)) ;; if close to end, stores the endpt as inspt and the insertion angle (setq inspt endpt ang (* (/ (angle (vlax-curve-getPointAtDist path (- len 0.001)) inspt) pi 180)) );; if ;insert the cone-p block (command "._insert" "cone-p" "_none" inspt "1" "1" "_none" ang) ;create arraypath with cone and polyline (command "._arraypath" (entlast) "" path "" "" "" "F" dist1 "" "") ;revert layer back to original current layer (setvar "clayer" cur_lay) );; progn );; if (princ) );; CONELINE2
HTH
Henrique
@hmsilva wrote:Something like this perhaps.
Fully untested, I don't have AutoCAD in this laptop...
(defun c:CONELINE2 (/ ANG CUR_LAY DIST1 ENDPT INSPT LEN PATH PICKPT SEL STARTPT) (vl-load-com) ;; user-input select path and for cone spacing (if (and (setq sel (entsel "\nSelect a LwPolyline to Insert Cones: ")) (setq dist1 (getdist "\nEnter the Distance Between Cones: ")) );; and ;; if the test expressions are true ;; start the insertion process, ;; if not, exits the code... (progn (setvar "CMDECHO" 0) ;remember current layer and set the current layer to CONE (setq cur_lay (getvar "clayer")) (setvar "clayer" "CONE") ;; sets the variable pickpt with the second list element from the entsel function (setq pickpt (cadr sel) ;; sets the variable path with the first list element from the entsel function path (car sel) ;; find the polyline length len (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path)) ;; find the strat point startpt (vlax-curve-getStartPoint path) ;; find the end point endpt (vlax-curve-getEndPoint path) );; setq ;; test if the pick point is closer from the start (if (< (distance startpt pickpt) (distance endpt pickpt)) ;; if close to start, stores the startpt as inspt and the insertion angle (setq inspt startpt ang (* (/ (angle inspt (vlax-curve-getPointAtDist path 0.001)) pi) 180)) ;; if close to end, stores the endpt as inspt and the insertion angle (setq inspt endpt ang (* (/ (angle (vlax-curve-getPointAtDist path (- len 0.001)) inspt) pi 180)) );; if ;insert the cone-p block (command "._insert" "cone-p" "_none" inspt "1" "1" "_none" ang) ;create arraypath with cone and polyline (command "._arraypath" (entlast) "" path "" "" "" "F" dist1 "" "") ;revert layer back to original current layer (setvar "clayer" cur_lay) );; progn );; if (princ) );; CONELINE2
HTH
Henrique
Thanks for the quick response. For some reason it won't run in my file though. I open a new file, select Load Application, browse to the lisp file that you attached, and it says that it loaded successfully. Then I type CONELINE2 and it says that it doesn't recognize the command. Any thoughts on what I'm doing wrong?