Jump to content

Recommended Posts

Posted

How can I export control point of a spline into a txt file?

Posted

Try this:

 

(defun c:spex (/ *error* lst->str GroupByNum f oFile ss sLst)
 (vl-load-com)
 ;; Lee Mac  ~  17.04.10

 (defun *error* (msg)
   (and ofile (close ofile))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (defun lst->str (lst del)
   (if (cdr lst)
     (strcat (car lst) del (lst->str (cdr lst) del))
     (car lst)))

 (defun GroupByNum (lst num / rtn)
   (setq rtn nil)
   
   (if lst
     (cons (reverse
             (repeat num
               (progn
                 (setq rtn (cons (car lst) rtn)
                       lst (cdr lst))
                 rtn)))

           (GroupByNum lst num)))) 

 (if (and (ssget '((0 . "SPLINE")))
          (setq f (getfiled "Choose Output File" "" "txt;csv" 1)))
   (progn      
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet
                              (vla-get-ActiveDocument (vlax-get-acad-object))))        
       (setq sLst (cons (GroupByNum (vlax-get obj 'ControlPoints) 3) sLst)))
     (vla-delete ss)

     (vlp sLst)

     (setq ofile (open f "w"))
     (mapcar
       (function
         (lambda ( spline )
           (write-line
             (lst->str
               (mapcar
                 (function
                   (lambda ( control )
                     (lst->str
                       (mapcar (function rtos) control) ","
                     )
                   )
                 )
                 spline
               )
              "\t\t"
             )
             ofile
           )
         )
       )
       sLst
     )        
     (setq ofile (close ofile))))

 (princ))

  • 3 years later...
Posted

Hi Lee Mac, i tried to use your lsp routine and all goes right, it asks me to select the object(spline) then save my file with a name but when i save it, it tells me at the command bar :** Error: no function definition: VLP ** I also want to add that i use autocad architecture, is that the problem or something else happening?? Could you please inform me or someone else could? I would appriciate it, thank you.

Posted

Sorry, that is extremely old code and the 'vlp' expression should not be present.

 

Please try this updated code instead:

[color=GREEN];; Spline Export  -  Lee Mac[/color]
([color=BLUE]defun[/color] c:spex ( [color=BLUE]/[/color] f i s )
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"SPLINE"[/color]))))
           ([color=BLUE]setq[/color] f ([color=BLUE]getfiled[/color] [color=MAROON]"Output File"[/color] [color=MAROON]""[/color] [color=MAROON]"txt"[/color] 1))
           ([color=BLUE]setq[/color] f ([color=BLUE]open[/color] f [color=MAROON]"w"[/color]))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))
               ([color=BLUE]write-line[/color]
                   (lst2str
                       ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) (lst2str ([color=BLUE]mapcar[/color] '[color=BLUE]rtos[/color] x) [color=MAROON]","[/color]))
                           (group3 ([color=BLUE]vlax-get[/color] ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))) 'controlpoints))
                       )
                       [color=MAROON]"\t"[/color]
                   )
                   f
               )
           )
           ([color=BLUE]close[/color] f)
       )
   )
   ([color=BLUE]princ[/color])
)

([color=BLUE]defun[/color] group3 ( l [color=BLUE]/[/color] r )
   ([color=BLUE]repeat[/color] ([color=BLUE]/[/color] ([color=BLUE]length[/color] l) 3)
       ([color=BLUE]setq[/color] r ([color=BLUE]cons[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] l '(0 0 0)) r)
             l ([color=BLUE]cdddr[/color] l)
       )
   )
   ([color=BLUE]reverse[/color] r)
)
([color=BLUE]defun[/color] lst2str ( l d )
   ([color=BLUE]if[/color] ([color=BLUE]cdr[/color] l)
       ([color=BLUE]strcat[/color] ([color=BLUE]car[/color] l) d (lst2str ([color=BLUE]cdr[/color] l) d))
       ([color=BLUE]car[/color] l)
   )
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Posted

Thank you very much Lee Mac now everything works fine!!!! I would also like to ask if it is generally possible to view the control points of an ordinary object 2d or 3d for example a circle or a rundom shape, because i can view the control points only for spline objects.Thank you again!!

Posted

I also forgot to ask you if it is possible with a lisp routine to export not only the coordinates of the control points but also the weight of each control point?

Posted
if it is possible with a lisp routine to export not only the coordinates of the control points but also the weight of each control point?

 

The following program will export each spline control point in the following format:

 

,,,

[color=GREEN];; Spline Export  -  Lee Mac[/color]
([color=BLUE]defun[/color] c:spex ( [color=BLUE]/[/color] f i l s w )
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] s ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"SPLINE"[/color]))))
           ([color=BLUE]setq[/color] f ([color=BLUE]getfiled[/color] [color=MAROON]"Output File"[/color] [color=MAROON]""[/color] [color=MAROON]"txt"[/color] 1))
           ([color=BLUE]setq[/color] f ([color=BLUE]open[/color] f [color=MAROON]"w"[/color]))
       )
       ([color=BLUE]progn[/color]
           ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] s))
               ([color=BLUE]setq[/color] o ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] s ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i))))
                     l (group3 ([color=BLUE]vlax-get[/color] o 'controlpoints))
               )
               ([color=BLUE]write-line[/color]
                   (lst2str
                       ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) (lst2str ([color=BLUE]mapcar[/color] '[color=BLUE]rtos[/color] x) [color=MAROON]","[/color]))
                           ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]setq[/color] w ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vlax-get[/color] ([color=BLUE]list[/color] o 'weights)))))
                               ([color=BLUE]mapcar[/color] '[color=BLUE]cons[/color] w l)
                               l
                           )
                       )
                       [color=MAROON]"\t"[/color]
                   )
                   f
               )
           )
           ([color=BLUE]close[/color] f)
       )
   )
   ([color=BLUE]princ[/color])
)

([color=BLUE]defun[/color] group3 ( l [color=BLUE]/[/color] r )
   ([color=BLUE]repeat[/color] ([color=BLUE]/[/color] ([color=BLUE]length[/color] l) 3)
       ([color=BLUE]setq[/color] r ([color=BLUE]cons[/color] ([color=BLUE]mapcar[/color] '[color=BLUE]+[/color] l '(0 0 0)) r)
             l ([color=BLUE]cdddr[/color] l)
       )
   )
   ([color=BLUE]reverse[/color] r)
)
([color=BLUE]defun[/color] lst2str ( l d )
   ([color=BLUE]if[/color] ([color=BLUE]cdr[/color] l)
       ([color=BLUE]strcat[/color] ([color=BLUE]car[/color] l) d (lst2str ([color=BLUE]cdr[/color] l) d))
       ([color=BLUE]car[/color] l)
   )
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Posted

Thank you once again Lee Mac for your help!!

Posted

Lee Mac i would like to inform you that i found the answer in my previous question, on how we can view the control points of a 3d surface or object but to do that i must turn my surface or the object to NURBS surface. If you have Autocad Civil 3d you can check it yourself by going to ''workspace switcing'' and choosing 3d modeling. Then at the ''Surface tab'' you choose ''cv on''. I was wondering if there is also a lisp routine capable to export the control points of NURBS surfaces and generally objects? I would appriciate your help.

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