Author Topic: 3dpoly projected onto the plane of the current UCS  (Read 1994 times)

0 Members and 1 Guest are viewing this topic.

mariolino0099

  • Newt
  • Posts: 25
3dpoly projected onto the plane of the current UCS
« on: March 02, 2023, 09:59:46 AM »
i have a problem, as with the flatten command i need to project 3dpoly onto the current UCS.
As you can see in the following picture, the 3dpoly in cyan must be projected onto the current UCS, the result must be like the green 3dpoly (the red line is only for generating the UCS).




At this link I found the following code:
https://www.cadtutor.net/forum/topic/62788-get-ucs-coordinates-of-a-3d-polyline/


the following code collects the vertex coordinates in local coordinates of the UCS and then exports them to file, I would need help to reset the z coordinates of the L list (in local coordinates) then reproject them into the WCS system and replace the original coordinates.... who can help me ?


; Pline's vertices to txt file
(defun C:test ( / LM:group-n SS i o e L fp opn )
 
 ;; Group by Number  -  Lee Mac
 ;; Groups a list 'l' into a list of lists, each of length 'n'
 
 (defun LM:group-n ( l n / r )
   (if l
     (cons
       (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
       (LM:group-n l n)
     )
   )
 )
 (cond
   (
     (not
       (progn
         (setq SS (ssget '((0 . "*POLYLINE"))))
         (repeat (setq i (sslength SS))
           (setq o (vlax-ename->vla-object (setq e (ssname SS (setq i (1- i))))))
           (if (vlax-property-available-p o 'Coordinates)
             (setq L (cons (cons (cdr (assoc 210 (entget e))) (LM:group-n (vlax-get o 'Coordinates) 3)) L))
           )
         ); repeat
         L
       )
     )
     (princ "\nInvalid objects selected.")
   )
   ( (not (setq fp (getfiled "Create vertices data" "" "txt" 1)))
     (princ "\nText file not specified.")
   )
   ( (setq opn (open fp "w"))
     (princ "X \tY \tZ" opn)
     (mapcar
       '(lambda (a b)
         (mapcar
           '(lambda (x)
             (princ
               (strcat "\n"
                 (vl-string-left-trim "\t"
                   (vl-string-right-trim ", "
                     (apply 'strcat (mapcar '(lambda (n) (strcat "\t" (rtos n 2 2) ", ")) (trans x a 1)))
                   )
                 )
               )
               opn
             )
           )
           b
         )
       )
       (mapcar 'car L)
       (mapcar 'cdr L)
     )
     (close opn)
     (initget "Yes No")
     (if (= "Yes" (cond ((getkword "\nDo you want to open the file? [Yes/No] <Yes>: ")) ("Yes")))
       (startapp "explorer" fp)
     )
   )
 ); cond
 (princ)
);| defun |; (vl-load-com) (princ)

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: 3dpoly projected onto the plane of the current UCS
« Reply #1 on: March 02, 2023, 10:38:39 AM »
Create very large REGION on current UCS and just use command PROJECTGEOMETRY with 3dpolylines and region...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mariolino0099

  • Newt
  • Posts: 25
Re: 3dpoly projected onto the plane of the current UCS
« Reply #2 on: March 03, 2023, 08:59:21 AM »
it works, thank you !
But the workflow when there are many 3dpoly is not particularly fast.... An idea to make it faster in lisp ?


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: 3dpoly projected onto the plane of the current UCS
« Reply #3 on: March 04, 2023, 02:37:44 AM »
Hi,

You can try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun projectPointOnUcsPlane (pt)
  2.   (setq pt (trans pt 0 1))
  3.   (list (car pt) (cadr pt) 0.)
  4. )
  5.  
  6. (defun getVertices (pline / param points)
  7.   (setq param (if (vlax-curve-IsClosed pline)
  8.                 (1- (fix (vlax-curve-getEndParam pline)))
  9.                 (fix (vlax-curve-getEndParam pline))
  10.               )
  11.   )
  12.   (while (<= 0 param)
  13.     (setq points (cons (vlax-curve-getPointAtParam pline param) points)
  14.           param  (1- param)
  15.     )
  16.   )
  17.   points
  18. )
  19.  
  20. (defun projectPoly3dOnUcsPlane (poly3d / points ucsDir)
  21.   (setq points (mapcar 'projectPointOnUcsPlane (getVertices poly3d))
  22.         ucsdir (trans '(0. 0. 1.) 1 0 T)
  23.   )
  24.     (append
  25.       (list
  26.         (cons 0 "LWPOLYLINE")
  27.         (cons 100 "AcDbEntity")
  28.         (cons 100 "AcDbPolyline")
  29.         (cons 90 (length points))
  30.         (cons 70
  31.               (if (vlax-curve-IsClosed poly3d)
  32.                 1
  33.                 0
  34.               )
  35.         )
  36.         (cons 38 (- (caddr (trans '(0. 0. 0.) 0 1))))
  37.         (cons 210 ucsdir)
  38.       )
  39.       (mapcar '(lambda (p) (cons 10 (trans p 1 ucsdir))) points)
  40.     )
  41.   )
  42. )
  43.  
  44. (defun c:PROJPOLY3D (/ ss i)
  45.   (if (setq ss (ssget '((0 . "POLYLINE") (-4 . "&") (70 . 8))))
  46.     (repeat (setq i (sslength ss))
  47.       (projectPoly3dOnUcsPlane (ssname ss (setq i (1- i))))
  48.     )
  49.   )
  50.   (princ)
  51. )
Speaking English as a French Frog

mariolino0099

  • Newt
  • Posts: 25
Re: 3dpoly projected onto the plane of the current UCS
« Reply #4 on: March 04, 2023, 03:58:07 AM »
thanks Gile,
great solution, it works exactly as needed and is very functional !!!
Many thanks !!!  :smitten:

xdcad

  • Bull Frog
  • Posts: 486
Re: 3dpoly projected onto the plane of the current UCS
« Reply #5 on: November 24, 2023, 03:15:28 AM »
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. Get the Z axis of UCS
  3. Parameters: none
  4. Return value: vector
  5. |;
  6. (defun XD::UCS:zDir()
  7.    (xdrx_vector_crossProduct (getvar "ucsxdir") (getvar "ucsydir"))
  8. )
  9. (defun XD::Project->UCSPLANE (ss / plane g g1 e1)
  10.   (setq plane (xdge::constructor
  11.                 "kPlane"
  12.                 (getvar "ucsorg")
  13.                 (XD::UCS:zDir)
  14.               )
  15.   )
  16.   ;Coordinate UCS PLANE AcGe kPlane
  17.   (mapcar '(lambda (x)
  18.              (setq g (xdge::constructor x))
  19.   ; Generate AcGe curve from AcDb curve
  20.              (setq g1 (xdge::getpropertyvalue g "orthoproject" plane))
  21.   ;Geometric curves are orthogonally projected onto the plane plane
  22.              (setq e1 (xdge::entity:make g1))
  23.   ;Generate entity after projection
  24.              (xdrx-entity-matchprop x e1)
  25.   ;The entity attributes match the original curve, color, layer, linetype....
  26.              (xdrx-object-swapid e1 x)
  27.   ;Entity ObjectId exchange to ensure that the newly generated curve entity name remains unchanged
  28.              (xdrx-entity-delete e1)
  29.   ;Delete the original curve
  30.              (xdrx-object-release g)
  31.   ;Geometric curve entities release memory
  32.            )
  33.           (xdrx-pickset->ents ss)
  34.   ;Select set to entity table
  35.   )
  36.   (xdge::free plane)
  37.   ;Geometry plane object releases memory
  38.   ss
  39. )
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net