Arraypath LISP to place block every X feet

Arraypath LISP to place block every X feet

Anonymous
Not applicable
1,918 Views
3 Replies
Message 1 of 4

Arraypath LISP to place block every X feet

Anonymous
Not applicable

I'm trying to automate the ARRAYPATH command.  I already have the object to array inserted at the start point of the polyline.  I have the polyline I want to use as my path.  My code has a prompt to ask the user how often to place the block (X feet).  I want the object to be arrayed along the path every X feet.  I also want the array to "fill" the polyline, so it's still close to X feet but not exactly.

 

Here is how I do this manually and it works fine:

Command: ARRAYPATH
Select objects: 1 found
Type = Path  Associative = Yes
Select path curve:
Select grip to edit array or [ASsociative/Method/Base point/Tangent direction/Items/Rows/Levels/Align items/Z direction/eXit]<eXit>: i
Specify the distance between items along path or [Expression] <0.6342>: 8
Maximum items = 32
Specify number of items or [Fill entire path/Expression] <32>:
Select grip to edit array or [ASsociative/Method/Base point/Tangent direction/Items/Rows/Levels/Align items/Z direction/eXit]<eXit>: M
Enter path method [Divide/Measure] <Measure>: D
Select grip to edit array or [ASsociative/Method/Base point/Tangent direction/Items/Rows/Levels/Align items/Z direction/eXit]<eXit>: X

 

I'm trying to get the below code to work but it doesn't:

(defun c:arp (/ sel path dist1 pickpt) ;Arraypath for JFK barrier wall
	
	(if (and (setq sel (entsel "\nSelect object to array:"))
		(setq path (entsel "\nSelect path:"))
		(setq dist1 (getdist "\nEnter the Distance Between Objects:")))
		;then
		(progn
		
		;; sets the variable pickpt with the second list element from the entsel function
		(setq pickpt (cadr path))
		(command "._arraypath" sel "" (osnap pickpt "NEA") "I" dist1 "F" "M" "D" "X" );...
		)
	)
	(princ))

 

Here is the output in CAD:

Command: ARP
Select object to array:
Select path:
Enter the Distance Between Objects:12
._arraypath
Select objects:   1 found
Select objects:
Type = Path  Associative = Yes
Select path curve:
Enter number of items along path or [Orientation/Expression] <Orientation>: I Requires an integer between 1 an 32767, or option keyword.
Enter number of items along path or [Orientation/Expression] <Orientation>: 12
Specify the distance between items along path or [Divide/Total/Expression]: F The syntax is incorrect or a variable is not defined.  Reenter the expression or value.
Specify the distance between items along path or [Divide/Total/Expression]: M The syntax is incorrect or a variable is not defined.  Reenter the expression or value.
Specify the distance between items along path or [Divide/Total/Expression]: D
Select grip to edit array or [ASsociative/Method/Base point/Tangent direction/Items/Rows/Levels/Align items/Z direction/eXit]<eXit>: X
0 Likes
Accepted solutions (1)
1,919 Views
3 Replies
Replies (3)
Message 2 of 4

devitg
Advisor
Advisor

Hi @Anonymous , please upload your sample DWG. 

0 Likes
Message 3 of 4

Sea-Haven
Mentor
Mentor

A simpler way with plines is to use getpointatdist a Vlax-curve function you can do stuff like take length divide by spacing what is remainder say divide 1/2 that is start distance you can also get the angle at that point so objects placed can be rotated to be square off pline.

 

(setq obj (vlax-ename->vla-object (car (entsel "\nPick Pline "))))
(setvar 'pdmode 34)
(setvar 'pdsize -5)
(while (setq dist (getreal "\nenter distance"))
(setq pt (vlax-curve-getpointatdist obj dist))
(command "point" pt)
)
0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

Some AutoCAD commands behave differently in the LISP environment than in AutoCAD itself.

Usually helps to add (initcommandversion) function prior to the command to which should be applied. As in this case. Also made some minor adjustments of your code but all you really needed was to add that magic function.

 

(defun c:ARP (/ sel path dist) ;Arraypath for JFK barrier wall

  (if (and (setq sel (ssget))
	   (setq path (car (entsel "\nSelect path:")))
	   (setq dist (cond ((getdist "\nEnter the Distance Between Objects <8 ft>: "))
			    (8.)))
	   (initcommandversion)
	   )
    (command "._arraypath" sel "" path "I" dist "F" "M" "D" "X" ))
  (princ)
  )

 

Here is one trick I use to confirm a different Autocad vs LISP behavior. From the command-line run this LISP function (command-s "arraypath") Command-s, unlike regular command, stays within the LISP environment all time until the user finishes the command. That way you can walk thru the LISP version of the command manually step by step and see, what's different. 

0 Likes