Jump to content

Lisp: coordinates of points to excel sheet (+point number)


janwillem89

Recommended Posts

Firs i want to thanks to VVA for the LISP.Great job man you are saving me so much time everyday.

If you have time can u do a little twist to the code for us.

Here is what i suggest:

1.Number and point as block /now they are separated and if u want to delete them when you are done you have to do it twice once delete the number and again delete the point/

2. Show points and number when you select them /now you select point after point and if get distracted miss a point or hit point twice or even forgot where u are you understand this at the end and you have to start all over again in the bed case/.

3.Number and point to be closer /now they are so far from each other/.

4.Scale factor for the text /can put a menu to ask you for the scale factor of the text because if you forgot to do separate layer and when your done you see that your numbers are ridiculously small it takes couple of clicks to make them right or for non advanced users is a little tricky to fix them/

 

Best regards

James R

Link to comment
Share on other sites

1.Number and point as block ...

Change EcoorE to Rev.4

Add command CoorNB

2. Show points and number when you select them ...

sense the above has not yet have understood

3.Number and point to be closer ...

find *ptcol:DELTA* in the code

4.Scale factor for the text /can put a menu to ask you for the scale factor ...

From Menu

^C^CTEXTSIZE;1;COORNB;

or add first line to EcoorE.lsp

(setvar "TEXTSIZE" 1.5);<=Change textsize here

Link to comment
Share on other sites

  • 3 weeks later...

Hi VVA, your Coorn lisp is awesome! Thank you so much for creating this, it's brilliant.

 

I use your program to pull the coordinates from multiple poly-line shapes, and was wondering how I could modify the code to separate the coordinates of each poly-line within the .txt file? I envision separating each shape by adding a space after each block of coordinates in the output .txt file like this:

 

-58.0321,2.3386,.0000

-4.8269,-26.2931,.0000

8.5532,9.7325,.0000

-22.2996,27.6666,.0000

 

-2.7682,9.1090,.0000

-16.7824,14.6167,.0000

-30.1668,7.2206,.0000

-36.9377,-19.0591,.0000

-10.6413,-12.7645,.0000

 

I would appreciate any help you could give (I hope it is a simple matter, but am new to creating lisps)

Thanks,

JoshKing

Link to comment
Share on other sites

As an alternative to using spaces, perhaps using an X or other flag would be better for seperating the poly-line shapes (as I would like to read this .txt file into another program, which typically ignores free space). The output could therefore be something like this:

 

-58.0321,2.3386,.0000

-4.8269,-26.2931,.0000

8.5532,9.7325,.0000

-22.2996,27.6666,.0000

X

-2.7682,9.1090,.0000

-16.7824,14.6167,.0000

-30.1668,7.2206,.0000

-36.9377,-19.0591,.0000

-10.6413,-12.7645,.0000

X

 

Thanks again,

Josh

Link to comment
Share on other sites

Thanks Josh

As an alternative to using spaces, perhaps using an X or other flag would be better for seperating the poly-line shapes (as I would like to read this .txt file into another program, which typically ignores free space). The output could therefore be something like this:

 

-58.0321,2.3386,.0000

-4.8269,-26.2931,.0000

8.5532,9.7325,.0000

-22.2996,27.6666,.0000

X

-2.7682,9.1090,.0000

-16.7824,14.6167,.0000

-30.1668,7.2206,.0000

-36.9377,-19.0591,.0000

-10.6413,-12.7645,.0000

X

 

Thanks again,

Josh

 

Update EcoorE to Rev.5

added option "Settings" where you can adjust the offset of the text, the text height and the separators

Alternative. Find these lines in the file and set your default the separator

(or *ptcol:SEPARATE* ;;;SEPARATE COORDINATES FLAG
   [color="red"](setq *ptcol:SEPARATE* "")[/color]
   )

Link to comment
Share on other sites

stevesfr

you use what version MS OFFICE? (I did not test with Office 2007)

In any case I have a little changed programs. Now it is possible to keep in a text file csv or txt a format.

 

If option Excell does not work, try option Text file (csv a format) and to answer "YES" inquiry "Open text file? [Yes/No] :"

 

Commands:

COOR - export of coordinates

COORN-export of coordinates with numbering. Numbers of points are drawn by the text on the current layer, the current style, current height (TEXTSIZE)

COORT-export of coordinates with numbering where number considers the text nearest to a point

CoorNP-Coordinates + Numbers + Points. Draw points with current value of PDMODE and PDSIZE

COORNB - CoorNB-Coordinates + Block (Numbers + Points)

 

Rev5. - added option "Settings" where you can adjust the offset of the text, the text height and the separators

 

works perfect but iwant to add label before the num in attribute

Link to comment
Share on other sites

Brilliant!

Thank you so much for your help, works perfectly!

 

Now I have an even more challenging request. This may be way too much (so feel free to tell me to go pound sand :), but if you find the time, or if you can point me in the right direction, on how to program this, I would greatly appreciate it:

 

After creating the .txt document with the original coordinates, I would like to do the following:

1. Scale all geometry by 25.4 from the origin (0,0) to convert from inches to millimeters

2. Rotate all shapes by -90 degrees from origin (0,0)

3. Create a user defined hatch on each shape, so that each shape is hatched at equal spacing from 0 to 90 degrees with a hatch spacing of 0.01875

- To do this manually, I would type in hatch, and in the drop down box "Type:" I would select "User Defined", in "Spacing" field I would type in 0.01875, and then I would enter in an angle such as 0 for the first shape, hatch it, then repeat this for the next shape with a new angle, until the last shape had a hatch angle of 90 degrees.

4. Once completed, if it is possible to delete the polylines and keep only the hatches, that would be awesome.

 

Again, I know this is a tall order, so if you know how to do even a portion of this, and can point me in the right direction, I would be extremely grateful.

 

Thanks again,

JoshKing

Link to comment
Share on other sites

Try it

(defun C:TEST ( / *error* Spacing anglestep item polyline ss )
 (vl-load-com)
 (defun *error* (msg)
   (princ msg)
   (vla-endundomark (vla-get-activedocument(vlax-get-acad-object)))
   (princ)
   )
 (setq Spacing 0.01875) ;_Spacing" field I would type in 0.01875
 (vla-startundomark (vla-get-activedocument(vlax-get-acad-object)))                        
 (while (> (getvar "CMDACTIVE") 0) (command))
 (sssetfirst nil nil)
 (if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))))
   (progn
     (setq anglestep (/
                         (* 0.5 pi) ;_90 degree
                         (1- (sslength ss)) ;_number of selected polylines -1
                       )
           )
     ;_1. Scale all geometry by 25.4 from the origin (0,0) to convert from inches to millimeters
     (command "_.SCALE" ss ""
              '(0. 0.) ;_origin (0,0)
              25.4    ;_ convert from inches to millimeters
     )
     ;_2. Rotate all shapes by -90 degrees from origin (0,0)
     (command "_.Rotate" "_p" ""
              '(0. 0.) ;_origin (0,0)
              "-90"
     )
      (while (> (getvar "CMDACTIVE") 0) (command))
      (setq item '-1)
      (repeat (sslength ss) ;_ cycle for each polyline
        (setq polyline (ssname ss (setq item (1+ item))))
        (entmakex-hatch
          (list
            (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget polyline))) ;_polyline vertex
            )
          (* item anglestep) ;_angle in radians
          "_USER" ;_User Defined pattern
          Spacing ;_Spacing" field I would type in 0.01875
          )
        ) ;_ end repeat
     (command "_.Zoom" "_O" ss "")
     ;_4. Once completed, if it is possible to delete the polylines and keep only the hatches, that would be awesome.
     (command "_.ERASE" ss "")
   )
 )
 (vla-endundomark (vla-get-activedocument(vlax-get-acad-object)))
 (princ)
 )
(princ "\nType TEST in command line")

