Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
rakesh_rao
Posts: 30
Registered: ‎01-14-2005
Message 11 of 25 (349 Views)

Re: Help with exporting point locations to text file

06-10-2012 08:48 PM in reply to: Cadastrophe1911

 

Hello,

 

Two solutions::

 

Solution 1: If you are a Lisp programmer and need help, look at our FREE resources on TechCenter:

 

This is the link: http:///www.4d-technologies.com/techcenter

 

There are a bunch of routines there under various library headings which you can use to export XYZ data into a text file, manage objects, retrieve information like coordinates etc etc.

 

Look at the LSP and if you need help, send me a message.

 

Solution 2: Alternatively, if you are looking at a ready-made solution, you may try our CADPower CP_IMPEX command

 

http://www.4d-technologies.com/cadpower/manual/export_tools.htm#IMPEX

 

You can try it fully functional for 30 days.

 

Regards
Rakesh

http://rakeshrao.typepad.com
http://www.coordsys.com
http://www.4d-technologies.com

- rakesh.rao@4d-technologies.com
- www.4d-technologies.com / www.coordsys.com
- Blog:EN: http://rakeshrao.typepad.com
- Blog: ES: http://kiranabhat.typepad.com
Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 12 of 25 (337 Views)

Re: Help with exporting point locations to text file

06-11-2012 10:58 AM in reply to: devitg

File has loaded and is exporting point locations, however, when i open the text file the locations are not the same as then ones in the cad file. Would moving my origin effect this??? Normally what I do is move my origin to the zero corner and then place the points in the drawing??? Also, how do I change the precision of the numbers it exports. Thanks again

*Expert Elite*
Kent1Cooper
Posts: 5,879
Registered: ‎09-13-2004
Message 13 of 25 (333 Views)

Re: Help with exporting point locations to text file

06-11-2012 12:03 PM in reply to: Cadastrophe1911

Cadastrophe1911 wrote:

File has loaded and is exporting point locations, however, when i open the text file the locations are not the same as then ones in the cad file. Would moving my origin effect this??? Normally what I do is move my origin to the zero corner and then place the points in the drawing??? Also, how do I change the precision of the numbers it exports. Thanks again


If you're talking about my suggested routine, I would guess that you're in some non-World Coordinate System.  The coordinates in the entity data for each Point (which is what the routine uses) will be in WCS terms, no matter what your current UCS.  But what you'll see as locations if you pick something is displayed in the current UCS.  So yes, you should set the Coordinate System to World, and if necessary, move everything from whatever you want the origin to be in relation to the points, to 0,0.  Alternatively, you can use (trans) to convert them -- write back if you'd rather do that and not change the UCS.

 

The precision of the numbers is controlled by the last number in the (rtos) functions [2 in both of them as I posted it, = 2 decimal places] -- see (rtos) in the AutoLISP Reference [you can also change the type of units to something other than decimal, if you want].  If you want whole numbers only, you can replace those last 2's with 0's [it will round things to the nearest integer value].  It turns out you can't use (itoa) for that -- it won't accept real numbers as input, but all Point location coordinates will be real numbers.

Kent Cooper
Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 14 of 25 (324 Views)

Re: Help with exporting point locations to text file

06-11-2012 12:15 PM in reply to: Kent1Cooper

Is there anyway I can make it work off of the UCS location???

*Expert Elite*
Kent1Cooper
Posts: 5,879
Registered: ‎09-13-2004
Message 15 of 25 (319 Views)

Re: Help with exporting point locations to text file

06-11-2012 12:23 PM in reply to: Cadastrophe1911

Cadastrophe1911 wrote:

Is there anyway I can make it work off of the UCS location???



Yes.  Replace this:

 

      (rtos (car x) 2 2) "\t" ; X coordinate <--- edit precision

      (rtos (cadr x) 2 2); Y coordinate <--- edit precision

 

with this:

 

      (trans (rtos (car x) 2 2) 0 1) "\t" ; X coordinate <--- edit precision

      (trans (rtos (cadr x) 2 2) 0 1); Y coordinate <--- edit precision
 

The 0 means to translate from World Coordinates; the 1 means to current coordinates.

Kent Cooper
Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 16 of 25 (313 Views)

Re: Help with exporting point locations to text file

06-11-2012 12:46 PM in reply to: Kent1Cooper

Command:
Command: _appload drill20.LSP successfully loaded.


Command:
Command:
Command: drill20
; error: bad argument type: 2D/3D point: "29.31"

Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 17 of 25 (312 Views)

Re: Help with exporting point locations to text file

06-11-2012 12:48 PM in reply to: Cadastrophe1911

I am using the move origin command with points set at 0,0   .5000, 2.1875       and 2.1875, .5000

Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 18 of 25 (306 Views)

Re: Help with exporting point locations to text file

06-11-2012 01:21 PM in reply to: Cadastrophe1911

defun C:drill20 (/ ptfile inc ptlist);
 
  (setq
  ptfile (open "C:/TEMP/PTFILE.TXT" "w"); <---- edit file path & name
  inc 0
  ptlist
    (mapcar
      '(lambda (x) (cdr (assoc 10 (entget x)))); Point locations
      (mapcar 'cadr (ssnamex (ssget "_X" '((0 . "POINT"))))); all Point entities in drawing
    ); mapcar & ptlist
); setq
(write-line "Units\tInch" ptfile)
(foreach x ptlist
  (write-line
    (strcat
      "WPT\t"
      (itoa (setq inc (1+ inc))) "\t"
      (trans (rtos (car x) 2 4) 0 1) "\t" ; X coordinate <--- edit precision
      (trans (rtos (cadr x) 2 4) 0 1); Y coordinate <--- edit precision
    ); strcat
    ptfile
  )
)


  (close ptfile)

); end defun

 

*Expert Elite*
Kent1Cooper
Posts: 5,879
Registered: ‎09-13-2004
Message 19 of 25 (298 Views)

Re: Help with exporting point locations to text file

06-11-2012 01:40 PM in reply to: Cadastrophe1911

Cadastrophe1911 wrote:

defun C:drill20 (/ ptfile inc ptlist);
.... 


I take it that's the format that does what you want [with, of course, the missing-here but requisite opening left parenthesis at the very beginning...].  If so, you could now remove all the " <---- edit ..." commentaries.  And there are other things you could do if you choose, such as have it alert the User if there are no Points in the drawing, and/or exit quietly with a (princ) just before the final closing right parenthesis so it doesn't put 'nil' on the Command: prompt line for inexperienced Users to be confused by.

Kent Cooper
Contributor
Cadastrophe1911
Posts: 13
Registered: ‎06-08-2012
Message 20 of 25 (292 Views)

Re: Help with exporting point locations to text file

06-11-2012 02:13 PM in reply to: Kent1Cooper

Why am i getting this error

 

Command:
Command: _appload drill20.LSP successfully loaded.


Command:
Command:
Command: drill20
; error: bad argument type: 2D/3D point: "29.31"

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.