Visual LISP, AutoLISP and General Customization

Reply
Contributor
miroko
Posts: 19
Registered: ‎03-06-2011
Message 1 of 13 (2,219 Views)
Accepted Solution

ATTOUT and ATTIN to file by lisp

2219 Views, 12 Replies
10-03-2012 02:43 PM

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:smileysurprised:ut-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

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 2 of 13 (2,205 Views)

Re: ATTOUT and ATTIN to file by lisp

10-03-2012 08:37 PM 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

 

Contributor
miroko
Posts: 19
Registered: ‎03-06-2011
Message 3 of 13 (2,178 Views)

Re: ATTOUT and ATTIN to file by lisp

10-04-2012 08:32 AM 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

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 4 of 13 (2,160 Views)

Re: ATTOUT and ATTIN to file by lisp

10-04-2012 08:15 PM 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

 

Contributor
miroko
Posts: 19
Registered: ‎03-06-2011
Message 5 of 13 (2,138 Views)

Re: ATTOUT and ATTIN to file by lisp

10-07-2012 12:13 PM 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

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 6 of 13 (2,126 Views)

Re: ATTOUT and ATTIN to file by lisp

10-07-2012 07:40 PM 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. :smileyhappy:

 

Contributor
miroko
Posts: 19
Registered: ‎03-06-2011
Message 7 of 13 (2,097 Views)

Re: ATTOUT and ATTIN to file by lisp

10-08-2012 01:09 PM 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. :smileyhappy:

 


 

miroko

 

*Expert Elite*
pbejse
Posts: 2,440
Registered: ‎11-24-2009
Message 8 of 13 (2,085 Views)

Re: ATTOUT and ATTIN to file by lisp

10-08-2012 06:02 PM 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. :smileyhappy:

 

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

 

Contributor
miroko
Posts: 19
Registered: ‎03-06-2011
Message 9 of 13 (2,067 Views)

Re: ATTOUT and ATTIN to file by lisp

10-10-2012 10:41 AM 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. :smileyhappy:

 

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

 


 

Valued Contributor
AR12
Posts: 90
Registered: ‎12-28-2009
Message 10 of 13 (2,064 Views)

Re: ATTOUT and ATTIN to file by lisp

10-10-2012 11:44 AM 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 2013 User using Visual LISP for editing LISP and DCL files

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community