Jump to content

Recommended Posts

Posted

Hello there,

Heres what I want to do.

I want to select a ref number( TEXT or MTEXT) then a dimension and have it exported to a csv file. I have found one such lisp on searching through the forums. Heres the lisp I found that does exactly this.

 

(defun c:dimtxtexp ( / des dim enx idx sel txt )

(if (and (setq sel (ssget '((0 . "TEXT,MTEXT,*DIMENSION"))))

(setq des (open (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv") "a"))

)

(progn

(repeat (setq idx (sslength sel))

(setq enx (entget (ssname sel (setq idx (1- idx)))))

(if (wcmatch (cdr (assoc 0 enx)) "*DIMENSION")

(setq dim (cons (rtos (cdr (assoc 42 enx))) dim))

(setq txt (cons (cdr (assoc 1 enx)) txt))

)

)

(while (or dim txt)

(write-line

(strcat

(cond ((car txt)) ("")) ","

(cond ((car dim)) ("")) ","

(cond ((cadr dim)) (""))

)

des

)

(setq txt (cdr txt)

dim (cddr dim)

)

)

)

)

(if (= 'file (type des)) (close des))

(princ)

)

 

 

However my problem is that this particular lisp takes in the label first(which is text) followed by two dimension values. I want it take only a single dimension value after the text then go to next line and repeat. Can somebody edit this lisp accordingly.

 

Your help is much Appreciated

Posted

Output from current lisp will be like this

1 0.5 0.4

2 0.7 0.5

3 0.5 0.2

 

I want an output like this

 

1 0.4

2 0.6

3 0.8

4 0.2

Posted

Try the following:

(defun c:dimtxtexp ( / des dim enx idx sel txt )
   (if (and (setq sel (ssget '((0 . "TEXT,MTEXT,*DIMENSION"))))
            (setq des (open (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".csv") "a"))
       )
       (progn
           (repeat (setq idx (sslength sel))
               (setq enx (entget (ssname sel (setq idx (1- idx)))))
               (if (wcmatch (cdr (assoc 0 enx)) "*DIMENSION")
                   (setq dim (cons (rtos (cdr (assoc 42 enx))) dim))
                   (setq txt (cons (cdr (assoc 1 enx)) txt))
               )
           )
           (while (or dim txt)
               (write-line
                   (strcat
                       (cond ((car  txt)) ("")) ","
                       (cond ((car  dim)) (""))
                   )
                   des
               )
               (setq txt (cdr txt)
                     dim (cdr dim)
               )
           )
       )
   )
   (if (= 'file (type des)) (close des))
   (princ)
)

 

FWIW, here is the original source of the code:

http://www.cadtutor.net/forum/showthread.php?90819-Extract-text-Label-and-Dimension-s-to-a-CSV-file&p=621923&viewfull=1#post621923

Posted

Thank you so much. Sorry for the late reply. Works like a charm

  • 4 years later...
Posted

Hello there!

Sorry for bringing this thread up again. I hope you guys don't mind it. I was just looking for a lisp routine similar to these but for a single text and a multiple dimensions (minimum of three) and  arrange in excel (csv) in rows not in columns. For example, for a single text (code) there are multiple dimensions arrange in row 1, then followed by another text (code) with its corresponding dimensions in row 2, so on and so forth.

 

I hope someone can help me on these. Your help is highly Appreciated.

Sample.xlsx

Posted

Dear Ramees,

This lisp will open a new excel file and record this value (not a CSV file)

You can try this one, maybe it will helpful for you,

 

Dear Lee Mac,

I just started this AutoLISP,

I know as a fresher I will suffer 1000 of the problems

Can you check this lisp and please tell me your correction and suggestion, so it will be very helpful for me in the future

 

 

(defun c:test()
  (vl-load-com)
  (setq xlapp(vlax-get-or-create-object "Excel.Application")
	xlrun(vlax-get-property xlApp 'Visible))
  (if (= XLrun :vlax-false)
    (progn
      (setq xlApp (vlax-get-or-create-object "Excel.Application")
	    xlBooks (vlax-get-property xlApp "Workbooks")
	    xlBook (vlax-invoke-method xlBooks "Add")
	    xlSheets (vlax-get-property xlBook "Sheets")
	    xlSheet (vlax-get-property xlSheets "Item" 1)
	    xlCells (vlax-get-property xlSheet "Cells"))
      (vla-put-visible xlApp :vlax-true)
      (AJ:excelstart)
      )
    (progn
      (AJ:excelstart))
    ))

(defun AJ:excelstart()
  (setq XLwbk (vlax-get-property XLapp 'WorkBooks)
	XLash (vlax-get-property XLapp 'ActiveSheet)
	XLcel (vlax-get-property XLapp 'ActiveCell))
  (setq XLcol (vlax-get-property XLcel 'Column)
	XLrow (vlax-get-property XLcel 'Row)
	XLcva (vlax-get-property XLcel 'Text)
	XLtxt (vlax-variant-value XLcva))
  (AJ:dimtxtexp))

(defun AJ:dimtxtexp()
  (while
    (setq tent(entsel "Pick text:"))
    (setq txt(cdr(assoc 1(setq enx (entget(car tent))))))
    (setq dims(entget(car(entsel "pick dimension"))))
    (setq di(cdr (assoc 42 dims)))
    (vlax-put-property xlCells "Item" XLrow XLcol txt)
    (vlax-put-property xlCells "Item" XLrow (+ XLcol 1) (rtos di 2 0))
    (repeat (setq XLrow (1+ XLrow)))))

 

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