Jump to content

[REQUEST] offsetting 3dpoly autolisp OR drawing 2 parallel 3Dpoly at the same time (like MLine)


Mugna101

Recommended Posts

Hello everyone. Im using AutoCad 2021 and sometimes older versions of AutoCad but nothing before 2016.

 

I often draw 3dpoly lines and im trying to make an effort using Sweep command to make that 3dpoly appear as a square tunnel.

The issue is when the object twists as there are arcs or angles around the path.

 

I wish to keep the rectangle shape of the tunnel straight and I saw an option of using Loft comand but i need atleast 2 lines to make a surface which brings me to my request.

ofcourse this problem doesnt occur with circles, but only in shapes that u can see twist.

 

I do have a lisp for offsetting a 3dpoly but it doesnt work good on a 3dpoly that turns around itself (as in the file attached, blue line is the resulted offset i tried).

what happens when i try is that the line gets cut off and split to smaller lines that arent paralel to the line i tried to offset

 

What i would wish for is like the double offset lisp made by lee mac but for 3dpoly, to make it offset on given range.

 

EDIT: maybe is there a known lisp to do something like MLine with a 3Dpoly?

 

 

test.dwg

do u guys have any idea or a lisp to get this done right?

 

Edited by Mugna101
Link to comment
Share on other sites

5 hours ago, Mugna101 said:

The issue is when the object twists as there are arcs or angles around the path.

 How do you define zero twist? Is your goal to keep two of the side of the square profile parallel to the world XY plane?  In the image below the red line is a 3DPOLY that has vertices of changing x, y, and z coordinates. The white shape used sweep and a square.  The yellow shape has its square cross sections with two side always parallel to the XY plane.  It was constructed by position boxes end to end with rotations about axes parallel to the XY plane.

 image.thumb.png.b170256902bf90c016fbc4972ab724f3.png

image.thumb.png.d4da1ae2964edf71af533b859ad61795.png

 

After unioning the boxes together it looks like this.

image.png.c3f8f5ff245c5dad76a13c5b6ff463c3.png

 

Is this what you want?

 

Link to comment
Share on other sites

9 hours ago, Mugna101 said:

Hello everyone. Im using AutoCad 2021 and sometimes older versions of AutoCad but nothing before 2016.

 

I often draw 3dpoly lines and im trying to make an effort using Sweep command to make that 3dpoly appear as a square tunnel.

The issue is when the object twists as there are arcs or angles around the path.

 

I wish to keep the rectangle shape of the tunnel straight and I saw an option of using Loft comand but i need atleast 2 lines to make a surface which brings me to my request.

ofcourse this problem doesnt occur with circles, but only in shapes that u can see twist.

 

I do have a lisp for offsetting a 3dpoly but it doesnt work good on a 3dpoly that turns around itself (as in the file attached, blue line is the resulted offset i tried).

what happens when i try is that the line gets cut off and split to smaller lines that arent paralel to the line i tried to offset

 

What i would wish for is like the double offset lisp made by lee mac but for 3dpoly, to make it offset on given range.

 

 

test.dwg 78.04 kB · 6 downloads

do u guys have any idea or a lisp to get this done right?

 

 

  https://www.cadtutor.net/forum/topic/53442-offseting-3d-polyline/?fbclid=IwAR2FxiJzbQH7Z0hG4PaoiT5XHvXYek-MvV30jpfPyQYXyTWeGfhhKjF_9hk

 

 

; Offset a 3dPoly with horizontal and vertical distances
; 15 August 2014 - Gian Paolo Cattaneo 
 
(defun c:o3 ( / *error* 3dp p ogt)
   (defun *error* ( msg )
       (setvar 'offsetgaptype ogt)
       (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))        
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
   (setq ogt (getvar 'offsetgaptype))
   (setvar 'offsetgaptype 0)
   (or op (setq op 0.00))
   (or oz (setq oz 0.00))
   (while
       (progn
           (setq 3dp (car (entsel "\nSelect the 3D polyline to offset")))
           (if (not (eq "AcDb3dPolyline" (vlax-get (vlax-ename->vla-object 3dp) 'ObjectName)))
               (progn
                   (alert "This is not a 3D Polyline")
                   t
               )
           )
       )
   )
   (if 3dp
       (progn
           (while
               (progn
                   (initget (+ 2 4))
                   (setq op
                       (cond
                           ( (getdist (strcat "\nOffset Distance (horizontal)  <" (rtos op 2 2)">: ")) )
                           ( op )
                       )
                   )
                   (if (= op 0.)
                       (progn
                           (alert "The horizontal offset distance must be greater than zero")
                           t
                       )
                   )
               )
           )
           (setq oz
               (cond
                   ( (getdist (strcat "\nOffset Distance (vertical)    <" (rtos oz 2 2)">: ")) )
                   ( oz )
               )
           )
           (setq p (getpoint "\nSpecify point on side to offset "))
           (off3DP 3dp op oz p)
       )
   )
   (setvar 'offsetgaptype ogt)
   (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
   (princ)
)

;******************* Offset 3D Polyline ********************;
;                                                           ;
;  obj   [ENAME] - entity name                              ;
;  d_o   [REAL]  - horizontal offset distance               ;
;  d_z   [REAL]  - vertical offset distance                 ;
;  p_of  
;[list]  - point on side to offset                  ;
;                                                           ;
; ----------------------------------------------------------;
; (off3DP (car (entsel)) 2.15 -2.00 '(3 4 0))               ;
; ----------------------------------------------------------;
; author: Gian Paolo Cattaneo - 30.03.2013                  ;
;***********************************************************;
(defun off3DP ( obj d_o d_z p_of / EL Lv PL2 PL3 Lv Lv1 Lv2 n_of obj_of)
   (if
       (and
           (eq "AcDb3dPolyline" (vlax-get (vlax-ename->vla-object obj) 'ObjectName))
           (setq Lv (pl_coord obj))
           (setq PL2
               (entmakex
                   (append
                       (list
                           (cons 0 "LWPOLYLINE")
                           (cons 100 "AcDbEntity")
                           (cons 100 "AcDbPolyline")
                           (cons 90 (length Lv))
                           (cons 70 (if (vlax-curve-IsClosed obj) 1 0))
                           (cons 43 0.0)
                       )
                       (mapcar '(lambda (x) (cons 10 x)) Lv)
                   )
               )
           )
       )
       (progn
           (setq EL (entlast))
           (vl-cmdf "_offset" d_o PL2 p_of "")
           (if (and
                   (/= EL (setq PL3 (entlast)))
                   (= (setq n_of (length (setq obj_of (e_next EL "LS")))) 1)
               )
               (progn
                   (setq Lv2 nil)
                   (setq Lv1 (pl_coord PL3)) 
                   (entdel PL2)
                   (entdel PL3)    
                   (mapcar
                       '(lambda ( a b )
                            (setq Lv2 (cons (list (car b) (cadr b) (+ d_z (caddr a))) Lv2))
                        )
                        Lv Lv1
                   )
                   (setq Lv2 (reverse Lv2))
                   (entmake
                       (list
                           '(0 . "POLYLINE")
                           '(10 0.0 0.0 0.0)
                           (assoc 8 (entget obj))
                           (assoc 70 (entget obj))
                       )
                   )
                   (repeat (length Lv2)
                       (entmake
                           (list
                               (cons 0 "VERTEX")
                               (cons 10 (CAR Lv2))
                               (cons 70 32)
                           )
                       )
                       (setq Lv2 (cdr Lv2))
                   )
                   (entmake '((0 . "SEQEND")))
                   t
               )
               (progn
                   (entdel PL2)
                   (if (> n_of 1)
                       (repeat n_of
                           (entdel (car obj_of))
                           (setq obj_of (cdr obj_of))
                       )
                   )
                   nil
               )
           )
       )
   )
)
;***********************************************************;

(defun pl_coord (# / p m)
   (setq p (if (vlax-curve-IsClosed #)
               (fix (vlax-curve-getEndParam #))
               (1+ (fix (vlax-curve-getEndParam #)))
           )
   )
   (while (/= 0 p)
       (setq m (cons (vlax-curve-getPointAtParam # (setq p (1- p))) m))
   )
)
;***********************************************************;

(defun e_next (entL mode / next)
   (if (= mode "SS") (setq next (ssadd)))
   (if (/= entL (entlast))
       (while (setq entL (entnext entL))
           (if (entget entL)
               (cond
                   ( (= mode "LS") (setq next (cons entL next)) )
                   ( (= mode "SS") (setq next (ssadd entL next)) )
               )
           )
       )
   )
   next
)

(vl-load-com)
;***********************************************************;

 

Link to comment
Share on other sites

On 10/11/2021 at 4:48 PM, lrm said:

 How do you define zero twist? Is your goal to keep two of the side of the square profile parallel to the world XY plane?  In the image below the red line is a 3DPOLY that has vertices of changing x, y, and z coordinates. The white shape used sweep and a square.  The yellow shape has its square cross sections with two side always parallel to the XY plane.  It was constructed by position boxes end to end with rotations about axes parallel to the XY plane.

 image.thumb.png.b170256902bf90c016fbc4972ab724f3.png

image.thumb.png.d4da1ae2964edf71af533b859ad61795.png

 

After unioning the boxes together it looks like this.

image.png.c3f8f5ff245c5dad76a13c5b6ff463c3.png

 

Is this what you want?

 

 

Thx for the asnwer. It seems good but I do not understand how to create the box on the 3dpoly like u did. is there a chance u can elaborate or refer me to a tutorial?

 

 

On 10/11/2021 at 9:04 PM, hosneyalaa said:

 

  https://www.cadtutor.net/forum/topic/53442-offseting-3d-polyline/?fbclid=IwAR2FxiJzbQH7Z0hG4PaoiT5XHvXYek-MvV30jpfPyQYXyTWeGfhhKjF_9hk

 

 


; Offset a 3dPoly with horizontal and vertical distances
; 15 August 2014 - Gian Paolo Cattaneo 
 
(defun c:o3 ( / *error* 3dp p ogt)
   (defun *error* ( msg )
       (setvar 'offsetgaptype ogt)
       (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))        
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
   (setq ogt (getvar 'offsetgaptype))
   (setvar 'offsetgaptype 0)
   (or op (setq op 0.00))
   (or oz (setq oz 0.00))
   (while
       (progn
           (setq 3dp (car (entsel "\nSelect the 3D polyline to offset")))
           (if (not (eq "AcDb3dPolyline" (vlax-get (vlax-ename->vla-object 3dp) 'ObjectName)))
               (progn
                   (alert "This is not a 3D Polyline")
                   t
               )
           )
       )
   )
   (if 3dp
       (progn
           (while
               (progn
                   (initget (+ 2 4))
                   (setq op
                       (cond
                           ( (getdist (strcat "\nOffset Distance (horizontal)  <" (rtos op 2 2)">: ")) )
                           ( op )
                       )
                   )
                   (if (= op 0.)
                       (progn
                           (alert "The horizontal offset distance must be greater than zero")
                           t
                       )
                   )
               )
           )
           (setq oz
               (cond
                   ( (getdist (strcat "\nOffset Distance (vertical)    <" (rtos oz 2 2)">: ")) )
                   ( oz )
               )
           )
           (setq p (getpoint "\nSpecify point on side to offset "))
           (off3DP 3dp op oz p)
       )
   )
   (setvar 'offsetgaptype ogt)
   (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
   (princ)
)

;******************* Offset 3D Polyline ********************;
;                                                           ;
;  obj   [ENAME] - entity name                              ;
;  d_o   [REAL]  - horizontal offset distance               ;
;  d_z   [REAL]  - vertical offset distance                 ;
;  p_of  
;[list]  - point on side to offset                  ;
;                                                           ;
; ----------------------------------------------------------;
; (off3DP (car (entsel)) 2.15 -2.00 '(3 4 0))               ;
; ----------------------------------------------------------;
; author: Gian Paolo Cattaneo - 30.03.2013                  ;
;***********************************************************;
(defun off3DP ( obj d_o d_z p_of / EL Lv PL2 PL3 Lv Lv1 Lv2 n_of obj_of)
   (if
       (and
           (eq "AcDb3dPolyline" (vlax-get (vlax-ename->vla-object obj) 'ObjectName))
           (setq Lv (pl_coord obj))
           (setq PL2
               (entmakex
                   (append
                       (list
                           (cons 0 "LWPOLYLINE")
                           (cons 100 "AcDbEntity")
                           (cons 100 "AcDbPolyline")
                           (cons 90 (length Lv))
                           (cons 70 (if (vlax-curve-IsClosed obj) 1 0))
                           (cons 43 0.0)
                       )
                       (mapcar '(lambda (x) (cons 10 x)) Lv)
                   )
               )
           )
       )
       (progn
           (setq EL (entlast))
           (vl-cmdf "_offset" d_o PL2 p_of "")
           (if (and
                   (/= EL (setq PL3 (entlast)))
                   (= (setq n_of (length (setq obj_of (e_next EL "LS")))) 1)
               )
               (progn
                   (setq Lv2 nil)
                   (setq Lv1 (pl_coord PL3)) 
                   (entdel PL2)
                   (entdel PL3)    
                   (mapcar
                       '(lambda ( a b )
                            (setq Lv2 (cons (list (car b) (cadr b) (+ d_z (caddr a))) Lv2))
                        )
                        Lv Lv1
                   )
                   (setq Lv2 (reverse Lv2))
                   (entmake
                       (list
                           '(0 . "POLYLINE")
                           '(10 0.0 0.0 0.0)
                           (assoc 8 (entget obj))
                           (assoc 70 (entget obj))
                       )
                   )
                   (repeat (length Lv2)
                       (entmake
                           (list
                               (cons 0 "VERTEX")
                               (cons 10 (CAR Lv2))
                               (cons 70 32)
                           )
                       )
                       (setq Lv2 (cdr Lv2))
                   )
                   (entmake '((0 . "SEQEND")))
                   t
               )
               (progn
                   (entdel PL2)
                   (if (> n_of 1)
                       (repeat n_of
                           (entdel (car obj_of))
                           (setq obj_of (cdr obj_of))
                       )
                   )
                   nil
               )
           )
       )
   )
)
;***********************************************************;

(defun pl_coord (# / p m)
   (setq p (if (vlax-curve-IsClosed #)
               (fix (vlax-curve-getEndParam #))
               (1+ (fix (vlax-curve-getEndParam #)))
           )
   )
   (while (/= 0 p)
       (setq m (cons (vlax-curve-getPointAtParam # (setq p (1- p))) m))
   )
)
;***********************************************************;

(defun e_next (entL mode / next)
   (if (= mode "SS") (setq next (ssadd)))
   (if (/= entL (entlast))
       (while (setq entL (entnext entL))
           (if (entget entL)
               (cond
                   ( (= mode "LS") (setq next (cons entL next)) )
                   ( (= mode "SS") (setq next (ssadd entL next)) )
               )
           )
       )
   )
   next
)

(vl-load-com)
;***********************************************************;

 

 

I think thats the lisp i tried using, it doesnt really offsets a 3dpoly, anyways it breaks and doesnt function well when the line intersects with itself making the offsetted line be different than the original.

Link to comment
Share on other sites

  • Mugna101 changed the title to [REQUEST] offsetting 3dpoly autolisp OR drawing 2 parallel 3Dpoly at the same time (like MLine)

I think need to explode and offset, then work out the new IP point and reset the 2 end points, as you can not fillet, then join ?

 

image.png.255a9e11b55c3da7dc8d09d2a36bbbfb.png

 

Now where is my sin cos. Ah yeah pt Z changes must do second sin cos.

Edited by BIGAL
Link to comment
Share on other sites

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