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

Having trouble

5 REPLIES 5
Reply
Message 1 of 6
ozitag
469 Views, 5 Replies

Having trouble

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
5 REPLIES 5
Message 2 of 6
Kent1Cooper
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, AIA
Message 3 of 6
_Tharwat
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 .

 

 

Message 4 of 6
ozitag
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
Message 5 of 6
ozitag
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
Message 6 of 6
ozitag
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

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

Post to forums  

Autodesk Design & Make Report

”Boost