Array along a path

Array along a path

mperez
Contributor Contributor
4,122 Views
12 Replies
Message 1 of 13

Array along a path

mperez
Contributor
Contributor

Looking for some help. I've been trying to write a lisp, with very limited knowledge, to array a block along  a path. My issue is that the path angle is always different and i need to be able to control the spacing between blocks. I've tried using Polar Array and it seems to do what i want, but I cant control the spacing between blocks as it always varies. I've tried the Div/Mea command but it wont take the path angle into account when measuring the distance between objects. The below image shows the spacing should have been 15'.

 

Any help is appreciated.

Using Autocad 2018

 

Thanks,

Mike

Capture.JPG

0 Likes
Accepted solutions (1)
4,123 Views
12 Replies
Replies (12)
Message 2 of 13

dbhunia
Advisor
Advisor

check this........

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-create-arraypath-from-a-sele...


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 13

marko_ribar
Advisor
Advisor

You can calculate correct distance between objects for measure command by using trigonometric functions sin and cos...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 4 of 13

mperez
Contributor
Contributor

Thanks Mark. I know how to calculate the true distance, I need a lisp routine to do it for me while I specify the distance and select the path.

0 Likes
Message 5 of 13

mperez
Contributor
Contributor

hmm doesnt seem to be working for me. This what happens when i run the lspCapture.JPG

0 Likes
Message 6 of 13

dbhunia
Advisor
Advisor

Hi

 

As your requirements.......

 


@mperez wrote:

Looking for some help. I've been trying to write a lisp, with very limited knowledge, to array a block along  a path. My issue is that the path angle is always different and i need to be able to control the spacing between blocks. I've tried using Polar Array and it seems to do what i want, but I cant control the spacing between blocks as it always varies. I've tried the Div/Mea command but it wont take the path angle into account when measuring the distance between objects. The below image shows the spacing should have been 15'.

..................

 

Try this...........(By this code you can control "Path Angle" and "Horizontal Distance" only not "Vertical Distance")

 

