Straighten polyline with viewports

Straighten polyline with viewports

alar
Explorer Explorer
2,582 Views
17 Replies
Message 1 of 18

Straighten polyline with viewports

alar
Explorer
Explorer

Hello

 

Model space and 2Dpolyline.

Lisp should create viewports - straighten polyline.

 

Each viewport: height 20 mm, length = polyline segment length. Viewport scale 2.0.

 

Capture1.PNG

 

0 Likes
Accepted solutions (1)
2,583 Views
17 Replies
Replies (17)
Message 2 of 18

Kent1Cooper
Consultant
Consultant

@alar wrote:

.... straighten polyline.

.... 


Since you don't say exactly what you're going to do with those Viewports, the following may not work for you, but....

 

It doesn't do it by way of Viewports, but this defines an SPS command [= Stretch Polyline(s) Straight] that straightens Polylines out into linear Polylines with all the same segment lengths -- as many as you want to do at once, LW or "heavy," and including straightening arc segments.  [It doesn't change the selected Polyline(s), but adds new one(s) extending 0--degree-ward from the start point(s) of the selected one(s).]

Kent Cooper, AIA
0 Likes
Message 3 of 18

alar
Explorer
Explorer

Hi

 

The polyline is like a target.Its a pipeline, and I'd like to use that LISP for straighten-piping-layout

 

Like that

Model view. Target polyline - [blue ---2T---  ---]

 

Capture1.JPG

 

 

 

And final result for paperspace

Polyline --2T---- is like "straightened"

Paperspace.JPG

 

0 Likes
Message 4 of 18

mtcopper
Participant
Participant

Love this topic , but sadly it dosen't have solution !

0 Likes
Message 5 of 18

sby0531
Enthusiast
Enthusiast

@mtcopper  已写:

Love this topic , but sadly it dosen't have solution !


I think there should be a solution of LISP code.

0 Likes
Message 6 of 18

mtcopper
Participant
Participant

  yes, but i think it's quite complex to write so. 
Hopefully someone will firgue out! 

0 Likes
Message 7 of 18

pbejse
Mentor
Mentor

Is your requirement exactly the same as the OP? right down to the size and units?

 

 

0 Likes
Message 8 of 18

phanaem
Collaborator
Collaborator
Accepted solution

Here is a partial solution.

Feel free to add your favorite error trap and some other settings (WCS/UCS, Layers, selection check etc)

I'd like to improve it, but I don't have the time right now.

 

Edit: It doesn't work if a layout has a space in it's name.

 

(defun c:test ( / m2p acobj acdoc e sc h p lst layouts layout p)
  (vl-load-com)

  (defun m2p (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b))
  
  (setq acobj (vlax-get-acad-object)
        acdoc  (vla-get-activedocument acobj)
  )
  
  (if
    (and
      (setq e (entsel "\nSelect polyline: "))
      (progn
        (initget 6)
        (setq sc (getreal "\nSpecify vports scale 1:"))
      )
      (progn
        (initget 6)
        (setq h (getdist "\nSpecify vport height in PS units: "))
      )
    )
    (progn
      (setq p (cadr e)
            e (car e)
      )
      (setq lst (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e))))
      (if
        (>
          (vlax-curve-getdistatpoint e
            (vlax-curve-getclosestpointto e p)
          )
          (/
            (vlax-curve-getdistatparam e
              (vlax-curve-getendparam e)
            )
            2.0
          )
        )
        (setq lst (reverse lst))
      )
      (if
        (progn
          (setq layouts (layoutlist))
          (initget (substr
                     (apply 'strcat
                       (mapcar '(lambda (x) (strcat " " x)) layouts)
                     )
                     2
                   )
          )
          (setq layout (getkword
                         (strcat
                           "\nSpecify destination layout ["
                            (substr
                              (apply 'strcat
                                (mapcar '(lambda (x) (strcat "/" x)) layouts)
                              )
                              2
                            )
                            "]: "
                         )
                       )
          )
        )
        (progn
          (setvar 'ctab layout)
          (vla-put-mspace acdoc :vlax-false)
          (if
            (setq p (getpoint "\nSpecify insertion point: "))
            (mapcar
              '(lambda (p1 p2 / vp)
                 (command
                   "_mview"
                   "_non" p
                   "_non" (mapcar '+ p (list (/ (distance p1 p2) sc) h))
                 )
                 (setq vp (vlax-ename->vla-object (entlast)))
                 (vla-put-twistangle vp (- (+ pi pi) (angle p1 p2)))
                 (vla-zoomextents acobj)
                 (vla-put-mspace acdoc :vlax-true)
                 (vla-put-activepviewport acdoc vp)
                 (vla-zoomcenter acobj (vlax-3d-point (m2p p1 p2)) (* h sc))
                 (vla-put-mspace acdoc :vlax-false)
                 (setq p (mapcar '+ p (list (/ (distance p1 p2) sc) 0.0)))
               )
              lst (cdr lst)
            )
          )
        )
      )
    )
  )
  (princ)
)

 

 

 

Message 9 of 18

pbejse
Mentor
Mentor

Nice Stefan 👍

 

0 Likes
Message 10 of 18

sby0531
Enthusiast
Enthusiast

@phanaem  已写:

Here is a partial solution.

Feel free to add your favorite error trap and some other settings (WCS/UCS, Layers, selection check etc)

I'd like to improve it, but I don't have the time right now.

 

Edit: It doesn't work if a layout has a space in it's name.

 

 

(defun c:test ( / m2p acobj acdoc e sc h p lst layouts layout p)
  (vl-load-com)

  (defun m2p (a b) (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b))
  
  (setq acobj (vlax-get-acad-object)
        acdoc  (vla-get-activedocument acobj)
  )
  
  (if
    (and
      (setq e (entsel "\nSelect polyline: "))
      (progn
        (initget 6)
        (setq sc (getreal "\nSpecify vports scale 1:"))
      )
      (progn
        (initget 6)
        (setq h (getdist "\nSpecify vport height in PS units: "))
      )
    )
    (progn
      (setq p (cadr e)
            e (car e)
      )
      (setq lst (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e))))
      (if
        (>
          (vlax-curve-getdistatpoint e
            (vlax-curve-getclosestpointto e p)
          )
          (/
            (vlax-curve-getdistatparam e
              (vlax-curve-getendparam e)
            )
            2.0
          )
        )
        (setq lst (reverse lst))
      )
      (if
        (progn
          (setq layouts (layoutlist))
          (initget (substr
                     (apply 'strcat
                       (mapcar '(lambda (x) (strcat " " x)) layouts)
                     )
                     2
                   )
          )
          (setq layout (getkword
                         (strcat
                           "\nSpecify destination layout ["
                            (substr
                              (apply 'strcat
                                (mapcar '(lambda (x) (strcat "/" x)) layouts)
                              )
                              2
                            )
                            "]: "
                         )
                       )
          )
        )
        (progn
          (setvar 'ctab layout)
          (vla-put-mspace acdoc :vlax-false)
          (if
            (setq p (getpoint "\nSpecify insertion point: "))
            (mapcar
              '(lambda (p1 p2 / vp)
                 (command
                   "_mview"
                   "_non" p
                   "_non" (mapcar '+ p (list (/ (distance p1 p2) sc) h))
                 )
                 (setq vp (vlax-ename->vla-object (entlast)))
                 (vla-put-twistangle vp (- (+ pi pi) (angle p1 p2)))
                 (vla-zoomextents acobj)
                 (vla-put-mspace acdoc :vlax-true)
                 (vla-put-activepviewport acdoc vp)
                 (vla-zoomcenter acobj (vlax-3d-point (m2p p1 p2)) (* h sc))
                 (vla-put-mspace acdoc :vlax-false)
                 (setq p (mapcar '+ p (list (/ (distance p1 p2) sc) 0.0)))
               )
              lst (cdr lst)
            )
          )
        )
      )
    )
  )
  (princ)
)

 

 

 

 


Your code is helpful and worth learning to me. But why don't you like closing the parens at the same line? Almost all the common lisp programmer always do so. And I think the lisp codes looks more concise and compact if the closing parens are placed at the same line.

0 Likes
Message 11 of 18

phanaem
Collaborator
Collaborator

@sby0531 wrote:

Your code is helpful and worth learning to me. But why don't you like closing the parens at the same line? Almost all the common lisp programmer always do so. And I think the lisp codes looks more concise and compact if the closing parens are placed at the same line.

It is the way VLIDE (auto)format the code. And you can easily pair them visually if they are closed on the same column.

So, it's the habit. In-line style is not so common among the AutoLispers.

Plus, someone might ask, why limit to the parenthesis only, why not all the code in one single line?

0 Likes
Message 12 of 18

mtcopper
Participant
Participant

oh maybe , i'm not sure... but i think the OP mean that (he/she) want to create multiple viewports by selecting a polyline or alignment from model in a layout or multiple layouts and besides all the viewports have the coordinate axis rotated exactly in the same direction so it can look like a straight polyline.

0 Likes
Message 13 of 18

mtcopper
Participant
Participant

Amazing ! Thank you .

0 Likes
Message 14 of 18

Sea-Haven
Mentor
Mentor

It is normal practice to show the plan view in a true orientation, 40 years Civil Engineer, but in saying this you are asking for a over the top solution when a simple answer is actually available and that is to use a ucs in your viewport that covers the range of the long section. 

 

This type of approach is built in to software like CIV3D Civilsite etc. They auto make the layouts and work out the ucs orientation.

 

Ok manual way very easy, draw a line from start point chainage to end chainage of your pipe for each layout section. Check that lines have Z set to 0 use properties, take your long section layout add a mview, go into view say zoom e, then UCS OB select match line section, pick left side, then type plan, your view will rotate to that orientation, set viewport scale and your nearly there, pan to approx. long section. Ok now to align a chainage, simply draw a vertical line in Mspace from a chainage of your long section, you can "move" the mview window select the correct chainage point of the mview stay in mspace then use say perp and the mview will be correctly aligned. Lock viewport, next viewport you may need to type UCS W Plan to reset view orientation.

 

Yes it could be automated.

 

For all those that have posted sorry but the solution exists in that you can take a pline and set spacings and auto create mviews on multiple layouts this code has existed for a long time.

 

screenshot206.png

0 Likes
Message 15 of 18

pbejse
Mentor
Mentor

@mtcopper wrote:

oh maybe , i'm not sure... but i think the OP mean that (he/she) want to create multiple viewports by selecting a polyline or alignment from model in a layout or multiple layouts and besides all the viewports have the coordinate axis rotated exactly in the same direction so it can look like a straight polyline.


Yes, maybe for the OP, but what i'm asking, is that your requirement? Since you were the one who "zombified"  this discussion 😊

 

Or your  interest on this discussion is for learning and not necessarily a need for this specific routine ? or both?

 

Message 16 of 18

pbejse
Mentor
Mentor

@Sea-Haven wrote:

...solution exists in that you can take a pline and set spacings and auto create mviews on multiple layouts this code has existed for a long time.


I would loved to see that code. Is that the one that creates  named views with boundaries  of different rotations?  

0 Likes
Message 17 of 18

mtcopper
Participant
Participant

thanks for your reply! 

haha 😄 ok...so my requirment is the same with OP and i'm looking for a lisp that can solve this issue automatically.

0 Likes
Message 18 of 18

Sea-Haven
Mentor
Mentor

Pbejse I think your right about the views option I don't have a copy as I use software that does it automatically, but have done it manually as suggested. The code would set a rectangle based on a scale and sheet size making the mview to suit.

 

I have never seen say a curved road pipe plan straightened. Certainly rotated around X axis to suit.

 

I had 12 roads 1 dwg each road profile had a plan view parallel to the road alignment say 30+ sheets auto generated.