Jump to content

PLACE BLOCKS ALONG POLYLINE WITH DISTANCES FROM A LIST


Wellington

Recommended Posts

Hey guys! How's going? Can anyone help me?

 

Look: i need to place a lot of blocks in an extensive polyline but the blocks need to have a specific distance from the polyline beginning - and this distance will not be equal to each block. 

So, i thought in create a list (excel or csv file) and specify each block name and distance to the lisp read the archive and place the block at correct point. Did you get it?

 

PS: remember that the blocks will not have the same interval distance.

 

This is an example for the list layout.

image.png.7c3c78c17e04a9a6a041bdeff72930ab.png

 

And the result is something like this:

image.png.238e27e6cbda8daa875970db54fb47c9.png

 

I hope you guys could understand and help me! - sorry for my english - 

Thanks!

Much love from Brazil

 

Wellington Moura

 

 

Edited by Wellington
Link to comment
Share on other sites

Its two Vlisp command to do the task

 

1st is (vlax-curve-getpointatdist obj dist)

2nd is (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj pt))

 

In the case of the 2nd its about getting the angle of the pline at a point, so you block would be inserted correctly.

 

Do you know how to write lisp ? The task is not hard. 

 

Post sample data a dwg and csv or xls.

Link to comment
Share on other sites

8 hours ago, Wellington said:

Hey guys! How's going? Can anyone help me?

 

Look: i need to place a lot of blocks in an extensive polyline but the blocks need to have a specific distance from the polyline beginning - and this distance will not be equal to each block. 

So, i thought in create a list (excel or csv file) and specify each block name and distance to the lisp read the archive and place the block at correct point. Did you get it?

 

PS: remember that the blocks will not have the same interval distance.

 

This is an example for the list layout.

image.png.7c3c78c17e04a9a6a041bdeff72930ab.png

 

And the result is something like this:

image.png.238e27e6cbda8daa875970db54fb47c9.png

 

I hope you guys could understand and help me! - sorry for my english - 

Thanks!

Much love from Brazil

 

Wellington Moura

 

 

 

The example "excel" doesn't match the example picture! How is BLOCK 2 between BLOCK1 and BLOCK3? Does BLOCK1 repeat every 100 units? Does each BLOCK repeat the said distance until the end of the polyline? This is very easy to achieve if all the rules are known. Post an example "*.csv" and an example drawing (saved as AutoCAD2010 or earlier) with the real blocks to be used, layers for the blocks etc.

Link to comment
Share on other sites

12 hours ago, dlanorh said:

 

The example "excel" doesn't match the example picture! How is BLOCK 2 between BLOCK1 and BLOCK3? Does BLOCK1 repeat every 100 units? Does each BLOCK repeat the said distance until the end of the polyline? This is very easy to achieve if all the rules are known. Post an example "*.csv" and an example drawing (saved as AutoCAD2010 or earlier) with the real blocks to be used, layers for the blocks etc.

The same block can appear a lot of time in differents distances along the polyline.

There's a example of blocks, polyline and list to use.  

EXAMPLE-CSV.csv EXAMPLE-BLOCKS.dwg

Link to comment
Share on other sites

19 hours ago, BIGAL said:

Its two Vlisp command to do the task

 

1st is (vlax-curve-getpointatdist obj dist)

2nd is (vlax-curve-getfirstderiv obj (vlax-curve-getparamatpoint obj pt))

 

In the case of the 2nd its about getting the angle of the pline at a point, so you block would be inserted correctly.

 

Do you know how to write lisp ? The task is not hard. 

 

Post sample data a dwg and csv or xls.

Sorry but i dont know how to write lisp but i got the examples here.

EXAMPLE-BLOCKS.dwg EXAMPLE-CSV.csv

Link to comment
Share on other sites

Try this a bit rough but should work note does not check which way pline is drawn. Can be added. hard coded for testing change to use findfile for the csv.

 

; Take a csv file of blk details and make in Cad
; By Alan H May 2020


; thanks to Lee-mac for the csv defun 
; www.lee-mac.com
; 44 is comma
; 59 is semicolon