(defun entmakex-hatch (L a n s)
;; By ElpanovEvgeniy
;; L - list of list point. like ((pt11 pt12 pt13)(pt21 pt22 pt23))
;; A - angle hatch
;; N - name pattern
;; S - scale
;; returne - hatch ename
;;USE
;|
(entmakex-hatch '(((538.794 584.563) (895.629 584.563) (895.629 997.377) (538.794 997.377))
                 ((386.809 345.13) (670.955 345.13) (670.955 855.369) (386.809 855.369))
                )
               (/ pi 2)
               "ANSI31"
               2.
) ;_  entmakex-hatch
(entmakex-hatch
(list
 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"SOLID"
2.
)
(entmakex-hatch
(list
 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"_USER" ;_User Defined
2.
)
(entmakex-hatch
(list
 (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car (entsel "\nSelect Polyline:")))))
) ;_  list
(/ pi 2)
"ANSI32"
2.
)
|;
(entmakex
 (apply
  'append
  (list
   (list '(0 . "HATCH")
         '(100 . "AcDbEntity")
         '(410 . "Model")
         '(100 . "AcDbHatch")
         '(10 0.0 0.0 0.0)
         '(210 0.0 0.0 1.0)
         (cons 2 n)
         (if (= n "SOLID")
          '(70 . 1)
          '(70 . 0)
         ) ;_  if
         '(71 . 0)
         (cons 91 (length l))
   ) ;_  list
   (apply 'append
          (mapcar '(lambda (a)
                    (apply 'append
                           (list (list '(92 . 7) '(72 . 0) '(73 . 1) (cons 93 (length a)))
                                 (mapcar '(lambda (b) (cons 10 b)) a)
                                 '((97 . 0))
                           ) ;_  list
                    ) ;_  apply
                   ) ;_  lambda
                  l
          ) ;_  mapcar
   ) ;_  apply
   (if (= n "SOLID")
    (list '(75 . 0)
         '(76 . 1)
         '(47 . 1.)
         '(98 . 2)
         '(10 0. 0. 0.0)
         '(10 0. 0. 0.0)
         '(450 . 0)
         '(451 . 0)
         '(460 . 0.0)
         '(461 . 0.0)
         '(452 . 0)
         '(462 . 0.0)
         '(453 . 2)
         '(463 . 0.0)
         '(63 . 256)
         '(463 . 1.0)
         '(63 . 256)
         '(470 . "LINEAR")
   ) ;_  list
   (list '(75 . 0)
         '(76 . 1)
         (cons 52 a)
         (cons 41 s)
         '(77 . 0)
         '(78 . 1)
         (cons 53 a)
         '(43 . 0.)
         '(44 . 0.)
         '(45 . 1.)
         '(46 . 1.)
         '(79 . 0)
         '(47 . 1.)
         '(98 . 2)
         '(10 0. 0. 0.0)
         '(10 0. 0. 0.0)
         '(470 . "LINEAR")
   ) ;_  list
     )
  ) ;_  list
 ) ;_  apply
) ;_  entmakex
) ;_  defun

Link to comment
Share on other sites

Incredible! I can't believe how quickly you programmed that, I knew you were good, but for a Newbie like me, your skills are miraculous.

 

Thank you so much, this will save me a lot of time hatching each shape individually. And thank you for adding my text within the code, as it helps me to better understand how to write the code. Not to press my luck, but could you also show me how I would copy the hatched lines into a metric drawing, and save the drawing as an old .dxf drawing?

 

To do this manually, I would do the following:

1. Select all hatch patterns on the screen

2. press ctrl+c (to copy)

3. select New (Drawing), select the "Metric" option in the dialog box

4. Once the drawing is up, I would select Edit/Paste to Original Coordinates

5. I would finally select File/Save As, and change the Files of type to: AutoCadR12/LT2 DXF (.dxf)

 

Thanks a million,

JoshKing

Link to comment
Share on other sites

3. select New (Drawing), select the "Metric" option in the dialog box

When you select "Metric" or "Imperial" option you set MEASUREMENT system variable to 0 or 1

So instead of 2,3,4 steps can be set in the current drawing measurement = 1

(defun C:TEST1 ()
 (while (> (getvar "CMDACTIVE") 0) (command))
 (if (setq ss (ssget "_ALL" '((0 . "HATCH")))) ;_Select all hatch
   (progn
     (setvar "MEASUREMENT" 1);_ "Metric" option
     (setvar "CMDECHO" 1)
     (command "_SAVEAS"
              "DXF" ;_DXF type
              "_E"  ;_Select object
              ss    ;_selected hatch
              ""    ;_ENTER
              "_V"  ;_version
              "R12" ;_R12 dxf version
              ""    ;_ENTER
              ""    ;_file name default
                    ;_you mast type your file name or/and change path
;_LOOK
;_http://www.cadtutor.net/forum/showthread.php?61162-Save-Current-DWG-to-Another-Location&
;_http://forums.autodesk.com/t5/forums/forumtopicprintpage/board-id/130/message-id/108894/print-single-message/false/page/1
              )
     )
   )
 )

Link to comment
Share on other sites

Terrrific! thanks again. This lisp stuff is pretty cool, I went through the code, and was able to string a number of different lisp routines together to make a large lisp that does all of the coordinate, hatching, rotation, polyline, .pedit etc... Thanks a million!

 

After going through everything, there is one last lisp routine that I would like help with, this involves moving the shapes down in the -Y direction, and adding that value to the beginning of the .txt file created within your "EcoorE.lsp" program. This is what I would like to do:

 

1. After your program "EcoorE Rev.6" outputs the .txt file, I would like the program to look at the smallest Y coordinate within the list (probably also saved in PtLst), and move all of those coordinates within AutoCAD down the difference between the smallest Y value, and say .050" (such that the shapes are essentially translated in the Y direction so that the lowest point is .050" above the origin)

 

IMPORTANT: I do not want to change the coordinates within the .txt file, but only want to move the geometry within the drawing down after the coordinates are written.

 

2. I would then like the distance moved to be included at the top of the .txt coordinate file with "moved" in place of the X and Z coordinates.

 

Thus, the coordinates captured in the .txt file will show the original coordinates of the polylines selected, except for the first coordinate in the file, which tells me how much the shapes within the autocad file moved down in the Y direction, with an output something like this:

 

moved -1.250 moved

-58.0321,2.3386,.0000

-4.8269,-26.2931,.0000

8.5532,9.7325,.0000

-22.2996,27.6666,.0000

X

-2.7682,9.1090,.0000

-16.7824,14.6167,.0000

-30.1668,7.2206,.0000

-36.9377,-19.0591,.0000

-10.6413,-12.7645,.0000

X

 

 

Thanks,

JoshKing

Link to comment
Share on other sites

By the way, my example data above is not accurate. This was an example to show the format of the output file. An actual example might look something like this:

 

moved -1.2500 moved

-58.0321,1.5000,.0000

-4.8269,6.2931,.0000

8.5532,9.7325,.0000

-22.2996,27.6666,.0000

X

-2.7682,9.1090,.0000

-16.7824,14.6167,.0000

-30.1668,7.2206,.0000

-36.9377,1.3000,.0000

-10.6413,2.7645,.0000

X

 

In this example, the lowest Y value (in bold) is 1.3000, so the polylines within the drawing would be moved down 1.2500 (1.3000-.0500).

 

Thanks,

Joshking

Link to comment
Share on other sites

I understand that "moved -1.2500 moved" to write for all polylines, except for a polyline containing the smallest Y coordinate?

Link to comment
Share on other sites

The line "moved -X.XXXX moved" is an additional line that I would like added at the very top of the .txt document containing all of the original coordinates created by "coor".

 

The X.XXXX number is the difference between the smallest "Y" coordinate in the .txt document (lowest polyline point of all polyline shapes) and some predetermined height. So the logical equation would be something like: amountmoved=-(Yminimum-SpecifiedMinimum). For example, if the lowest polyline point has a "Y" coordinate of 3.2375, and the spefified height is .0500, and, then I want the top line to say "moved -3.1875 moved" in the original text file output by "coor".

 

Once this file is created, I then want the program to actually move all polylines by the amount specified (-3.1875) in the Y direction.

 

The reason I want to do it this way, is that I am pulling the data into two different programs. The first program will plot all of the original shapes just as they are, which is why I want the original coordinates in the .txt file. The second program takes the .dxf itself, but the shapes need to be moved close to the origin in order for this second program to work. So after creating the .txt file, I need all of the shapes to be moved down by the amount specified in the .txt file. I then use the first line in the .txt file to tell me how far all of the shapes were moved for the second program.

 

So the real trick, is that I want to write all of the original coordinates in the text file first, and then I want to move all of the shapes down towards the origin before I start the hatching routine that you created.

 

I hope this helps to clarify. Let me know if this is still confusing.

 

Thanks,

JoshKing

Link to comment
Share on other sites

For example, if the lowest polyline point has a "Y" coordinate of 3.2375, and the spefified height is .0500, and, then I want the top line to say "moved -3.1875 moved"

And if the smallest Y-coordinate is negative, eg if the lowest polyline point has a "Y" coordinate of -3.2375 ?

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