Offset 3D polyline both sides and join the offset polylines

Offset 3D polyline both sides and join the offset polylines

sonny_t
Contributor Contributor
1,863 Views
15 Replies
Message 1 of 16

Offset 3D polyline both sides and join the offset polylines

sonny_t
Contributor
Contributor

Hi,

 

I'm new to lisp and looking for a routine for my project, that is almost like the "Lee Mac: Double Offset".

But it must select all 3D polylines in a layer and close the offset.

Like the pictures.

 

Any help much appreciated!

S.

 

 

0 Likes
Accepted solutions (1)
1,864 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant

3D Polylines cannot be Offset.  We can't tell from images [post a .dwg file], but are they planar, and not actually bending out of a plane [even if their plane is not the current Coordinate System]?  If so, would you settle for Exploding them, and Joining the pieces into non-3D Polylines so they can be Offset?

Kent Cooper, AIA
0 Likes
Message 3 of 16

sonny_t
Contributor
Contributor

Hi  Kent1Cooper,

 

The polylines are non coplanar, it need to be kept an 3Dpolyline.

I've posted an (Test.dwg) example.

0 Likes
Message 4 of 16

Kent1Cooper
Consultant
Consultant

The reason 3DPolylines [and Splines if they are not planar] can't be Offset is that they do not define a plane, and there is no such thing as a "side" to choose, as opposed to "the other side," for a direction for the positional relationship of the result to the source.  Your drawing has a lot of 3DPolylines with only the two end vertices, and those are in fact planar, though there are an infinite number of planes any of them could be considered to lie in, spinning around their one segment as a rotational axis.

 

Would it work for you to Copy them in opposite directions in the context of the current construction plane, as a kind of "pseudo-offset"?  It seems that's the situation with your triples -- the Z coordinates of the ends of the ones on either side are the same as each other and as the one between them [in a couple that I checked, at least].  If that will serve, it's probably possible to do that, by determining the two directions to Copy as perpendicular to the XY-only angle of the 3DPolyline.  But for those with more than one segment, and some kind of bend(s), what should that determination be based on?  The XY-only angle of the longest segment, or something?

Kent Cooper, AIA
0 Likes
Message 5 of 16

Sea-Haven
Mentor
Mentor

The only way to get some form of planar answer may be to use extrude and draw a line and somehow extrude along the 3dpath. The line may need to be a rectang say 0.0000001 high. Need to work out the rotate 3d so get rectang square of the 1st segment of the 3d poly. Exploding result would possibly be a offset. 

0 Likes
Message 6 of 16

sonny_t
Contributor
Contributor

Hi all, sorry for the late reaction, been a bit busy.

I appeciate all the input for trying solving my problem. I thought it would be easier..... ‌‌ But unfortunately it is more difficult then i thought it would be. I guess i have to do it the old school way, manualy....
But if someone finds this unicorn, please do let me know. ‌‌


Thanks again all for the effort.

 

0 Likes
Message 7 of 16

CADaSchtroumpf
Advisor
Advisor

One of my old lisp which is certainly not perfect but which can help you...

(defun pm_dec (lpo lpn / l n1 n2)
  (setq l (append lpo lpn) n1 1 n2 (length l))
  (command "_pface")
  (repeat (* 2 (length lpo))
    (command (car l))
    (setq l (cdr l))
  ) 
  (command "")
  (repeat (1- (length lpo))
    (command n1)
    (setq n1 (1+ n1))
    (command n1)
    (command (1- n2))
    (command n2)
    (setq n2 (1- n2))
    (command "")
  ) 
  (command "")
)
(defun m_lpl (ent / l l1 x y z)
  (setq l_2d '() l_3d '())
  (setq l (entget (car ent)))
  (if (eq (cdr (assoc 0 l)) "LWPOLYLINE")
    (setq l_2d (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) l)))
    (progn
      (setq l1 (entget (entnext (cdr (assoc -1 l)))))
      (while (/= "SEQEND" (cdr (assoc 0 l1)))
        (setq
          x (cadr (assoc 10 l1))
          y (caddr (assoc 10 l1))
          z (cadddr (assoc 10 l1))
        )
        (setq pt_scur (trans (list x y z) 0 1))
        (setq x (car pt_scur) y (cadr pt_scur) z (caddr pt_scur))
        (setq
          l_2d (append l_2d (list (list x y)))
          l_3d (append l_3d (list z))
          l1 (entget (entnext (cdr (assoc -1 l1))))
        )
      )
    )
  )
)
(defun c:Offset3d ( / ent_or typpol dec_z dec_xy c_curr l_3do l_3dn key_md counter l_3d l_2d ent_m ent_nw l_nw)
  (while (null (setq ent_or (entsel "\nChoice of the 3Dpoly to offset: "))))
  (setq typpol (entget (car ent_or)))
  (cond
    ((and (= (cdr (assoc 0 typpol)) "POLYLINE") (eq (boole 1 (cdr (assoc 70 typpol)) 12) 8))
      (initget 1)
      (setq dec_z (getdist "\nZ offset: "))
      (if (zerop dec_z)
        (progn
          (initget "Uniform Variable")
          (setq key_md (getkword "\nDelta Z [Uniform/Variable] <U>: "))
        )
      )
      (initget 71)
      (setq dec_xy (getdist "\nOffset in the XY plane: "))
      (setvar "cmdecho" 0)
      (command "_.undo" "_begin")
      (setvar "osmode" (+ 16384 (rem (getvar "osmode") 16384)))
      (setq c_curr (getvar "clayer"))
      (setvar "clayer" (cdr (assoc 8 typpol)))
      (m_lpl ent_or)
      (setq l_3do (mapcar 'append l_2d (mapcar 'list l_3d)) counter 0)
      (setq l_3dn
        (mapcar 
          '(lambda (x) 
            (if (eq key_md "Variable")
              (progn
                (setq counter (1+ counter)) (initget 1)
                (+ x (getdist (strcat "\nDelta Z  at " (itoa counter) "(first)(second) point: ")))
              )
              (+ x dec_z)
            )
          )
          l_3d
        )
      )
      (command "_.pline") 
      (repeat (length l_2d)
        (command (car l_2d))
        (setq l_2d (cdr l_2d))
      )
      (command "")
      (setq ent_m (entlast))
      (setvar "cmdecho" 1)
      (command "_.offset" dec_xy ent_m pause "")
      (setvar "cmdecho" 0)
      (setq ent_nw (entlast))
      (m_lpl (list ent_nw '(0.0 0.0 0.0)))
      (setq l_nw (mapcar 'append l_2d (mapcar 'list l_3dn)))
      (cond
        ((zerop (- (length l_2d) (length l_3do)))
          (initget "Yes No")
          (if (eq (getkword "\nCreate a mesh in the current layer? [Yes/No] <No>: ") "Yes")
            (progn
              (setvar "clayer" c_curr)
              (pm_dec l_3do (reverse l_nw))
              (setvar "clayer" (cdr (assoc 8 typpol)))
            )
          )
        )
        (T (alert "\nCAUTION presence of short segments (< at offset); Wrong result in Z!"))
      )
      (entdel ent_m)
      (entdel ent_nw)
      (command "_.3dpoly")
      (repeat (length l_nw)
        (command (car l_nw))
        (setq l_nw (cdr l_nw))
      )
      (command "")
      (setvar "clayer" c_curr)
      (command "_.undo" "_end")
      (setvar "cmdecho" 1)
    )
    (T (prompt "\nSelected entity is not a 3D polyline, or it is Splined."))
  )
  (prin1)
)
(prompt "\nOFFSET3D loaded! - Offset of a 3DPOLY in 3D in the current LAYER and UCS")(prin1)
0 Likes
Message 8 of 16

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