(defun _csv->lst (str del / pos )
	(if (setq pos (vl-string-position del str))
		(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
		(list str)
    )
)

; program starts here hardcoded for testing
; 1st line is heading so just read

(defun c:csvblk ( / newlst x obj pt1)
(setq fname (open "D:\\acadtemp\\EXAMPLE-csv.csv" "r"))
(setq newline (read-line fname))
(while (setq newline (read-line fname))
(princ newline)
(setq newlst (cons ( _csv->lst newline (ascii ";")) newlst))
)
(close fname)
(setq obj (vlax-ename->vla-object (car (entsel "Pick pline object near start end"))))
(repeat (setq x (length newlst))
(setq pair (nth (setq x (- x 1)) newlst))
(setq pt1 (vlax-curve-getpointatdist obj (atof(cadr pair))))
(command "-insert" (car pair) pt1 1 1 0)
)
)

(c:csvblk)

 

Edited by BIGAL
Link to comment
Share on other sites

(defun c:blkdis (/ *error* acadobj activeundo adoc bl blks dir ent i ln lst msp num op pl pm ps sep)
    (defun *error* ( msg )
	(if op (close op))
	(vla-EndUndoMark adoc)
	(if (not (wcmatch (strcase msg T) "*break*,*cancel*,*exit*"))
	    (princ (strcat "Error: " msg))
	    )
	)
    (setq acadobj (vlax-get-acad-object)
	  adoc (vla-get-ActiveDocument acadobj)
	  msp (vla-get-ModelSpace adoc)
	  activeundo nil)
    (if (= 0 (logand 8 (getvar "UNDOCTL"))) (vla-StartUndoMark adoc) (setq activeundo T))

    (setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))

    (if
	(and
	    (setq dir (getfiled "Select CSV" "" "csv" 0))
	    (setq op (open dir "r"))
	    (setq pl (ssget '((0 . "LWPOLYLINE,POLYLINE,ARC,ELLIPSE,CIRCLE,SPLINE"))))
	    )
	(progn
	    (while (setq ln (read-line op))
		(setq lst (cons (JH:str->lst ln sep) lst))
		)
	    (close op)
	    (setq lst (reverse lst)
		  ps (vl-position "DISTANCE" (mapcar 'strcase (car lst)))
		  bl (vl-position "BLOCK" (mapcar 'strcase (car lst)))
		  blks (vl-remove-if-not '(lambda (x) (tblsearch "block" (car x))) (cdr lst))
		  blks (mapcar
			   '(lambda (x)
				(mapcar
				    '(lambda (y)
					 (if
					     (and
						 (null
						     (vl-catch-all-error-p
							 (setq
							     num
								(vl-catch-all-apply 'read
								    (list y)
								    )
							     )
							 )
						     )
						 (numberp num)
						 )
					     num
					     y
					     )
					 )
				    x
				    )
				)
			   blks
			   )
		  )
	    (repeat (setq i (sslength pl))
		(setq ent (ssname pl (setq i (1- i))))
		(foreach x blks
		    (if (setq pm (vlax-curve-getParamAtDist ent (nth ps x)))
			(entmake
			    (list
				'(0 . "INSERT")
				'(100 . "AcDbEntity")
				'(100 . "AcDbBlockReference")
				(cons 10 (vlax-curve-getPointAtParam ent pm))
				(cons 2 (nth bl x))
				'(41 . 1.0)
				'(42 . 1.0)
				'(43 . 1.0)
				(cons 50 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv ent pm)))
				)
			    )
			)
		    )
		)
	    )
	)
    
    (if activeundo nil (vla-EndUndoMark adoc))
    (princ)
    )

;; JH:str->lst --> Jonathan Handojo
;; Seperates a string into a list using a specified delimiter
;; str - full string to parse
;; del - string representing the delimeter

(defun JH:str->lst (str del / l rtn src)
    (setq l (1+ (strlen del)))
    (while (setq src (vl-string-search del str))
	(setq rtn (cons (substr str 1 src) rtn)
	      str (substr str (+ src l))
	      )
	)
    (reverse (cons str rtn))
    )

 

Link to comment
Share on other sites

  • 3 years later...

Thank you for your input...

I was trying to do the same thing a while ago

and copy here and copy there... Manage to compile

Same thing but with the location of a road sign

along a 3D civilian lineup . . .

 

As it is shared here, I also want to share

And above all, that they improve it:

 

 

(defun c:SENALES-LISTA (/ fl ofl s sn nb linetx dat p a fk op lado pos2 lt c_pos1 c_pos2 num entero decimal enterox1000 aa b c d e absx)
  
  (setq fl (getfiled "Select Data File *.csv: " "" "csv" 4)
        ofl (open fl "r")
        ldat ())

  (princ "Select Alignment...:")
  (setq s (ssget "_+.:E:S" '((0 . "AECC_ALIGNMENT")))
        sn (ssname s 0)
        fk (getstring "\nIngrese Escala Senalizacion (1 ... n): "))

  (while (setq linetx (read-line ofl))
    (if linetx
      (progn
        (setq dat (atof linetx))
        ;(princ "\n")
        ;(princ linetx)
        ;(princ "\n")
        ;(princ dat)

; si dat = 0.00
(if (= dat 0.00)
    (setq dat 0.0001)
)
; porque con 0.00 no funciona

        ;(princ "\n")
         (pr dat)
        ;(princ p)
        ;(princ "\n")
        ;(princ a)
        ;(princ "/-->")

        (setvar "attreq" 1)
        (setvar "attdia" 0)
        (initdia 0)

        (setq lt (strlen linetx))
        ;(princ lt)
        ;(princ "/-->")

        ;; Obtener posición de la 2coma
           (setq c_pos1 (vl-string-position (ascii ",") linetx nil t))

           ;(princ c_pos1)
           ;(princ "/-->")
           (setq c_pos2 (+ c_pos1 2))

        (setq nb (substr linetx c_pos2 999))

        ;(princ "/name_bloque-->")
        ;(princ nb)
        ;(princ "/-->")

        (setq pos2 (- (strlen (strcat (rtos dat 2 2) "")) 1))
        (setq op (substr linetx pos2 1))
        
        ;(princ pos2)
        ;(princ "/ ")  
        ;(princ op)
        ;(princ "/ ")  
        
        (if (= op "D")
            (setq lado "LADO DER")
            (setq lado "LADO IZQ")
        )

;::::::::::::::::::::::::::::::::

(setq sign (if (< dat 0) "-" "+")
        num (abs dat)
        entero (fix num)
        decimal (rtos (fix (* (- num entero) 100)) 2 0)
        enterox1000 (* (fix (/ entero 1000)) 1000)
        aa (strcat (rtos (/ enterox1000 1000.0) 2 0) "+")
        c (if (>= num 1000) (- entero enterox1000) entero)
        b (if (< c 10) "00" (if (= c 0) "00" (if (>= c 100) "" "0")))
        d "."
        e (if (< (atoi decimal) 10) (strcat "0" decimal) decimal)
  )
(setq absx (strcat aa b (itoa c) d e))

;::::::::::::::::::::::::::::::::

        (if (= op "D")
            (command "_insert" nb "_non" p fk "" (- (/ (* 1 a 180) pi) 90) absx lado nb)
            (command "_insert" nb "_non" p fk "" (+ (/ (* 1 a 180) pi) 90) absx lado nb)
        )
      )
    )
  )

  (close ofl)
  (princ)
)

(defun pr (dat)
  (setq p (vlax-curve-getpointatdist sn dat)
        a (angle '(0. 0. 0.) (vlax-curve-getfirstDeriv sn (vlax-curve-getParamAtPoint sn p))))
)


(princ)
(princ "wortega 2024 // SENALES EN LISTA // ")
(princ "command: SENALES-LISTA              ")
(princ)
(c:SENALES-LISTA)


 

Screenshot 2024-02-15 125602.png

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

You dont need Excel to do this if you want warning signs on a bend you can find the curve in the alignment, re CIV3D, much simpler if it is a pline or have kept the original pline when making the alignment. 

 

Just needs say some rules about placement 1st sign dist from TP then spacing etc.

 

If you have CIV3d can get the chainage of the TP point and use that with "getpointatdistance" for the signs.

 

Link to comment
Share on other sites

  • 1 month later...
On 5/20/2020 at 6:48 AM, Wellington said:

Hey guys! How's going? Can anyone help me?

 

Look: i need to place a lot of blocks in an extensive polyline but the blocks need to have a specific distance from the polyline beginning - and this distance will not be equal to each block. 

So, i thought in create a list (excel or csv file) and specify each block name and distance to the lisp read the archive and place the block at correct point. Did you get it?

 

PS: remember that the blocks will not have the same interval distance.

 

This is an example for the list layout.

image.png.7c3c78c17e04a9a6a041bdeff72930ab.png

 

And the result is something like this:

image.png.238e27e6cbda8daa875970db54fb47c9.png

 

I hope you guys could understand and help me! - sorry for my english - 

Thanks!

Much love from Brazil

 

Wellington Moura

 

 

 

https://www.theswamp.org/index.php?topic=59433.0

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...