Jump to content

Get UCS coordinates of a 3D Polyline


GerIng

Recommended Posts

Hallo CadTutors,

 

 

I am a bloody beginner in Lisp programming and i would need a way to get this to work for 3d-Polylines.

 

 

Basically it should give me the current UCS coordinates of every Point on this Polyline.

 

 

The Problem is, I just learnd how to do stuff like this in 2D, not 3D...

 

 

 

 

Thanks

Link to comment
Share on other sites

Oh, I Forget the file I have so far.... sorry

Ist just a classic ptexport file

 

 

 

 

 

 

 

(defun c:ptexport ()

(setq sset (ssget '((-4 . "

(0 . "LWPOLYLINE")(-4 . "OR>"))))

(if sset

(progn

(setq itm 0 num (sslength sset))

(setq fn (getfiled "Point Export File" "" "txt" 1))

(if (/= fn nil)

(progn

(setq fh (open fn "w"))

(while (

(setq hnd (ssname sset itm))

(setq ent (entget hnd))

(setq obj (cdr (assoc 0 ent)))

(cond

((= obj "POINT")

(setq pnt (cdr (assoc 10 ent)))

(setq pnt (trans pnt 0 1));;**CAB

(princ (strcat (rtos (car pnt) 2 8) ","

(rtos (cadr pnt) 2 8) ","

(rtos (caddr pnt) 2 8)) fh)

(princ "\n" fh)

)

((= obj "LWPOLYLINE")

(if (= (cdr (assoc 38 ent)) nil)

(setq elv 0.0)

(setq elv (cdr (assoc 38 ent)))

)

(foreach rec ent

(if (= (car rec) 10)

(progn

(setq pnt (cdr rec))

(setq pnt (trans pnt 0 1));;**CAB

(princ (strcat (rtos (car pnt) 2 8) ","

(rtos (cadr pnt) 2 8) ","

(rtos elv 2 8)) fh)

(princ "\n" fh)

)

)

)

)

(t nil)

)

(setq itm (1+ itm))

)

(close fh)

)

)

)

)

(princ)

)

(princ "\nPoint Export loaded, type PTEXPORT to run.")

(princ)

Link to comment
Share on other sites

Consider the following:

(defun c:ptx ( / d f i n s x z )
   (if (and (setq s (ssget '((0 . "POINT,LWPOLYLINE"))))
            (setq f (getfiled "" "" "txt" 1))
       )
       (if (setq d (open f "w"))
           (progn
               (repeat (setq i (sslength s))
                   (setq x (entget (ssname s (setq i (1- i))))
                         z (cdr (assoc 038 x))
                         n (cdr (assoc 210 x))
                   )
                   (if (= "POINT" (cdr (assoc 0 x)))
                       (write-line (pnt2str (trans (cdr (assoc 10 x)) 0 1)) d)
                       (foreach g x
                           (if (= 10 (car g))
                               (write-line (pnt2str (trans (list (cadr g) (caddr g) z) n 1)) d)
                           )
                       )
                   )
               )
               (close d)
           )
           (princ "\nUnable to open the file for writing.")
       )
   )
   (princ)
)
(defun pnt2str ( p )
   (if (cdr p) (strcat (rtos (car p) 2) "," (pnt2str (cdr p))) (rtos (car p) 2))
)
(princ)

Link to comment
Share on other sites

Thanks for you answer, but I think my question is a bit missunterstanding.

 

 

I dont have actual Points on the 3Dpolyline. What I Need are the Vertices.

 

 

Sorry for that, I´m a Survey engineer so everything is a Point to me ^^

Link to comment
Share on other sites

Just a headsup :

 

LWPOLYLINEs, POINTs and 3DPOLYLINEs are very very different entities. So it is a LWPOLYLINE you are dealing with?

 

POINTs LINEs 3DPOLYLINEs 3DPOLYMESHes all store there points values in 3 axis WCS coordinates.

 

-David

Link to comment
Share on other sites

For a true 3DPOLYLINE, this could work :

 

[b][color=BLACK]([/color][/b]defun c:3dp2ucs [b][color=FUCHSIA]([/color][/b]/ ss en ed vl vn vd wf[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"POLYLINE"[/color][b][color=BLUE])[/color][/b]
                            [b][color=BLUE]([/color][/b]cons -4 [color=#2f4f4f]"&"[/color][b][color=BLUE])[/color][/b]
                             [b][color=BLUE]([/color][/b]cons 70 8[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]= [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b] 1[b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]setq en [b][color=MAROON]([/color][/b]ssname ss 0[b][color=MAROON])[/color][/b]
            ed [b][color=MAROON]([/color][/b]entget en[b][color=MAROON])[/color][/b]
            vn [b][color=MAROON]([/color][/b]entnext en[b][color=MAROON])[/color][/b]
            vd [b][color=MAROON]([/color][/b]entget vn[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]= [color=#2f4f4f]"VERTEX"[/color] [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 0 vd[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq vl [b][color=GREEN]([/color][/b]cons [b][color=BLUE]([/color][/b]trans [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 10 vd[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] 0 1[b][color=BLUE])[/color][/b] vl[b][color=GREEN])[/color][/b]
                   vn [b][color=GREEN]([/color][/b]entnext vn[b][color=GREEN])[/color][/b]
                   vd [b][color=GREEN]([/color][/b]entget vn[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]

      [b][color=NAVY]([/color][/b]setq wf [b][color=MAROON]([/color][/b]open [color=#2f4f4f]"POINT.DAT"[/color] [color=#2f4f4f]"w"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]foreach v [b][color=MAROON]([/color][/b]reverse vl[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]prin1 v wf[b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]write-line [color=#2f4f4f]""[/color] wf[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
      [b][color=NAVY]([/color][/b]close wf[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

 

-David

-3DP.DWG

Link to comment
Share on other sites

Thanks for your fast reply David,

 

 

but i cant get it to create and write in a ucs file.

 

 

It gets ridiculious by now, so I will just ask my Boss to send me to an Seminar for this stuff.

 

 

Thanks guys.

Link to comment
Share on other sites

Heres another - using some list manipulation and visual lisp (after learning from LM's code) :

; 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)

Link to comment
Share on other sites

Thanks for your fast reply David,

 

An drawing example would be helpful I don't know if you can post a file attachment until you have 10 posts. -Davud

Link to comment
Share on other sites

An drawing example would be helpful I don't know if you can post a file attachment until you have 10 posts. -Davud

 

They may post anything, Links are moderated, Images and Files posted to CADTutor via Advanced>Manage Attachments come through with no moderation.

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