.... Would it work for you to Copy them in opposite directions in the context of the current construction plane, as a kind of "pseudo-offset"?  .... by determining the two directions to Copy as perpendicular to the XY-only angle of the 3DPolyline.  .... The XY-only angle of the longest segment....


Assuming those to be acceptable criteria, try the attached 3DPOBSJ.lsp with its command of the same name.  It stands for 3D Polyline Offset Both Sides & Join.  [You can change the file and/or command name(s) as you choose.]

 

See the comments at the top of the file.  Lightly tested, but it seems to work in your sample drawing.

Kent Cooper, AIA
0 Likes
Message 9 of 16

sonny_t
Contributor
Contributor

Great!! 😀 I will try both. And let you know if it works.

0 Likes
Message 10 of 16

sonny_t
Contributor
Contributor

CADaSchtroumpf

Unfortunatly this didn't worked for me, but appeciate the effort!!!!  Thank you. 🙏

 

@ Kent1Coope

My unicorn has been discoverd!!!  😀 That's what i was looking for!!! 🙌

With a very tiny request...., 😊 is it possible to have also points where the lines intersect (see red circle)?

 

sonny_t_1-1686901843462.png

 

 

sonny_t_0-1686901738818.png

 

After said i couldn't be done, i was thinking of exporting the polylines coordinates to excel and then draw, with an offset the polylines......

But this is way better (and easier)! 😄

 

Btw your approach is interesting.

 

Kind regards,

S.

 

0 Likes
Message 11 of 16

Kent1Cooper
Consultant
Consultant

@sonny_t wrote:

 

.... is it possible to have also points where the lines intersect (see red circle)? ....

....

    (initcommandversion)
    (command
      "_.join" toJoin ""
      "_.point" (vlax-curve-getStartPoint 3DP)
      "_.point" (vlax-curve-getEndPoint 3DP)
    ); command
  ); repeat
); progn
....

 

Kent Cooper, AIA
0 Likes
Message 12 of 16

sonny_t
Contributor
Contributor

Sorry for my unclear question.

As you can see in the first picture I have added the rules with good results.

 

But what I meant was like the bottom picture, sorry for the misinterpretation.

 

sonny_t_0-1686930537727.png

 

 

 

sonny_t_1-1686930608460.png

 

 

Kind regards,

S.

 

 

0 Likes
Message 13 of 16

marko_ribar
Advisor
Advisor

Did you mean - offset - copy in vertical plane and closure in it?

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 14 of 16

Kent1Cooper
Consultant
Consultant
Accepted solution

You mean you want vertices at those locations?  [I took your word "points" literally in AutoCAD's meaning of the word.]

 

If so, try the attached.  It just draws a 3DPolyline across the ends instead of a Line, including vertices at the ends of the source object along the way.  [Super-minimally tested.]

Kent Cooper, AIA
0 Likes
Message 15 of 16

sonny_t
Contributor
Contributor

Hi Marko,

It is in the horizontal plane.

0 Likes
Message 16 of 16

sonny_t
Contributor
Contributor

Perfect!!! 🙌

That was the little push it needed...... 😄

Kent1Cooper, thanks for the great effort ! 👍

 

Thanks to all for the input and interest.

 

Kind regards,

S.

0 Likes