Automated Divide Calculation and block placement

Automated Divide Calculation and block placement

amoeggenborgHBYL6
Explorer Explorer
1,058 Views
18 Replies
Message 1 of 19

Automated Divide Calculation and block placement

amoeggenborgHBYL6
Explorer
Explorer

We are trying to program an autolisp to streamline the following sequence of placing blocks on lines using the divide tool. 

  1. Start Divide command
  2. User Input => Select Line

            -Pull the length of the line from the properties tab.

            -Divide the length given in the properties tab by 20ft to determine ‘X’, if the line does not evenly divide, round up to the nearest whole number (ex: 44ft divided by 20 = 2.2, we want to round up to 3) This formula in excel was 'Ceiling'. The goal is to have the blocks both evenly spaced and less than or equal to 20ft apart. 

  1. Enter the number of segments or block =>Block
  2. Enter the name of the block to insert=>SAMPLE
  3. Align block with object? =>No
  4. Enter the number of segments =>’X’
  5. Press Enter

Our end goal would be: 

Start our 'New Divide Tool' and select the line to place the blocks automatically. 

 

0 Likes
Accepted solutions (1)
1,059 Views
18 Replies
Replies (18)
Message 2 of 19

dbroad
Mentor
Mentor

No lisp is required.  Use the block option of the divide command. Same for measure command.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 19

amoeggenborgHBYL6
Explorer
Explorer

This link is a video that goes into a bit more detail about what we are attempting to program. 

https://watch.screencastify.com/v/KsEepR2nGMG25Pq0T98b

0 Likes
Message 4 of 19

Kent1Cooper
Consultant
Consultant

DivdeMeasurePlus.lsp, [newer version] >here<, has a DIV+ command in it that was designed specifically to do this, as well as other enhancements over regular DIVIDE.  Read about the differences at the link and in the top of the file.  You want the Maximum-spacing option.  When it asks for a Rotation, specify 0 [if you don't want it Aligned-with-the-path, it can be any constant angle you want, not just 0 as in DIVIDE, which is why it asks differently than DIVIDE does].

EDIT:  Found a more recent version [link updated].

Kent Cooper, AIA
0 Likes
Message 5 of 19

ВeekeeCZ
Consultant
Consultant

You can select multiple lines. Dist of 20 is hardcoded, block name is not. But could be.

 

(vl-load-com)

(defun c:div20 ( / s b e i l)

  (if (and (setq s (ssget '((0 . "LINE,ARC,LWPOLYLINE"))))
	   (setq b (getstring T "\nBlock name: ")))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
      (command  "_.divide" e "_b" b "_n" (1+ (fix (/ l 20))))))
  (princ)
  )

 

0 Likes
Message 6 of 19

amoeggenborgHBYL6
Explorer
Explorer

This seems to do the trick but could you show me how to hard code the block title in the code? 

0 Likes
Message 7 of 19

ВeekeeCZ
Consultant
Consultant
Accepted solution
(vl-load-com)

(defun c:div20 ( / s b e i l)

  (if (and (or (tblsearch "BLOCK" "perimeter point")
	       (prompt "Error: 'perimeter point' block not found in the drawing!"))
	   (setq s (ssget '((0 . "LINE,ARC,LWPOLYLINE")))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
      (command  "_.divide" e "_b" "perimeter point" "_n" (1+ (fix (/ l 20))))))
  (princ)
  )
0 Likes
Message 8 of 19

amoeggenborgHBYL6
Explorer
Explorer

This is great, thank you for all your help. The only other question we would have would be if this would even be possible to turn into a macro for an LT user but that is not a huge priority. 

0 Likes
Message 9 of 19

ВeekeeCZ
Consultant
Consultant

Get LT 2024 and your issue is solved as is. 

 

It might be limitedly convertible to a macro, but I'm not going to play with that.


0 Likes
Message 10 of 19

pendean
Community Legend
Community Legend
@ВeekeeCZ Your LISP in Message#7 works great as is in the new LT2024 in a quick test here.
Message 11 of 19

Kent1Cooper
Consultant
Consultant

@amoeggenborgHBYL6 wrote:

.... could you show me how to hard code the block title in the code? 


DIV+ in DivideMeasurePlus.lsp [Message 4, with link updated for a more recent version] could have a Block name hard-coded, but even without alteration it at least remembers a Block name that you give it [unlike regular DIVIDE], and offers it as default on subsequent use.  [It also works on Circles, Splines, and Ellipses, as well as the Lines/Arcs/Polylines of other offerings.]  [It also has the option, if it's of use to you, to include putting them at the ends of the path object, which DIVIDE won't do.]

Kent Cooper, AIA
0 Likes
Message 12 of 19

john.uhden
Mentor
Mentor

@dbroad ,

I mostly agree but without listing the length of the polyline and breaking out his calculator, he wouldn't know if he had the min/max number of insertions.

I've gotta see what @ВeekeeCZ supplied.

John F. Uhden

0 Likes
Message 13 of 19

Sea-Haven
Mentor
Mentor

If you have more than 1 block can make a dcl that displays block names then select from that, either a Listbox or a Radio button DCL.

Message 14 of 19

john.uhden
Mentor
Mentor

@pendean ,

Are you saying that they unleashed AutoLisp for LT?!

But no Visual Lisp, right?

We'll likely get swamped by the previously under privileged, but I can break out my '90s stuff with functions like @perp and dealing with polylines.

John F. Uhden

0 Likes
Message 15 of 19

tanbqtb03
Contributor
Contributor

Would you to update method from operation lisp: type name block => Select block on screen autocad command? Thanks

0 Likes
Message 16 of 19

ВeekeeCZ
Consultant
Consultant

Sure. 

 

(vl-load-com)

(defun c:div20 ( / s b e i l)

  (if (and (setq s (ssget '((0 . "LINE,ARC,LWPOLYLINE"))))
	   (setq b (getpropertyvalue (car (entsel "\nSelect block: ")) "BlockTableRecord/Name"))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
      (command  "_.divide" e "_b" b "_n" (1+ (fix (/ l 20))))))
  (princ)
  )
0 Likes
Message 17 of 19

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:
....
(command "_.divide" e "_b" b "_n" (1+ (fix (/ l 20)))))) ....

I would suggest a check on whether the length divides exactly by [in this case] 20, and if so, don't add 1 to the quantity.  [My DIV+ command at the link in Message 4 does this.]  If the length is exactly [for example] 40, a single Block in the middle will divide it into two segments without exceeding the 20-unit limit, but the code above will divide it into three segments, shorter than necessary, and insert two Blocks.

Kent Cooper, AIA
Message 18 of 19

pendean
Community Legend
Community Legend
@john.uhden Indeed, all of my legacy LISP seem intact and working quite well.

Here is a live link to HELP on LT2024 on the topic of LISP, it goes deeper into the new offering and current limits https://help.autodesk.com/view/ACDLT/2024/ENU/?guid=GUID-037BF4D4-755E-4A5C-8136-80E85CCEDF3E
0 Likes
Message 19 of 19

tanbqtb03
Contributor
Contributor

Thanks bro

0 Likes