AutoLISP Script for Inserting Dynamic Blocks Between Perpendicular Lines Based on CSV Input

AutoLISP Script for Inserting Dynamic Blocks Between Perpendicular Lines Based on CSV Input

_Matheus_
Contributor Contributor
341 Views
7 Replies
Message 1 of 8

AutoLISP Script for Inserting Dynamic Blocks Between Perpendicular Lines Based on CSV Input

_Matheus_
Contributor
Contributor

Hello everyone,

I am developing an AutoLISP script designed to generate perpendicular construction lines along a reference curve (which may be a line, polyline, or spline), based on distance values imported from a CSV file. The CSV parsing and initial vertex marking functions are fully implemented and operational.

The next step is to extend the script to insert dynamic blocks between these perpendicular lines, supporting two distinct insertion strategies:

🔹 Type 1 – Single dynamic block with action parameters anchored at segment boundaries

In this mode, a single dynamic block is placed between two consecutive perpendicular lines. The block’s action parameters (e.g., grips or control points) must precisely coincide with the intersection points defining the start and end of the segment, ensuring accurate parametric control and alignment.

Example block name: "Block_With_Grips".

🔹 Type 2 – Multiple repeated dynamic blocks distributed uniformly along the segment

In this case, the script inserts the maximum number of identical dynamic blocks possible between two consecutive perpendicular lines, provided that each block maintains a minimum spacing of 4.5 meters.

The segment length is evenly divided among these blocks, guaranteeing equal spacing without residual gaps.

For example, for a 13-meter segment, two blocks would be inserted at intervals of 6.5 meters.

Each repeated block contains a centered grip (action parameter), which must be properly aligned to the block’s midpoint for user manipulation and parameter adjustment.

Sample CSV snippet:

          10.5,Block_single
          23.2,Block_Repeated
          45.0,Block_Repeated

Hence, the script inserts a "Block_With_Grips" between the 10.5 m and 23.2 m marks, and subsequently replicates the "Block_Repeated" blocks along the following segments according to the calculated spacing.

Currently, I am implementing the CSV second-column parsing logic and developing the algorithm for block insertion, including calculation of insertion points, block rotation to align with the perpendicular lines, and precise positioning of action parameters to ensure dynamic behavior within AutoCAD’s block framework.

I welcome any suggestions or best practices regarding the efficient management of block placement

Thank you in advance for your insights!

Attachments:

corruent .LSP

DWG with the blocks (Far left is the one that has to repeat and can’t be less than 4.5 m spacing, middle is the one that goes only once per segment, and far right is another that has to repeat but can’t be less than 2.25 m spacing)

0 Likes
Accepted solutions (1)
342 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

Post some DWG illustrating the desired outcome. Also post a respective csv file.

0 Likes
Message 3 of 8

_Matheus_
Contributor
Contributor

the lisp i use today is just with the distances, i want to implement the names of the parking spaces

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

Post an example with a curve.

0 Likes
Message 5 of 8

_Matheus_
Contributor
Contributor

sorry for the lack of information provided, DWG attached;

0 Likes
Message 6 of 8

_Matheus_
Contributor
Contributor

if it's too difficult it could be like a straight line between the perpendicular lines, but like that would be amazing

0 Likes
Message 7 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

Did you write the code you posted? If I give you an example of type 1, would you be able to do type 2?

 

Here's the 1

 

(defun c:InsertParallelParkingSlot ( / e m c d i p q)

  (if (and (setq e (car (entsel "Select a polyline: ")))
	   (setq m (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
	   (setq c (fix (/ m 4.5)))
	   (setq d (/ m c))
	   (setq i 0)
	   )
    (repeat c
      (and (setq p (vlax-curve-getpointatdist e (* d i)))
	   (setq q (vlax-curve-getpointatdist e (* d (1+ i))))
	   (vl-cmdf "_.insert" "VAGA PARALELA" "_s" 1 "_r" "_non" p "_non" q "_non" p)
	   (setpropertyvalue (entlast) "AcDbDynBlockPropertyDistance1" (distance p q))
	   )
      (setq i (1+ i))))
  (princ)
  )

 

 

BUT... You know that this is ridiculous. 

eekeeCZ_0-1747928714113.png

You need to add some math around it to avoid these overlaps. I didn't.

 

0 Likes
Message 8 of 8

_Matheus_
Contributor
Contributor

actually i didn't write it, but i think i can do it yes, and yeah, that overlap is indeed ridiculous, but in what i will be using will be very rare that it is a so closed curve, so it is fine
Thanks for the help o7

 

0 Likes