Jump to content

How to insert block at every vertice of a polyline in lisp?


Recommended Posts

Posted (edited)

Hi i want to insert attribute block at every polyline vertices. I am writing a code but i have two problems.

 

1) When the code insert the block at polyline vertices at  the last vertece have a duplicate block

2) I want to add  a list box to select the type of the block i want to insert. This block will be already insert the drawing

 

(defun c:test()
  (setq plobj (car (entsel "\nSelect Polyline: ")) inc 0); end setq
  (while (<= inc (vlax-curve-getEndParam plobj))
  ; This lines set the scale of the block
   (setq scl (getvar "useri1"))
   (setq scl1 (* scl 0.0025))
  ;======================================             
   (command  "_.insert" "point" (vlax-curve-getPointAtParam plobj inc) scl1 "" "" "" )
   (setq inc (1+ inc))
  ); end while
); end defun

 

I have this part of a code from another lisp  that load the list box i want , but i don't know how to  use it in the code above

 

(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
  ;; List Select Dialog (Temp DCL list box selection, based on provided list)
  ;; title - list box title
  ;; label - label for list box
  ;; height - height of box
  ;; width - width of box
  ;; multi - selection method ["true": multiple, "false": single]
  ;; lst - list of strings to place in list box
  ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                   (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                   (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                   (strcat "width = " (vl-princ-to-string width) ";")
                   (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
             )
    (write-line x fo)
  )
  (close fo)
  (new_dialog "list_select" (setq d (load_dialog fn)))
  (start_list "lst")
  (mapcar (function add_list) lst)
  (end_list)
  (setq item (set_tile "lst" "0"))
  (action_tile "lst" "(setq item $value)")
  (setq f (start_dialog))
  (unload_dialog d)
  (vl-file-delete fn)
  (if (= f 1)
    ((lambda (s / i s l)
       (while (setq i (vl-string-search " " s))
         (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
         (setq s (substr s (+ 2 i)))
       )
       (reverse (cons (nth (atoi s) lst) l))
     )
      item
    )
  )
)

 

Thanks

 

Screenshot 2022-11-06 172050.jpg

Drawing1.dwg

Edited by prodromosm
Posted
(defun c:test()
  (setq plobj (car (entsel "\nSelect Polyline: ")) inc 0); end setq
  (while (<= inc (vlax-curve-getEndParam plobj))
   (setq scl (getvar "useri1"))
   (setq scl1 (* scl 0.0025))
  ; (command  "_.insert" "point" (vlax-curve-getPointAtParam plobj inc) scl1 "" "" "" )
   (setq block (car (AT:ListSelect "Select block to insert:" "" 10 10 "false" lst)))
   (setq inc (1+ inc))
  ); end while
); end defun


(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
  ;; List Select Dialog (Temp DCL list box selection, based on provided list)
  ;; title - list box title
  ;; label - label for list box
  ;; height - height of box
  ;; width - width of box
  ;; multi - selection method ["true": multiple, "false": single]
  ;; lst - list of strings to place in list box
  ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                   (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                   (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                   (strcat "width = " (vl-princ-to-string width) ";")
                   (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
             )
    (write-line x fo)
  )
  (close fo)
  (new_dialog "list_select" (setq d (load_dialog fn)))
  (start_list "lst")
  (mapcar (function add_list) lst)
  (end_list)
  (setq item (set_tile "lst" "0"))
  (action_tile "lst" "(setq item $value)")
  (setq f (start_dialog))
  (unload_dialog d)
  (vl-file-delete fn)
  (if (= f 1)
    ((lambda (s / i s l)
       (while (setq i (vl-string-search " " s))
         (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
         (setq s (substr s (+ 2 i)))
       )
       (reverse (cons (nth (atoi s) lst) l))
     )
      item
    )
  )
)

 

 

I update the code but need help.

 

Thanks

Posted

Hi Scoutr4. Yes this code works. Can you help me with the scale of the blocks? I use the code bellow for the scale. Thanks

 

   (setq scl (getvar "useri1"))
   (setq scl1 (* scl 0.0025))

 

Posted

Hi Scoutr4. Is it possible to add a filter if polyline vertex have already a block, not to insert another ? Sometimes  for example I have   polyline with 10 vertices and the 3 of them have already a block and I want to insert block to the other seven not to all.

 

Thanks

 

 

Posted

To check for blocks at the points, there must be a line at the base point of the blocks. 

If the base point is empty, with the line command click the base point and type 0,0 once. Then click escape. You will get a dot-like line.

PLB.LSP

Posted
Quote

You will get a dot-like line.

The code works. You said something about a dot line.  I can not see any dot line in the drawing !!! Can you explain me ?

 

Thanks

Posted

There are six different blocks. Try to throw blocks with similar characteristics on the same line. 

You will understand the difference between the blocks.

 

Example.dwg

Posted

I understand now. I am using dot blocks, that's why I didn't understand it !!!!

 

Thanks

Posted

Rather than use "Useri1" which is integer by the way, use (setq sc (vlax-ldata-get "prodromosn" "scale")) this is saved in the dwg using (vlax-ldata-put "prodromosn" "scale" scl1)

 

"Userr1" is a real.

  • Agree 1

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...