is there any way to create vertical construction line on selected polyline all vertices

is there any way to create vertical construction line on selected polyline all vertices

7aizur
Contributor Contributor
1,393 Views
17 Replies
Message 1 of 18

is there any way to create vertical construction line on selected polyline all vertices

7aizur
Contributor
Contributor

Here is a sample image where I want to add automatically construction line on all vertices with the help of lisp or any other way. 

TIA

007faizur_0-1662722404158.png

 

0 Likes
1,394 Views
17 Replies
Replies (17)
Message 2 of 18

ВeekeeCZ
Consultant
Consultant
Accepted solution

Easy enough.

 

(vl-load-com)

(defun c:VerAtVer ( / s)
  (and (setq s (car (entsel "\nPolyline: ")))
       (setq s (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget s)))
       (foreach v s (entmake (list '(0 . "XLINE") '(100 . "AcDbEntity") '(100 . "AcDbXline") v '(11 0. 1. 0.)))))
  (princ)
  )
Message 3 of 18

Kent1Cooper
Consultant
Consultant
Accepted solution

For as many as you want to select, all at once, including "heavy" 2D and 3D Polylines [not just LWPolylines]:

 

(vl-load-com)
(defun C:XLVAPV (/ plss n pl v); = XLines Vertical at All Polyline Vertices
  (prompt "\nTo draw Vertical Xlines through All Polyline Vertices,")
  (if (setq plss (ssget '((0 . "*POLYLINE"))))
    (repeat (setq n (sslength plss))
      (setq pl (ssname plss (setq n (1- n))))
      (command "_.XLINE" "_ver")
      (repeat (setq v (+ (fix (vlax-curve-getEndParam pl)) (if (vlax-curve-isClosed pl) 0 1)))
        (command "_non" (vlax-curve-getPointAtParam pl (setq v (1- v))))
      )
      (command "")
    )
  )
  (princ)
)

 

[It will "do it" on a Spline-fitted Polyline, though the Xlines will not be at the positions of its pre-Splined source vertices except at the ends.]

Kent Cooper, AIA
Message 4 of 18

7aizur
Contributor
Contributor

Thanks for the code but can you kindly tell me where to use the code?

0 Likes
Message 5 of 18

Kent1Cooper
Consultant
Consultant
Accepted solution

For starters, to try it, you can just Ctrl+C copy it to the clipboard and Ctr+V paste it into a drawing at the Command: line, and hit Enter to "register" the closing right parenthesis when it looks like this:

Kent1Cooper_0-1662724584651.png

Type the XLVAPV command name to use it.  [You can change the command name if you like.]

 

If it works as you intend, paste the code into a plain-text editor such as Notepad.  Save it as a file called whatever you like but with a .lsp filetype ending.  [It's best to put it in some folder location in the list in the OPTIONS command, Files tab, under Support File Search Path, preferably one with ...\support at the end.]  In AutoCAD, use the APPLOAD command, navigate to where you saved it and Load it.

Kent Cooper, AIA
0 Likes
Message 6 of 18

7aizur
Contributor
Contributor
Thanks for the code 😄
0 Likes
Message 7 of 18

7aizur
Contributor
Contributor
Thanks for your help ❤️
0 Likes
Message 8 of 18

Kent1Cooper
Consultant
Consultant

@7aizur wrote:
Thanks for your help ❤️

You're welcome.  I added the (vl-load-com) line at the top that should be there if you don't always have (vl...) functions loaded.  And it could use "the usual enhancements" like command-echo suppression and *error* handling.  Other things could be incorporated, e.g. to put them on a specific Layer [and make that if it doesn't exist], etc.

Kent Cooper, AIA
0 Likes
Message 9 of 18

ronjonp
Mentor
Mentor
Accepted solution

Solved HERE too .. mine creates an "XLINE" layer and sets it to not plot too 🙂

Message 10 of 18

Sea-Haven
Mentor
Mentor
0 Likes
Message 11 of 18

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

Posted here also ....


The same one as linked in Message 9.  Also limited to LWPolylines only.

Kent Cooper, AIA
0 Likes
Message 12 of 18

calderg1000
Mentor
Mentor

Regards @7aizur 

Please try this code

(defun c:Xp_pol2 (/ sn i pt)
  (if
    (setq sn (vlax-ename->vla-object (car (entsel "\nSelect. Lwpolyline: "))))
     (repeat (setq i (1+ (fix (vlax-curve-getendparam sn))))
       (setq pt (vlax-curve-getpointatparam sn (setq i (1- i))))
       (entmake (list '(0 . "Xline")
                      (cons 100 "AcDbEntity")
                      (cons 100 "AcDbXline")
                      (cons 10 pt)
                      (cons 11 '(0. 1. 0.))
                )
       )
     )
  )
)

Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 13 of 18

_Tharwat
Advisor
Advisor

Hi,

Your codes have three issues:

1- If a user selected object other than polyline.

2- If a user missed the object.

3- If selected polyline is closed, then there will be double vertical lines at the common start / end point.

0 Likes
Message 14 of 18

calderg1000
Mentor
Mentor
Accepted solution

Regards @_Tharwat 

Here I made some small adjustments, exclusive for open or closed Lwpolylines. I know that the Vl-remove-if and foreach approach would save me a few steps, but I wanted to try with parameters. It is likely to run faster with many vertices.

 

(defun c:Xp_pol0 (/ sn i pt)
  (princ "\nSelect Lwpolyline: ")
  (if (and
        (setq s (ssname (ssget "_+.:E" '((0 . "lwpolyline"))) 0))
        (if (= (cdr (assoc 70 (entget s))) 1)
          (setq c 0)
          (setq c 1)
        )
      )
    (repeat (setq i
                   (+ c
                      (fix (vlax-curve-getendparam (setq sn (vlax-ename->vla-object s))))
                   )
            )
      (setq pt (vlax-curve-getpointatparam sn (setq i (1- i))))
      (entmake (list '(0 . "Xline")
                     (cons 100 "AcDbEntity")
                     (cons 100 "AcDbXline")
                     (cons 10 pt)
                     (cons 11 '(0. 1. 0.))
               )
      )
    )
  )
  (princ)
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 15 of 18

7aizur
Contributor
Contributor
Thanks, dear for the code ❤️
0 Likes
Message 16 of 18

Sea-Haven
Mentor
Mentor

For others look at post 10 link again further explanation of what is really wanted.

0 Likes
Message 17 of 18

calderg1000
Mentor
Mentor

Dear @7aizur 

Glad to hepl...!!!


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 18 of 18

Kent1Cooper
Consultant
Consultant

@calderg1000 wrote:
....
  (fix (vlax-curve-getendparam (setq sn (vlax-ename->vla-object s))))
....

Just for your information, (vlax-curve-...) functions do not require conversion of entities to VLA objects -- they will also take just the entity name [as in Message 3]:

 

....
  (fix (vlax-curve-getendparam s))
....

 

and of course replacement of 'sn' with 's' later where parameter values are pulled.

 

In some routines the VLA-object conversion is needed for other reasons, so it can be appropriate, but it's not needed for something like this.

 

Also, if you're using parameter values, instead of the 10-code entries in entity data, then there's no reason to restrict it to LWPolylines [also as in Message 3]:

....  '((0 . "*polyline"))) ....

 

Kent Cooper, AIA