Jump to content

Recommended Posts

Posted

Hi all, 

 

I need a lisp file where I want to place block at every bend of the polyline. So bending may occur polyline to polyline or segment in a polyline. For the reference I’m attaching a dwg file below: 

sample.dwg

Posted

OK. How far have you gotten into trying a, AutoLISP  program for yourself? Perhaps we can help to answer your questions.

Just requesting a free program is not what this for was intended for, but to help other beginner programmers.

 

That being said - we can be charitable if we like the challenge or it's a short, easy one. I personally don't have the time at the moment to provide a whole program for you.

Have you done a Google search to find something similar?

Posted
1 minute ago, pkenewell said:

OK. How far have you gotten into trying a, AutoLISP  program for yourself? Perhaps we can help to answer your questions.

Just requesting a free program is not what this for was intended for, but to help other beginner programmers.

 

That being said - we can be charitable if we like the challenge or it's a short, easy one. I personally don't have the time at the moment to provide a whole program for you.

Have you done a Google search to find something similar?

Actually I’m new in autolisp so I didn’t know much but I only can find the coordinates. And also search in google and I didn’t find any similar. 

Posted (edited)
1 hour ago, Akanezuko said:

Actually I’m new in autolisp so I didn’t know much but I only can find the coordinates. And also search in google and I didn’t find any similar. 

To get you started. Here's 2 examples of how to extract the coordinates from an LWPOLYLINE:

(defun get-plcoords (/ en ob pl rt)
   (vl-load-com)
   (if (and
         (setq en (entsel "\nSelect a Polyline: "))
         (= (cdr (assoc 0 (entget (car en)))) "LWPOLYLINE")
       )
      (progn
         (setq ob (vlax-ename->vla-object (car en))
               pl (vla-get-coordinates ob)
               pl (vlax-safearray->list (vlax-variant-value pl))
         )
         (while pl
            (setq rt (append rt (list (list (car pl) (cadr pl))))
                  pl (cddr pl)
            )
         )
         rt   
      )
   )
)

(defun get-plcoords2 (/ en el)
   (if (and
         (setq en (entsel "\nSelect a Polyline: "))
         (= (cdr (assoc 0 (entget (car en)))) "LWPOLYLINE")
       )
      (progn
         (setq el (entget (car en)))
         (mapcar 'cdr   
            (vl-remove-if 'null
               (mapcar (function (lambda (x)(if (= (car x) 10) x nil))) el)
            )
         )
      )
   )
)

 

Quick Example of inserting a block at the vertices (rename "MyBlock" to the block you want to insert):

(defun c:Block-on-pline ()
    (foreach n (get-plcoords)
       (command "._-insert" "MyBlock" "_non" n "" "" "")
    )
)

 

Edited by pkenewell
Posted
15 hours ago, pkenewell said:

To get you started. Here's 2 examples of how to extract the coordinates from an LWPOLYLINE:

(defun get-plcoords (/ en ob pl rt)
   (vl-load-com)
   (if (and
         (setq en (entsel "\nSelect a Polyline: "))
         (= (cdr (assoc 0 (entget (car en)))) "LWPOLYLINE")
       )
      (progn
         (setq ob (vlax-ename->vla-object (car en))
               pl (vla-get-coordinates ob)
               pl (vlax-safearray->list (vlax-variant-value pl))
         )
         (while pl
            (setq rt (append rt (list (list (car pl) (cadr pl))))
                  pl (cddr pl)
            )
         )
         rt   
      )
   )
)

(defun get-plcoords2 (/ en el)
   (if (and
         (setq en (entsel "\nSelect a Polyline: "))
         (= (cdr (assoc 0 (entget (car en)))) "LWPOLYLINE")
       )
      (progn
         (setq el (entget (car en)))
         (mapcar 'cdr   
            (vl-remove-if 'null
               (mapcar (function (lambda (x)(if (= (car x) 10) x nil))) el)
            )
         )
      )
   )
)

 

Quick Example of inserting a block at the vertices (rename "MyBlock" to the block you want to insert):

(defun c:Block-on-pline ()
    (foreach n (get-plcoords)
       (command "._-insert" "MyBlock" "_non" n "" "" "")
    )
)

 

Thank you @pkenewell , but how do I process that bending or angle things after getting the coordinates?

Posted (edited)
8 hours ago, Akanezuko said:

Thank you @pkenewell , but how do I process that bending or angle things after getting the coordinates?

 

@Akanezuko OK - here is the simplest way, change the command to below. Keep the original (get-coords) function from above. I've commented it to explain how it works.

(defun c:Block-on-pline (/ an bn pl) ;; Localize variables
    (setq pl (get-plcoords) ;; Gets the polyline coordinates with (get-plcoords) function.
          bn "MyBlock"      ;; Set the bn variable to your block name.
    )
    (while pl ;; While list is not empty
       (if (cadr pl)(setq an (angle (car pl)(cadr pl)))) ;; Get the angle of the 1st 2 points.
       ;; Insert the Block to the 1st point (convert angle from radians to degrees).
       (command "._-insert" bn "_non" (car pl) "" "" (if an (* (/ an pi) 180.0) 0.0))
       (setq pl (cdr pl));; Strip the first coordinate from the list.
    ) ;; End While
)

 

Edited by pkenewell

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