Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 1 of 6 (262 Views)

Having trouble

262 Views, 5 Replies
10-29-2012 02:07 PM

Hi,

Just thought I'd write a LISP file to create a lisp file that contains an entmake for all the items selected. I will reuse the code in another file I've created but want to extend, so this is just a test. Below is what I have. It works in saving it out. But, the code it creates contains the -1 and 330 codes which create an error: extra cdrs in dotted pair on input. If you remove them manually (haven't looked in to removing them in the program yet) then I get a bad DXF group (0 . POINT). A couple of questions:

1. Why doesn't it like using the -1 and 330 codes?

2. Is there a way to write it to file so it does like them or is it best that I just remove them?

3. Am I going about this the right way or Is there a simpler way of doing this?

 

I've done very little Lisp but am starting to get a little bit of it happening.

Thanks in advance for your comments,

Ozitag

 

(defun c:test ()
  (setq file (getfiled "Select a destination and choose a file name" "C:/Test" "lsp" 145))

  (if (setq itemset (ssget ())) ;get item set
    (progn
      (setq filecheck (open file "w"))
      (write-line "(defun c:redraw()" filecheck)
      (setq counter 0) ;set counter to first item in set
      (while (< counter (sslength itemset)) ;while counter is less than the length of the set
 (setq item (ssname itemset counter)) ;get entity name of the item indexed
 (setq itemcodes(entget item)) ;get items group codes
 (write-line (strcat "(entmake (append '" (vl-princ-to-string itemcodes) "))") filecheck) ;write line to file
 (setq counter (+ counter 1))
 ) ;close while
      (write-line "(princ)" filecheck) 
      (write-line ");close defun" filecheck)
      (close filecheck)
      (startapp "notepad.exe" file)
      );close progn
    ) ;close if
  (princ)
  ) ;close defun

IV 2010
*Expert Elite*
Kent1Cooper
Posts: 5,417
Registered: ‎09-13-2004
Message 2 of 6 (232 Views)

Re: Having trouble

10-31-2012 02:30 PM in reply to: ozitag

ozitag wrote:

.... Below ... works in saving it out. But, the code it creates contains the -1 and 330 codes which create an error: extra cdrs in dotted pair on input. If you remove them manually (haven't looked in to removing them in the program yet) then I get a bad DXF group (0 . POINT). A couple of questions:

1. Why doesn't it like using the -1 and 330 codes?

2. Is there a way to write it to file so it does like them or is it best that I just remove them?

....

 (setq itemcodes(entget item)) ;get items group codes
....


Very quickly, without having dug too deep:

 

The -1 and 330 entries are entity names, and AutoCAD is going to want to assign those itself, in the process of making the entities, so it's best just to remove them.  You could do something like:

 

....

 (setq itemcodes

   (vl-remove-if '(lambda (x) (member (car x) '(-1 330))) (entget item)) ; get item's group codes without entity names

 )

....

 

(0 . POINT) should be (0 . "POINT").  Could it be that something in the processing of things is removing those double-quotes, which should certainly be there in what (entget) returns?

Kent Cooper
Distinguished Mentor
_Tharwat
Posts: 600
Registered: ‎07-02-2010
Message 3 of 6 (223 Views)

Re: Having trouble

10-31-2012 11:44 PM in reply to: ozitag

There are lots of work to do on the lisp file to account for each entity and write the needed DXF codes to file , so you can

use this lisp file by CAB and take a look about the big efforts that put in this routine .

 

Thanks to CAB for this nice routine .

 

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 4 of 6 (189 Views)

Re: Having trouble

11-02-2012 02:10 PM in reply to: Kent1Cooper

Thanks for the info Kent. The first part works a treat but as to what is taking the speeachmarks out it appears the vl-princ-to-string takes them out. I tried vl-prin1-to-string but that adds a slash before every speechmark. Is there any other way to get a list to a string so I can write/print it.

Thanks for your help.

Ozitag

IV 2010
Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 5 of 6 (184 Views)

Re: Having trouble

11-02-2012 02:24 PM in reply to: _Tharwat

I see what you mean by a lot of effort.

There are a lot of functions / subroutines in that lsp file. Wow.

Thanks for code.

Going through it it appears they have had the same trouble as I have with the speech marks missing, so they go through and add double speechmarks before running vl-princ-to-string on it, effectively removing what they just added, but keep the strings in tack. Seems complicated, and it seems silly that there is no function that takes it to a string without removing the speechmarks.

Thanks anyway for the code.

Regards,

Ozitag

IV 2010
Distinguished Contributor
ozitag
Posts: 288
Registered: ‎05-09-2008
Message 6 of 6 (171 Views)

Re: Having trouble

11-04-2012 02:05 PM in reply to: ozitag

Well I finally had a chance to look at this again and I got it working. Here is the code that seems to work. This is just the basis of what I'm wanting to do, but it is the hardest part so the next part is just typing ie selecting a point to draw the saved area, etc etc. Thanks for your help guys on this.

Regards,

Ozitag

 

(defun c:saveout ()
  (setq file (getfiled "Select a destination and choose a file name" "C:/Test" "lsp" 145))

  (if (setq itemset (ssget ())) ;get item set
    (progn
      (setq filecheck (open file "w"))
      (write-line "(defun c:redrawn()" filecheck)
      (setq counter 0) ;set counter to first item in set
      (while (< counter (sslength itemset)) ;while counter is less than the length of the set
 (setq item (ssname itemset counter)) ;get entity name of the item indexed
 (setq itemcodes (vl-remove-if '(lambda (x) (member (car x) '(-1 330))) (entget item))) ;get items group codes without entity names
 (setq testitemcodes (vl-princ-to-string itemcodes))
 (setq testitemcodes2 (vl-prin1-to-string itemcodes))
 (princ "(entmake (append '" filecheck)
 (print itemcodes filecheck);write line to file
 (princ "))\n" filecheck)
 ;(prin1 (strcat "(entmake (append '" (vl-prin1-to-string itemcodes) "))\n" ) filecheck) ;write line to file
 (setq counter (+ counter 1))
 ) ;close while
      (write-line "(princ)" filecheck)
      (write-line ");close defun" filecheck)
      (close filecheck)
      (startapp "notepad.exe" file)
      );close progn
    ) ;close if
  (princ)
  ) ;close defun

IV 2010
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 or visit the Installation and Licensing Forum to get help installing your software.