3d poly -> rectangle

3d poly -> rectangle

BB8x
Advocate Advocate
1,266 Views
9 Replies
Message 1 of 10

3d poly -> rectangle

BB8x
Advocate
Advocate

Hello

 

I do have 3d poly. Important is FIRST and LAST point of this poly. I need rectangle with key-ined width using first and last point as a base.

 

I would see it like this:

Create line from first and last point of poly

Offset line left and right for half key-ined offset

Close 2 offseted lines and create rectangle (as a 3d poly)

Delete base 3d poly

 

I do have lisp to draw rectangle with key-ined width, but I need to click beginning and end. It works for few elements. I need to so several hundred every week

 

0 Likes
Accepted solutions (1)
1,267 Views
9 Replies
Replies (9)
Message 2 of 10

CodeDing
Advisor
Advisor

@BB8x ,

 

Since a 3D polyline can start and end at different elevations, does your final polyline ALSO need to start and end at those same elevations? Or can the elevation of the final polyline be 0?

 

Best,

~DD

0 Likes
Message 3 of 10

BB8x
Advocate
Advocate

Same elevations please. It is 3d drawing

0 Likes
Message 4 of 10

CodeDing
Advisor
Advisor

@BB8x ,

 

Then in what direction is the view for the 'width' of the final 3dPoly?

 

Can we just make a cylinder? This would accomplish the same width of a 2-segment polyline in ALL views..

Because if we create a planar offset of a polyline, then what is the purpose of a 'width' if it couldn't be seen from other views?

 

For example.. Here I have a top-down view and I can see my offsets..

image.png

...but here, I have a side view, and I cannot see my offsets...

image.png

So from what direction does the 'width' need to be seen from?

0 Likes
Message 5 of 10

BB8x
Advocate
Advocate

It has to be rectangle I am afraid. Seen good from top view, but rectangle.

 

For clarification: I want select lets say 100 3d polylines and same time, not click one by one

 

This is what I am using. You could use this for building rectangle

 

(defun C:DL (/ s e o d f v l x r -r3p)
(defun -r3p (Pts / l p o)
(setq l (apply 'append (mapcar 'append Pts)))
(setq p (vlax-make-safearray
vlax-vbDouble (cons 0 (1- (length l)))))
(vlax-safearray-fill p l)
(setq o (vla-Add3DPoly (cd:ACX_ASpace) p))
(vla-put-Closed o :vlax-true)
(vlax-vla-object->ename o)
)
(initget "Change")
(setq s
(getpoint
(strcat "\current width ("
(cd:CON_Real2Str *X* 2 nil)
") [Change] or 1st point: "))
)
(if s
(cond
( (= s "Change")
(initget (+ 1 2 4))
(setq x (getdist
"\new width: "))
(if x
(progn
(setq *X* x)
(C:DL)
)
(princ "\cancelled. ")
)
)
( (and (listp s)(= 3 (length s)))
(if
(setq e (getpoint s "\2nd point: "))
(progn
(setq d (/ *X* 2.0)
o (cd:ENT_MakeLine (getvar "CTAB") s e T)
v (vlax-ename->vla-object o)
)
(cd:SYS_UndoBegin)
(vla-offset v d)
(setq f (entlast))
(vla-offset v (* -1 d))
(setq l (entlast)
r (list
(cdr (assoc 10 (entget f)))
(cdr (assoc 11 (entget f)))
(cdr (assoc 11 (entget l)))
(cdr (assoc 10 (entget l)))
)
)
(-r3p r)
(foreach % (list f l o)(entdel %))
(cd:SYS_UndoEnd)
)
(princ "\cancelled. ")
)
)
(t (princ "\cancelled. "))
)
(princ "\cancelled. ")
)
(princ)
)
; --------------------------------------------------------------- ;
(princ)

Message 6 of 10

CodeDing
Advisor
Advisor

@BB8x ,

 

I'm not 100% on creating 3D objects yet in Lisp. I'll have to do some researching and get back with you.

Sorry I can't get you something today, but hopefully this week I can.

 

Best,

~DD

0 Likes
Message 7 of 10

BB8x
Advocate
Advocate

No worries. Been doing click by click for 2 years, can wait bit more 🙂

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

If I understand correctly, something like this?

(defun C:3DPRE2E ; = 3DPolyline Rectangle End {to} End
  (/ ss wid n 3dpl end1 end2 ang)
  (if
    (and
      (setq ss (ssget '((0 . "POLYLINE") (-4 . "&") (70 . 8))))
      (setq wid (getdist "\nWidth of 3DPolyline rectangles from starts to ends: "))
    ); and
    (repeat (setq n (sslength ss)); then
      (setq
        3dpl (ssname ss (setq n (1- n)))
        end1 (vlax-curve-getStartPoint 3dpl)
        end2 (vlax-curve-getEndPoint 3dpl)
        ang (angle end1 end2); in XY plane
      ); setq
      (command "_.3dpoly"
        "_non" (polar end1 (+ ang (/ pi 2)) (/ wid 2))
        "_non" (polar end1 (- ang (/ pi 2)) (/ wid 2))
        "_non" (polar end2 (- ang (/ pi 2)) (/ wid 2))
        "_non" (polar end2 (+ ang (/ pi 2)) (/ wid 2))
        "_close"
      ); command
    ); repeat
  ); if
  (princ)
); defun

Minimally tested.  It could be made to remember your width and offer it as default on subsequent use, and of course could have all the usual features added [command-echo suppression, overall instead of one-at-a-time Osnap control, draw on a specific Layer or on the Layer of each source object, error handling if anything is changed that should be reset, etc., etc.].

Kent Cooper, AIA
0 Likes
Message 9 of 10

BB8x
Advocate
Advocate

Checked few times and works good.

 

Can you please add deleting base 3d poly?

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@BB8x wrote:

Checked few times and works good.

 

Can you please add deleting base 3d poly?


(defun C:3DPRE2E ; = 3DPolyline Rectangle End {to} End
  (/ ss wid n 3dpl end1 end2 ang)
  (if
    (and
      (setq ss (ssget '((0 . "POLYLINE") (-4 . "&") (70 . 8))))
      (setq wid (getdist "\nWidth of 3DPolyline rectangles from starts to ends: "))
    ); and
    (repeat (setq n (sslength ss)); then
      (setq
        3dpl (ssname ss (setq n (1- n)))
        end1 (vlax-curve-getStartPoint 3dpl)
        end2 (vlax-curve-getEndPoint 3dpl)
        ang (angle end1 end2); in XY plane
      ); setq
      (command "_.3dpoly"
        "_non" (polar end1 (+ ang (/ pi 2)) (/ wid 2))
        "_non" (polar end1 (- ang (/ pi 2)) (/ wid 2))
        "_non" (polar end2 (- ang (/ pi 2)) (/ wid 2))
        "_non" (polar end2 (+ ang (/ pi 2)) (/ wid 2))
        "_close"
      ); command
      (entdel 3dpl)
    ); repeat
  ); if
  (princ)
); defun

Or it could be done with an Erase command inside that already-running (command) function:

....
        "_non" (polar end2 (+ ang (/ pi 2)) (/ wid 2))
        "_close"
        "_.erase" 3dpl ""
      ); command
    ); repeat
....

With a huge enough number of them, you might possibly notice a small increase in the time it takes to do it that way [because (command) operations can take a hair longer than other ways of doing things], but maybe not if the (command) is already going.  And in any case, the difference would be in something like a few milliseconds per Polyline, so it would need to be a lot before you'd notice.

Kent Cooper, AIA
0 Likes