Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help me a autolisp export dimensions to excel?

18 REPLIES 18
Reply
Message 1 of 19
minhphuong.humg
4911 Views, 18 Replies

Help me a autolisp export dimensions to excel?

I have a drawing with dimensions and number (number and text number). I want ouput (Can select or Automatic) to a file excel. Please, write a lisp do.

Thank you very much.

I want ouput to excel the same this picture.

want output.PNG

18 REPLIES 18
Message 2 of 19
hmsilva
in reply to: minhphuong.humg


@minhphuong.humg wrote:

I have a drawing with dimensions and number (number and text number). I want ouput (Can select or Automatic) to a file excel. Please, write a lisp do.

Thank you very much.

...


minhphuong.humg,

 

this quick and dirty code will create a .csv  file, in the dwg directory with the same name, try it, is minimally tested...

(defun c:test (/ *error* a b c file line)

  (defun *error* (msg)
    (if	file
      (close file)
    )
    (vl-cmdf "regen")
    (cond ((not msg))
	  ((member msg '("Function cancelled" "quit / exit abort")))
	  ((princ (strcat "\n** Error: " msg " ** ")))
    );; cond
    (princ)
  );; *error*

  (setq	file (open (strcat (getvar "dwgprefix")
			   (vl-filename-base (getvar "dwgname"))
			   ".csv"
		   )
		   "w"
	     )
  )

  (while
    (and (not (prompt "\n<<< Select the number >>>"))
	 (setq a (ssget "_+.:E:S" '((0 . "TEXT"))))
	 (not (redraw (ssname a 0) 3))
	 (not (prompt "\n<<< Select the reference >>>"))
	 (setq b (ssget "_+.:E:S" '((0 . "TEXT"))))
	 (not (redraw (ssname b 0) 3))
	 (not (prompt "\n<<< Select the length >>>"))
	 (setq c (ssget "_+.:E:S" '((0 . "TEXT"))))
	 (not (redraw (ssname c 0) 3))
    );; and
     (setq line	(strcat	(cdr (assoc 1 (entget (ssname a 0))))
			"\t"
			(cdr (assoc 1 (entget (ssname b 0))))
			"\t"
			(cdr (assoc 1 (entget (ssname c 0))))
		)
     )
     (write-line line file)
  );; while
  (close file)
  (*error* nil)
  (princ)
);; test

HTH

Henrique

 

EESignature

Message 3 of 19
devitg
in reply to: minhphuong.humg

Hi Enrique at

 

(not (prompt "\n<<< Select the length >>>"))
	 (setq c (ssget "_+.:E:S" '((0 . "TEXT"))))

 

The lenght is not a TEXT , it is a Aligned Dimension.

Message 4 of 19
hmsilva
in reply to: devitg


@devitg wrote:

Hi Enrique at

 

(not (prompt "\n<<< Select the length >>>"))
	 (setq c (ssget "_+.:E:S" '((0 . "TEXT"))))

 

The lenght is not a TEXT , it is a Aligned Dimension.


Gabriel,

thanks, you are correct, I was with an open dwg posted by Patcy at

http://forums.autodesk.com/t5/AutoCAD-2013-2014-DWG-Format/Help-me-write-a-autolisp-export-drawing-d...

when the same OP start this thread, so I thought that was the same dwg, my bad...

 

So here's the revised code:

(defun c:test (/ *error* a b c file line)

  (defun *error* (msg)
    (if	file
      (close file)
    )
    (vl-cmdf "regen")
    (cond ((not msg))
	  ((member msg '("Function cancelled" "quit / exit abort")))
	  ((princ (strcat "\n** Error: " msg " ** ")))
    );; cond
    (princ)
  );; *error*

  (setq	file (open (strcat (getvar "dwgprefix")
			   (vl-filename-base (getvar "dwgname"))
			   ".csv"
		   )
		   "w"
	     )
  )

  (while
    (and (not (prompt "\n<<< Select the number >>>"))
	 (setq a (ssget "_+.:E:S" '((0 . "TEXT"))))
	 (not (redraw (ssname a 0) 3))
	 (not (prompt "\n<<< Select the reference >>>"))
	 (setq b (ssget "_+.:E:S" '((0 . "TEXT"))))
	 (not (redraw (ssname b 0) 3))
	 (not (prompt "\n<<< Select the length >>>"))
	 (setq c (ssget "_+.:E:S" '((0 . "DIMENSION"))))
	 (not (redraw (ssname c 0) 3))
    );; and
     (setq line	(strcat	(cdr (assoc 1 (entget (ssname a 0))))
			"\t"
			(cdr (assoc 1 (entget (ssname b 0))))
			"\t"
			(rtos (cdr (assoc 42 (entget (ssname c 0)))) 2 0)
		)
     )
     (write-line line file)
  );; while
  (close file)
  (*error* nil)
  (princ)
);; test

 Henrique

 

EESignature

Message 5 of 19
Ajilal.Vijayan
in reply to: hmsilva

I think the csv file should open on 'append' mode than 'write' mode.

Hence OP can continue selection and csv file gets updated.

 

(setq	file (open (strcat (getvar "dwgprefix")
			   (vl-filename-base (getvar "dwgname"))
			   ".csv"
		   )
		   "a"
	     )
  )
Message 6 of 19
devitg
in reply to: Ajilal.Vijayan

Find attached a FAS file , and the CSV .

 

You only need to pick at any DIM , and then at any REF or NUM 

Message 7 of 19
hmsilva
in reply to: Ajilal.Vijayan


@Ajilal.Vijayan wrote:

I think the csv file should open on 'append' mode than 'write' mode.

Hence OP can continue selection and csv file gets updated.

 

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

Agree!
It's a good idea using the "append" insted of "write", we can also give OP the chance to choose the output file name, and... but it is just a demo, let's wait the OP feedback.


Henrique

 

EESignature

Message 8 of 19
hmsilva
in reply to: devitg

Nice one, Gabriel! Smiley Happy

 

Using EXpressTools functions, you have to be sure that the OP have ET installed, however, it's a pity that don't share your code with us... Smiley Wink

 

Henrique

 

EESignature

Message 9 of 19
devitg
in reply to: hmsilva

Hi Enrique, no EXpressTools used.

 

Just vl-lisp 

Message 10 of 19
hmsilva
in reply to: devitg


@devitg wrote:

Hi Enrique, no EXpressTools used.

 

Just vl-lisp 


Gabriel,

from your code:

 

Command: (LOAD "C:/a-test/a-test/GabrielEnrique/dim-text-tocsv.fas")
 Put
 TXT-TO-CSV
 at the command linenil

Command: TXT-TO-CSV
acetutil.arx    esta cargado
_

 Pick one dimension:
Select objects:

 

Henrique

EESignature

Message 11 of 19

Thank my friends (hmsilva, devitg, ajilal.vijayan). Special, lisp's devitg very very good with the simplest case (my drawing upload). However, I must do work very hard. It's complexer than you think.

With drawings (attach) complex I must pick each object from autocad to excel. Very long with drawing complex.

My friends, please help me write lisp (can select dimension (pick), select other text (select window or pick)) to output as image attach. Mr. hmsilva, devitg, ajilal.vijayan please help me!

Really, thank my friends very much.

P/S: Can you give me solutions that work fast to have results like that?

complex.PNG

Message 12 of 19

The attached drawing looks 'complex'Smiley Happy

 

As you wait for the lisp routine in here,

Can I suggest something that will make your work more easier in future ?

I think you should start creating Dynamic block with attributes for this kind of job.

So for an external output you can use DATAEXRACTION command.

Message 13 of 19
devitg
in reply to: hmsilva

Forma parte de una defun básica 

 

It is par of a basic DEFUN 

 

(IF (= (CAR (MEMBER "acetutil.arx" (ARX))) "acetutil.arx")
(PRINC (STRCAT "acetutil.arx" " esta cargado"))
(PROGN
(ARXLOAD "acetutil.arx" "no se cargo")
(PRINC (STRCAT "acetutil.arx" "..se ha cargado"))
)
)

 No tiene implicancias en el lisp 

 

It have no implied action on the LISP 

 

 

Message 14 of 19

Dir, ajilal.vijayan. do not understand your health. I think, there are things I know I've said things. Here I ask is I want to help people. I would help you or others in a field that I knew. Simply as that. I think, could not create such block. Thank you very much.

Message 15 of 19
devitg
in reply to: minhphuong.humg

As ever and for the last of the times to being , The OP, only show a part of it .

It is like to go to the Surgeon Officce, show the arm and hand , and ask for a help to heal its leg .

Why it will be it so???

 

Message 16 of 19
devitg
in reply to: minhphuong.humg

Mr minhphuong.humg, you ask for help , and offer yours knows.

What can you offer?

 

 

Message 17 of 19
hmsilva
in reply to: devitg


@devitg wrote:

Forma parte de una defun básica 

 

It is par of a basic DEFUN 

 

(IF (= (CAR (MEMBER "acetutil.arx" (ARX))) "acetutil.arx")
(PRINC (STRCAT "acetutil.arx" " esta cargado"))
(PROGN
(ARXLOAD "acetutil.arx" "no se cargo")
(PRINC (STRCAT "acetutil.arx" "..se ha cargado"))
)
)

 No tiene implicancias en el lisp 

 

It have no implied action on the LISP 

 

 


Gabriel,

only commented the command line echo... Smiley Wink

 

Henrique

EESignature

Message 18 of 19
hmsilva
in reply to: minhphuong.humg

minhphuong.humg,
it is a good practice, when asking for help, provide the maximum of information possible, to ensure that the person who try to helps us, is not wasting time...

 

First - we all, are using our free time to help other people who have more difficulties than we!

 

Second - you should consider the ajilal.vijayan advice as a good practice for future jobs like this, using Dynablocks, Attributes and the DATAEXRACTION command, the excel spreadsheet would be automatically created!

 

Third - let's see what we can get, working together, if you are interested...

 

Starting, at your "complex.dwg" and at the image you attached, there are some coffers with no name, this is a possible situation, or is just a failure?

 

Henrique

EESignature

Message 19 of 19

Dear, all my friends.

I think have a solution (ideas):
First: select dimension 1, select (Pick) other texts (group text 1) (1, H8.5, 2H1, H4...)---->row 1
Then: right click (purpose to split into two lines in excel)
Second: Continue select dimension 2, select (pick) group text 2 (2, H6,5)---->row 2.
......
Just like that, Every time we select a group of them in a row in excel and finish (another line) by pressing the right mouse button.
End: double click (2 enter).
I hope to receive feedback and comments.
Please, you help me write a lisp work it. Only just like that is okay. I think so. That could solve my problem.
Thank all you very much!
Please.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost