Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Export drawing objects coordinates

  1. #1
    Member
    Join Date
    2016-10
    Posts
    31
    Login to Give a bone
    0

    Default Export drawing objects coordinates

    Hi all,

    i am new to this site. i want layer description, start point coordinate, end point coordinates. and rectangles layer description, bottom left point coordinate and top right coordinates to note pad. please have a look for format of notepad.

    example for one line data is: Line "Layer1" "45.56,0.23" "45.56,2.56"

    Here "Line" is type of object, Layer name=Layer1, Start point of line is=45.56,0.23 and End Point of line is="45.56,2.56"

    For Rectangle Data: Rec "Layer3" "45.49,0.12" "45.72,0.50"

    Here Rec is Rectangle object, Layer name=Layer1, Bottom Left Rectangle corner point is45.49,0.12 , Top right Rectangle corner point is 45.72,0.50.

    please solve by lisp.

    Thanks.
    Attached Files Attached Files

  2. #2
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Hi,
    This code can help you?

    Code:
    (defun l-coor2l-pt (lst flag / )
      (if lst
        (cons
          (list
            (car lst)
            (cadr lst)
            (if flag
              (+ (if (vlax-property-available-p ename 'Elevation) (vlax-get ename 'Elevation) 0.0) (caddr lst))
              (if (vlax-property-available-p ename 'Elevation) (vlax-get ename 'Elevation) 0.0)
            )
          )
          (l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag)
        )
      )
    )
    (defun c:ptdef2csv ( / js n file_name cle f_open key_sep str_sep oldim ent ename dxf_cod l_pt l_pr nbs)
      (vl-load-com)
      (setq
        js
        (ssget
          (list
            '(0 . "*LINE,POINT,ARC,CIRCLE,ELLIPSE,INSERT")
            (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
            (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
          )
        )
        n -1
      )
      (cond
        (js
          (setq file_name (getfiled "File to create ?: " (strcat (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 3)) "csv") "csv" 37))
          (if (null file_name) (exit))
          (if (findfile file_name)
            (progn
              (prompt "\nFile already exist!")
              (initget "Add Replace Cancel")
              (setq cle
                (getkword "\nData in file? [Add/Replace/Cancel] <R>: ")
              )
              (cond
                ((eq cle "Add")
                  (setq cle "a")
                )
                ((or (eq cle "Replace") (eq cle ()))
                  (setq cle "w")
                )
                (T (exit))
              )
              (setq f_open (open file_name cle))
            )
            (setq f_open (open file_name "w"))
          )
          (setq str_sep ",")
          (setq oldim (getvar "dimzin"))
          (setvar "dimzin" 0)
          (write-line (strcat "Registration" str_sep "Type Entitie" str_sep "Layer Name" str_sep "Coordinates X" str_sep "Coordinates Y" str_sep "Coordinates Z") f_open)
          (repeat (sslength js)
            (setq ent (ssname js (setq n (1+ n))) ename (vlax-ename->vla-object ent) l_pt nil dxf_cod (entget ent))
            (setq l_pr (list 'StartPoint 'EndPoint 'Center 'InsertionPoint 'Coordinates 'FitPoints) nbs 0)
            (foreach n l_pr
              (if (vlax-property-available-p ename n)
                (setq l_pt
                  (if (or (eq n 'Coordinates) (eq n 'FitPoints))
                    (append
                      (if (eq (vla-get-ObjectName ename) "AcDbPolyline")
                        (l-coor2l-pt (vlax-get ename n) nil)
                        (if (and (eq n 'FitPoints) (zerop (vlax-get ename 'FitTolerance)))
                          (l-coor2l-pt (vlax-get ename 'ControlPoints) T)
                          (l-coor2l-pt (vlax-get ename n) T)
                        )
                      )
                      l_pt
                    )
                    (cons (vlax-get ename n) l_pt)
                  )
                )
              )
            )
            (foreach n l_pt
              (write-line
                (strcat
                  (itoa (setq nbs (1+ nbs))) str_sep
                  (cdr (assoc 0 dxf_cod)) str_sep
                  (cdr (assoc 8 dxf_cod)) str_sep
                  (rtos (car n) 2 2) str_sep
                  (rtos (cadr n) 2 2) str_sep
                  (rtos (caddr n) 2 2)
                )
                f_open
              )
            )
            (write-line "" f_open)
          )
          (close f_open)
          (setvar "dimzin" oldim)
        )
      )
      (prin1)
    )
    Last edited by Bruno.Valsecchi; 2016-11-03 at 09:29 AM.

  3. #3
    Member
    Join Date
    2016-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Dear my friend Bruno.Valsecchi,

    Thank you for your code. i have struggling with language of code options. please arrange in English version with two decimal precision like 45.56. i found "virgule" option is synced for my requirement. so please remove remaining options for direct execution.

    Thanks.
    Last edited by Structo; 2016-11-03 at 04:45 AM.

  4. #4
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Ok,
    I have edited the previous post for update the code

  5. #5
    Member
    Join Date
    2016-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Dear Friend,

    Your editing is marvelous. now minor error showing like at CSV file, "Coordinates X" column showing Name of the Layer. please edit this error as "Layer Name" instead of "Coordinates X". because description is moved.

    please find sample file for reference.

    Thanks.
    Attached Files Attached Files

  6. #6
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Sorry, I have forgot this! The code is updated

  7. #7
    Member
    Join Date
    2016-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Dear Friend,

    Amazing help by you, thank you very much. i need continuation of this lisp by fresh thread.please have a look and kindly help me.

    Thanks.
    Last edited by Structo; 2016-11-03 at 11:48 AM.

  8. #8
    Member
    Join Date
    2010-11
    Posts
    7
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Hi Bruno.
    Indeed its a great code. I have a situation with slight variation & hope you could help me.
    I have a drawing with lot of vertical lines and horizontal lines (something like a grid)& I need to place the easting value at the start or end of each vertical line and northing value at the start or end of each horizontal line & in the same layer of the lines.

    your help is very much appreciated.

  9. #9
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Quote Originally Posted by symoin View Post
    Hi Bruno.
    Indeed its a great code. I have a situation with slight variation & hope you could help me.
    I have a drawing with lot of vertical lines and horizontal lines (something like a grid)& I need to place the easting value at the start or end of each vertical line and northing value at the start or end of each horizontal line & in the same layer of the lines.

    your help is very much appreciated.
    Hi symoin,
    Is this that you wont?

    Code:
    (vl-load-com)
    (defun c:label_bearing ( / l_var js htx AcDoc Space nw_style n obj dxf_ent pt_start pt_end alpha val_txt nw_obj)
    	(setq l_var (mapcar 'getvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS")))
    	(mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") '(4 3 2 2))
    	(princ "\nSelect lines.")
    	(while (null (setq js (ssget '((0 . "LINE")))))
    		(princ "\nSelection is empty or are not LINE!")
    	)
    	(initget 6)
    	(setq htx (getdist (getvar "VIEWCTR") (strcat "\nSpecify text height <" (rtos (getvar "TEXTSIZE")) ">: ")))
    	(if htx (setvar "TEXTSIZE" htx))
    	(setq
    		AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
    		Space
    		(if (= 1 (getvar "CVPORT"))
    			(vla-get-PaperSpace AcDoc)
    			(vla-get-ModelSpace AcDoc)
    		)
    	)
    	(vla-startundomark AcDoc)
    	(cond
    		((null (tblsearch "STYLE" "ELEV_ARIAL_1"))
    			(setq nw_style (vla-add (vla-get-textstyles AcDoc) "ELEV_ARIAL_1"))
    			(mapcar
    				'(lambda (pr val)
    					(vlax-put nw_style pr val)
    				)
    				(list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
    				(list (strcat (getenv "windir") "\\fonts\\arial.ttf") 0.0 0.0 1.0 0.0)
    			)
    		)
    	)
    	(repeat (setq n (sslength js))
    		(setq
    			obj (ssname js (setq n (1- n)))
    			dxf_ent (entget obj)
    			pt_start (cdr (assoc 10 dxf_ent))
    			pt_end (cdr (assoc 11 dxf_ent))
    			alpha (rem (angle (trans pt_start 0 1) (trans pt_end 0 1)) pi)
    		)
    		(if (> alpha 0)
    			(setq alpha (+ alpha pi) val_txt (strcat "E " (rtos (car pt_start))))
    			(setq val_txt (strcat "N " (rtos (car pt_start))))
    		)
    		(setq nw_obj
    			(vla-addMtext Space
    				(vlax-3d-point (setq pt (polar pt_start (+ alpha (* pi 0.5)) (getvar "TEXTSIZE"))))
    				0.0
    				val_txt
    			)
    		)
    		(mapcar
    			'(lambda (pr val)
    				(vlax-put nw_obj pr val)
    			)
    			(list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
    			(list 8 (getvar "TEXTSIZE") 5 pt "ELEV_ARIAL_1" (cdr (assoc 8 dxf_ent)) alpha)
    		)
    	)
    	(vla-endundomark AcDoc)
    	(mapcar 'setvar '("AUNITS" "AUPREC" "LUPREC" "LUNITS") l_var)
    	(prin1)
    )

  10. #10
    Member
    Join Date
    2010-11
    Posts
    7
    Login to Give a bone
    0

    Default Re: Export drawing objects coordinates

    Yes
    Thanks for this and one last and small update is to keep the values at the end of the lines instead of a shift towards the right side and the justification to be middle center.
    Thanks once again.

Page 1 of 2 12 LastLast

Similar Threads

  1. export line coordinates
    By spamkiller433238 in forum AutoLISP
    Replies: 16
    Last Post: 2020-04-21, 04:35 PM
  2. Export coordinates to Excel
    By rputhenv in forum AutoCAD General
    Replies: 5
    Last Post: 2016-10-14, 02:09 PM
  3. Replies: 1
    Last Post: 2016-06-17, 08:20 PM
  4. 2013: How do I export to IFC with project coordinates and not real world coordinates?
    By m.knutsson in forum Revit Architecture - General
    Replies: 2
    Last Post: 2013-10-15, 06:54 AM
  5. Export Coordinates
    By Maastricht in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2009-08-19, 04:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •