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

ATTOUT and ATTIN to file by lisp

19 REPLIES 19
SOLVED
Reply
Message 1 of 20
miroko
10171 Views, 19 Replies

ATTOUT and ATTIN to file by lisp

Hello,

 

How to create a lisp to automatically export attributes from selected blocks to defined txt file without having to everytime confirm the file name, location and if the file shall be replaced?

 

Meaning is that I often export attributes to txt file for further use. It is always the same file (I just overwrite it always).

The way I do it now is selecting blocks, using ATTOUT command, then going to the desktop, selecting ATT.txt file and confirming that it is to be replaced.

 

Is there a way to make lisp or script that will just do all it in at once?

 

I found on forum such a lisp as below, but it exports all ablocks on drawing and it exports to txt file which is located in same  place as drawing and with same name as drawing. Tried to modify it but without success:

 

 

(defun c:out-att ()
(load "attout")
(setq fna (strcat (getvar "dwgprefix")
(acet-filename-path-remove (acet-filename-ext-remove (getvar "dwgname")))
".txt"
))
(setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))
(bns_attout fna ss)
)

 

 

 

Same question for ATTIN - I use attin and always same file name from same location - how to automate it with one command?

 

 

miroko

 

19 REPLIES 19
Message 2 of 20
pbejse
in reply to: miroko


@miroko wrote:

... 

I found on forum such a lisp as below, but it exports all ablocks on drawing and it exports to txt file which is located in same  place as drawing and with same name as drawing. Tried to modify it but without success:

  

miroko

 


what part of the code you want to modify?

 

The name of the target file?
replace this...
(strcat (getvar "dwgprefix") (acet-filename-path-remove (acet-filename-ext-remove (getvar "dwgname"))) ".txt")
with
(yourpathandfilename) e.g. "C:\\Users\\MyLogin\\Desktop\\today.txt"

 

Block selection? For you to be able to select from screen
Take out "X" from
(setq ss (ssget "X" '((0 . "INSERT") (66 . 1))))

to
(setq ss (ssget '((0 . "INSERT") (66 . 1))))

 

HTH

 

Message 3 of 20
miroko
in reply to: miroko

Hello

 

Thank you for help.

Sorry for not being specific enough.

 

I would like to do following.

1 Manually select blocks which i want to be exported (not selecting during lisp is active)

2 Run the lisp which will export attributes from already selected blocks to predefined file:

"C:\Documents and Settings\username\Desktop\att.txt "

 

After your reply i have following code:

 

(defun c:att-out ()
(load "attout")
(setq fna "C:\\Documents and Settings\\username\\Desktop\\att.txt")
(setq ss (ssget '((0 . "INSERT") (66 . 1))))
(bns_attout fna ss)
)

 

It is working (needed to remove brackets from around the path).

Thank you for help.

 

Could you also see on hiow it should look like when i want to import attributes from same file by lisp?

 

 

miroko

 

Message 4 of 20
pbejse
in reply to: miroko


@miroko wrote:

 

Could you also see on hiow it should look like when i want to import attributes from same file by lisp?

 

miroko

 


(defun c:att-in (/ fna)
  (load "attout")
  (if (setq fna (findfile  "C:\\Documents and Settings\\username\\Desktop\\att.txt"))
    (bns_attin  fna nil)
  )
)

 

HTH

 

Message 5 of 20
miroko
in reply to: pbejse


@pbejse wrote:

@miroko wrote:

 

Could you also see on hiow it should look like when i want to import attributes from same file by lisp?

 

miroko

 


(defun c:att-in (/ fna)
  (load "attout")
  (if (setq fna (findfile  "C:\\Documents and Settings\\username\\Desktop\\att.txt"))
    (bns_attin  fna nil)
  )
)

 

HTH

 


Hello

 

thanks for your time.

unfortunatelly this one is returning error:

--

Reading the input file... Done.; error: bad argument type: numberp: nil

--

I just exported the attributes and without any changes tried to import back and error appeared (i did not edit the create file).

For info: 'number' from error is name of one of attributes, but name of attribute is without 'p;' as it says in error   'numberp:'

 

Cannot see what can be wrong.

Tried first with edited txt file and thought that i edited it wrong but without editing it also not work.

 

Could you see once more?

 

miroko

 

Message 6 of 20
pbejse
in reply to: miroko

 


@miroko wrote:

 

thanks for your time.

unfortunatelly this one is returning error:

--

Reading the input file... Done.; error: bad argument type: numberp: nil

--

I just exported the attributes and without any changes tried to import back and error appeared (i did not edit the create file).

 

For info: 'number' from error is name of one of attributes, but name of attribute is without 'p;' as it says in error   'numberp:'

.....

miroko



Try this

 

(defun  c:att-in (/ tmpn)
  (load "attout")
  (setq #bns_attin_modified 0)
  (if (setq
        tmpn
         (findfile
           "C:\\Documents and Settings\\username\\Desktop\\att.txt"
           )
        )
    (bns_attin tmpn nil)
    )
  )

 

 

The numberp error has nothing to do with your attribute name. 🙂

 

Message 7 of 20
miroko
in reply to: pbejse

Hello

 

Now it is working, thanks!

 

Could you say what the lisp is doing? I noticed that there is lot of 'undo':

 

------------------

Reading the input file... Done._.UNDO Current settings: Auto = On, Control =
All, Combine = Yes, Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _BEGIN
Command: _.UNDO Current settings: Auto = On, Control = All, Combine = Yes,
Layer = Yes

Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _END
Command: _.UNDO Current settings: Auto = On, Control = All, Combine = Yes,
Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _BEGIN
Command: _.UNDO Current settings: Auto = On, Control = All, Combine = Yes,
Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: _END

--------------------

 

Just curious why it is like that.

But anyway thank you fo help!

 


@pbejse wrote:

 



Try this

 

(defun  c:att-in (/ tmpn)
  (load "attout")
  (setq #bns_attin_modified 0)
  (if (setq
        tmpn
         (findfile
           "C:\\Documents and Settings\\username\\Desktop\\att.txt"
           )
        )
    (bns_attin tmpn nil)
    )
  )

 

 

The numberp error has nothing to do with your attribute name. 🙂

 


 

miroko

 

Message 8 of 20
pbejse
in reply to: miroko


@miroko wrote:

Hello

 

Now it is working, thanks!

 

Could you say what the lisp is doing? I noticed that there is lot of 'undo':....

 

Just curious why it is like that.

But anyway thank you fo help!

 

miroko

 

You are welcome, Glad it works for you.

 

It is generated by the ET attouts' error sub program which i did not really spend time pondering on it. 🙂

 

If it bothers you, you can set cmdecho to 0 to "prevent" those from printing on the command prompt

 

like this

(defun  c:att-in (/ tmpn)
  (load "attout")
  (setvar 'cmdecho 0)
  (setq #bns_attin_modified 0)
  (if (setq
        tmpn
         (findfile
           "C:\\Documents and Settings\\username\\Desktop\\att.txt"
           )
        )
    (bns_attin tmpn nil)
    )
  )

 

HTH

 

Message 9 of 20
miroko
in reply to: pbejse

hello

 

thanks

 

and how to turn the cmdecho back inside this lisp?

I tried to put somewhere in end same command but with 1 instead of 0 but it does not want to work

 

miroko


@pbejse wrote:

@miroko wrote:

Hello

 

Now it is working, thanks!

 

Could you say what the lisp is doing? I noticed that there is lot of 'undo':....

 

Just curious why it is like that.

But anyway thank you fo help!

 

miroko

 

You are welcome, Glad it works for you.

 

It is generated by the ET attouts' error sub program which i did not really spend time pondering on it. 🙂

 

If it bothers you, you can set cmdecho to 0 to "prevent" those from printing on the command prompt

 

like this

(defun  c:att-in (/ tmpn)
  (load "attout")
  (setvar 'cmdecho 0)
  (setq #bns_attin_modified 0)
  (if (setq
        tmpn
         (findfile
           "C:\\Documents and Settings\\username\\Desktop\\att.txt"
           )
        )
    (bns_attin tmpn nil)
    )
  )

 

HTH

 


 

Message 10 of 20
AR12
in reply to: miroko

Hi miroko,

Here's how I do it in my programs:

 

;;;At the Beginning of program:

;;;Save and Change AutoCAD Variables
(setq CE-SAVE (getvar "cmdecho"))

;;;Change AutoCAD variables
(setvar "cmdecho" 0)

;;;At the end of program:

;;Return Variables to original state
(setvar "cmdecho" CE-SAVE)

 

Thanks,
Adam Richardson

If needed: AutoCAD 2017 User using Visual LISP for editing LISP and DCL files
Message 11 of 20
miroko
in reply to: AR12


@AR12 wrote:

Hi miroko,

Here's how I do it in my programs:

 

;;;At the Beginning of program:

;;;Save and Change AutoCAD Variables
(setq CE-SAVE (getvar "cmdecho"))

;;;Change AutoCAD variables
(setvar "cmdecho" 0)

;;;At the end of program:

;;Return Variables to original state
(setvar "cmdecho" CE-SAVE)

 


Hi AR12,

 

It is working fine.

 

Thank you.

 

regards

miroko

Message 12 of 20
chestanu435
in reply to: miroko

i m using attout to extract blocks within blocks but it is not coming , is this possible

PLEASE reply....

Message 13 of 20
pbejse
in reply to: chestanu435


@chestanu435 wrote:

i m using attout to extract blocks within blocks but it is not coming , is this possible

PLEASE reply....


Can you be more specific chestanu435? 

Message 14 of 20
flaneto
in reply to: miroko

Hi guys!
I have a question about this discussion, I don't want to create a new for this...


So, I'm try to create a LSP and/or scr to do ATTOUT in multiple files, whatever it is opened or by folder. Using the lsp that I found here, the dialog of ATTOUT appears, but with this it's impossible to create anything.


I'm using AutoCAD 2016.


Anyone know what can I do?


Thanks!

Message 15 of 20
lboey
in reply to: pbejse

Hi,

 

I'm new to AutoLisp..

 

Can you explain how can i use this .lsp function in a script file (.scr)???

 

I'm trying to automise the ATTOUT operation in Java but i don't know how 😞

 

Many thanks!!

Message 16 of 20
dbroad
in reply to: lboey

Stop cross posting new questions on old threads.  Stop duplicating your threads!  Wait till the conversation develops.

Architect, Registered NC, VA, SC, & GA.
Message 17 of 20
margono_bersinar
in reply to: pbejse

sorry sir, can you help me how i can modify that Att-out automatice export atribute with specific name, ex:TB-ASBUILTSHOPDWG, or TB 1.

I want use that lisp on script so i can export title drawing on all my drawing. thank you

Message 18 of 20
WeTanks
in reply to: pbejse

@pbejse 

I also want to automate my ATTOUT, but without success,
What's wrong?

(defun  c:MyAttout (/ tmpn)
  (load "attout")
  (setvar 'cmdecho 0)
  (setq #bns_attin_modified 0)
  (if (setq
        tmpn
         (findfile
           "D:\soft\att.txt"
           )
        )
    (bns_attin tmpn nil)
    )
  )

 

 

We.Tanks



A couple of Fusion 360 improvement ideas that could your vote/support:
図面一括印刷

Message 19 of 20
ronjonp
in reply to: WeTanks

@WeTanks 

Try changing this:

"D:\soft\att.txt"

to this

"D:\\soft\\att.txt"

Message 20 of 20
WeTanks
in reply to: ronjonp

Thanks.
I fixed it,
But this is it.

Done.nil

 

WeTanks_0-1691705059629.png

 

We.Tanks



A couple of Fusion 360 improvement ideas that could your vote/support:
図面一括印刷

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

Post to forums  

Autodesk Design & Make Report

”Boost