Author Topic: Array along line ,pline spline , arc - read distance from txt file  (Read 2184 times)

0 Members and 1 Guest are viewing this topic.

PPETROS

  • Newt
  • Posts: 27
Hello evryone
I am trying to make a lisp routine that arrays a block across a line, polyline, spline, arc   at distances that it reads from the file distance list. But  i cannot do it.
Also if i read the file distance list again the lisp routine crashes
Is there anyone that help me ?
Here is the routine , distance list file and dwg file sample.
Thanks

Code: [Select]
(defun C:test () ;(/ ang cumm_dist dis dist_list leng obj pt)
  (vl-load-com)
  ;; build master list of the distances, starting from 0.0 - important!

  (setq fn (getfiled "Enter file name without extension"(getvar "dwgprefix")"txt" 4))
  (setq fp  (open fn "r")
lst '()
  )
  ;; Iterate the file, writing each line to
  ;; the list
  (while (setq l (read-line fp))
    (setq lst (cons l lst))
  )
  ;; Close the file.
  (close fp)
  ;; Reverse the list
  ;  (setq lst (reverse lst))
  ;string to list of real numbers
  (foreach x lst
    (setq lst1 (cons (read x) lst1))
  )
  (reverse lst1)

  (setq dist_list 'lst1)
  ;(print dist_list)     
  (setq cumm_dist (apply '+ A))

  (setq dis 0.0)
  (setq obj (vlax-ename->vla-object
      (car (entsel "\n >> Select profile >>"))
    )
  )
  (setq leng (vlax-curve-getdistatpoint obj (vlax-curve-getendpoint obj)))

(setq A (ENTSEL "\PICK THE BLOCK YOU WANT TO ARRAY "))
(setq B (entget (car a)))
(setq BLK (cdr (assoc 2 b)));EXTRACT THE BLOCK NAME

;; check if pline length is not less than the cumulative distance
  (if (< leng cumm_dist)
    (progn
      (alert "Pline length is less then summary distance")
      (princ)
    )

    (while (< dis cumm_dist)
      (setq dis (+ dis (car lst1)))
      (setq pt (vlax-curve-getpointatdist obj dis))

      ;; get angle:
      (setq ang (angle '(0 0 0)
       (vlax-curve-getfirstderiv
obj
(vlax-curve-getparamatpoint obj pt)
       )
)
      )
      ;;insert block: 
      (vlax-invoke
(vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
'InsertBlock pt BLK 1 1 1 ang)

        (setq dist_list (cdr dist_list))
     )
  )
  (princ)
)

kpblc

  • Bull Frog
  • Posts: 396
Re: Array along line ,pline spline , arc - read distance from txt file
« Reply #1 on: June 27, 2018, 12:23:33 PM »
Use not pt but (vlax-3d-point pt):
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test2 (/ adoc file handle str lst blk ent len f_len pt)
  2.   (if (and (setq file (setq fn (getfiled "Enter file name without extension" (getvar "dwgprefix") "txt" 4)))
  3.            (/= file "")
  4.            (findfile file)
  5.            (= (type
  6.                 (setq blk (vl-catch-all-apply (function (lambda () (car (entsel "\nSelect block reference <Cancel> : "))))))
  7.                 ) ;_ end of type
  8.               'ename
  9.               ) ;_ end of =
  10.            (= (cdr (assoc 0 (entget blk))) "INSERT")
  11.            (setq blk (cdr (assoc 2 (entget blk))))
  12.            (= (type
  13.                 (setq ent (vl-catch-all-apply (function (lambda () (car (entsel "\nSelect profile <Cancel> : "))))))
  14.                 ) ;_ end of type
  15.               'ename
  16.               ) ;_ end of =
  17.            (wcmatch (cdr (assoc 0 (entget ent))) "*LINE,ARC")
  18.            ) ;_ end of and
  19.     (progn (setq handle (open file "r"))
  20.            (while (setq str (read-line handle)) (setq lst (cons str lst)))
  21.            (close handle)
  22.            (setq lst   (mapcar (function atof) (reverse lst))
  23.                  lst   (cons (car lst) (vl-remove-if 'zerop (cdr lst)))
  24.                  len   0.
  25.                  f_len (vlax-curve-getdistatpoint ent (vlax-curve-getendpoint ent))
  26.                  ) ;_ end of setq
  27.            (while (and lst (< len f_len))
  28.              (vla-insertblock (vla-get-modelspace adoc)
  29.                              (vlax-3d-point (setq pt (vlax-curve-getpointatdist ent (setq len (+ len (car lst))))))
  30.                               blk
  31.                               1.
  32.                               1.
  33.                               1.
  34.                               (angle '(0. 0. 0.) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatpoint ent pt)))
  35.                               ) ;_ end of vla-InsertBlock
  36.              (setq lst (cdr lst))
  37.              ) ;_ end of while
  38.            (vla-endundomark adoc)
  39.            ) ;_ end of progn
  40.     ) ;_ end of if
  41.   (princ)
  42.   ) ;_ end of defun
  43.  
Sorry for my English.

PPETROS

  • Newt
  • Posts: 27
Re: Array along line ,pline spline , arc - read distance from txt file
« Reply #2 on: June 27, 2018, 01:20:58 PM »
Thanks for the suggestion but it doesn't work with the polylines, splines.
Also if you run the routine again it doesn't  work.

kpblc

  • Bull Frog
  • Posts: 396
Re: Array along line ,pline spline , arc - read distance from txt file
« Reply #3 on: June 27, 2018, 01:38:33 PM »
I started routine at least 10 times - it works fine (ACAD 2016x64Eng + all updates).
Sorry for my English.

kpblc

  • Bull Frog
  • Posts: 396
Re: Array along line ,pline spline , arc - read distance from txt file
« Reply #4 on: June 27, 2018, 01:41:49 PM »
Screensht:
Sorry for my English.

PPETROS

  • Newt
  • Posts: 27
Re: Array along line ,pline spline , arc - read distance from txt file
« Reply #5 on: June 27, 2018, 02:18:18 PM »
OK  it works. Thank you very mach

ahsattarian

  • Newt
  • Posts: 112
Re: Array along line ,pline spline , arc - read distance from txt file
« Reply #6 on: January 22, 2021, 04:49:55 AM »
I recommend u to use commands  :   DIVIDE     MEASURE    ARRAYPATH