(defun c:arh (/ ent p1 p2 ang num dst dst1)
(setq echo (getvar 'cmdecho)
      osm (getvar 'osmode)
      snp (getvar 'snapang)
)
(setvar 'cmdecho 0)
(while (= (setq ent (car(entsel "\nSelect Object for Array: "))) nil))
(setq p1 (getpoint "\nSpecify First Point of Line/Path (To get Angle and Direction): ")
      p2 (getpoint p1 "\nSpecify End Point of Line/Path (To get Angle and Direction): ")
      dst  (getdist "\nSpecify Offset Distance (Horizontal) Between Objects: ")
      num (getint "\nSpecify Number of Array Iteams: ")
      ang (angle p1 p2)
      dst1 (/ dst (cos ang))
)
(if (< (/ pi 2) ang (* pi 1.5))
    (setq dst1 (* -1 (/ dst (cos ang))))
)
(setvar 'osmode 0)
(setvar 'snapang ang)
(command "_.array" ent "" "R" "1" num dst1)
(setvar 'osmode osm)
(setvar 'snapang snp)
(setvar 'cmdecho echo)
(princ)
)

 

Tested in AutoCAD 2007......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 7 of 13

mperez
Contributor
Contributor

Sorry but this does not work. It looks to do a rectangular array and not along a path. The blocks can't be rotated to align to the path.

0 Likes
Message 8 of 13

dbhunia
Advisor
Advisor

Try this....... (or post a sample drawing with explanation.....)

 

(defun c:ARP (/ ANG CUR_LAY DIST1 ENDPT INSPT LEN PATH PICKPT SEL STARTPT)
  (vl-load-com)
  (if (and (setq ent (car(entsel "\nSelect Object to Array: ")))
	   (setq dist1 (getdist "\nEnter Distance Between Objects: "))
           (setq sel (entsel "\nSelect Array Path: "))
      )
    (progn
      (setvar "CMDECHO" 0)
      (setq pickpt  (cadr sel)
	    path    (car sel)
	    len	    (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path))
	    startpt (vlax-curve-getStartPoint path)
	    endpt   (vlax-curve-getEndPoint path)
      )
      (if (< (distance startpt pickpt) (distance endpt pickpt))
	(setq inspt startpt
	      ang   (* (/ (angle inspt (vlax-curve-getPointAtDist path 0.001)) pi) 180))
	(setq inspt endpt
	      ang   (* (/ (angle (vlax-curve-getPointAtDist path (- len 0.001)) inspt) pi 180)))
      ) 
      (command "._arraypath" ent "" (osnap pickpt "NEA")  "" "" "" "F" dist1 "" "")
    )
  )
(setvar "CMDECHO" 1)
(princ)
)

Modification of the post.......

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-create-arraypath-from-a-sele...


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 13

mperez
Contributor
Contributor

Capture.JPGCapture1.JPG 

Sorry still doesnt work. It uses the default space between objects. I've been playing around with the lisp but cant get it to work properly.

0 Likes
Message 10 of 13

mperez
Contributor
Contributor

Capture.JPGI've made a modification to the lisp but the calculation for the spacing is not correct. If I chose 15 the true distance 14.7403 because of the angle. Not sure how to correct it in the lisp. 

(defun c:ARP (/ ANG CUR_LAY DIST1 ENDPT INSPT LEN PATH PICKPT SEL STARTPT)
(vl-load-com)
(if (and (setq ent (car(entsel "\nSelect Object to Array: ")))
(setq dist1 (getdist "\nEnter Distance Between Objects: "))
(setq sel (entsel "\nSelect Array Path: "))
)
(progn
(setvar "CMDECHO" 0)
(setq pickpt (cadr sel)
path (car sel)
len (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path))
startpt (vlax-curve-getStartPoint path)
endpt (vlax-curve-getEndPoint path)
)
(if (< (distance startpt pickpt) (distance endpt pickpt))
(setq inspt startpt
ang (* (/ (angle inspt (vlax-curve-getPointAtDist path 0.001)) pi) 180))
(setq inspt endpt
ang (* (/ (angle (vlax-curve-getPointAtDist path (- len 0.001)) inspt) pi 180)))
)
(command "._arraypath" ent "" sel "I" dist1 "F" "" "")
)
)
(setvar "CMDECHO" 1)
(princ)
)

0 Likes
Message 11 of 13

Kent1Cooper
Consultant
Consultant

@mperez wrote:

…. calculation for the spacing is not correct. If I chose 15 the true distance 14.7403 because of the angle. .... 

....
(if (< (distance startpt pickpt) (distance endpt pickpt))
(setq inspt startpt
ang (* (/ (angle inspt (vlax-curve-getPointAtDist path 0.001)) pi) 180))
(setq inspt endpt
ang (* (/ (angle (vlax-curve-getPointAtDist path (- len 0.001)) inspt) pi 180)))
)
(command "._arraypath" ent "" sel "I" dist1 "F" "" "")

….


 

There's no point I can see in converting the angle to degrees [not to mention that your code doesn't even use  the 'ang' variable].  You need it in radians to get its cosine to figure the hypotenuse distance.  And since you want the spacing to be positive in any case, you need the absolute value  of that, whether the cosine is positive or negative, which means [for a straight-line path] you can figure the angle one way regardless of which is the 'inspt' end [another variable that is not used ].  Also, I think you have an extra Enter at the end.  Try just this in place of all the quoted portion above [untested]:

 

....
 (command "._arraypath" ent "" sel "I" (/ dist1 (abs (cos (angle startpt endpt)))) "F" "")

….

 

 

Kent Cooper, AIA
0 Likes
Message 12 of 13

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

First thing .......

 

How far I know it is not possible to control the Horizontal/Vertical distance using "ARRAYPATH" command by selecting a path (Except LINE).....

 

What @Kent1Cooper advised that is

....
 (command "._arraypath" ent "" sel "I" (/ dist1 (abs (cos (angle startpt endpt)))) "F" "")
….

true only for a LINE or a PLINE with 2 vertices (path).... (and also I followed that process in my second post.....). Because this gives the angle by considering only START/END point of any CURVE...... for PLINE more than 2 vertices every segment has its own angle....for SPLINE you have to calculate through every TANGENT point.............

 

 

Second Thing ........

 

In your post each attached image shows only a Rectangular Array along a Line....so there is no array object with rotation.......

 

If that is your requirement then try this for LINE/PLINE with 2 vertices only.....(To control "Horizontal Distance" only not "Vertical Distance")

 

(defun C:ARP (/);;Put Variables......
(vl-load-com)
(princ "\nSelect Objects for Array: ")
(setq ent (ssget))
(setq ent_sel (entget (car (setq sel (entsel "\nSelect Array Path (Line or Pline with 2 vertices): ")))))
(if (or (= (cdr (assoc 0 ent_sel)) "LINE") (= (cdr (assoc 0 ent_sel)) "LWPOLYLINE"))
	(progn
		(if (and (= (cdr (assoc 0 ent_sel)) "LWPOLYLINE") (> (cdr (assoc 90 ent_sel)) 2))
			(princ "\nSelected Array Path has more than 2 vertices")
			(progn
				(setq dst (getdist "\nEnter Distance Between Objects: "))
				(setvar "CMDECHO" 0)
				(setq pickpt (cadr sel)
				    path (car sel)
				    startpt (vlax-curve-getStartPoint path)
				    endpt (vlax-curve-getEndPoint path)
				    dst2 (/ dst (abs (cos (angle startpt endpt))))
				)
				(command "._arraypath" ent "" (osnap pickpt "NEA") "" "" "" "F" dst2 "" "");;Use this or
				;(command "._arraypath" ent "" (osnap pickpt "NEA") "" "" "" "F" dst2 "");this
				;;The above two line controls the direction & Start point of the array by considerring selection point of path
				;(command "._arraypath" ent "" sel "" "" "" "F" dst2 "");;You can use this also or
				;(command "._arraypath" ent "" sel "" "" "" "F" dst2 "" "");this
				(setvar "CMDECHO" 1)
			)
		)
	)
	(princ "\nSelect Line or Pline with 2 vertices only for Array Path")
)
(princ)
)

 

Lightly tested in AutoCAD 2018......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 13 of 13

mperez
Contributor
Contributor

I can't Thank you enough. Worked perfectSmiley Very Happy

 

Cheers!

0 Likes