Jump to content

Recommended Posts

Posted

Hi everyone, my name is Alberto, i'm from Brasil, and i studing about lisp almost a week. I read a "4 dummies" tutorial, who teaches how to draw a square using lisp, and, could understand a little about lisp, the suficient to write this lisp.

 

(Defun C:DSS ()
(setq bnum (getint "\nEntre com um numero: "))

 (setq inum (itoa bnum))

  (Setq PT1 (GetPoint "\nPonto de Desapropriação: " )) 

   (Command "-INSERT""PONTO" PT1 "1""1""0" inum inum "")

(while (/= nil PT1)
    (setq bnum (+ bnum 1))
     (setq inum (itoa bnum))
      (setq PT1 (getpoint "\nEscolha proximo ponto: "))
       (Command "-INSERT""PONTO" PT1 "1""1""0" inum inum "")
(Princ) 
)
) 

 

That's not a "pro lisp", but is the better i could do, with my knowledge for now... I want to continues reading about lisp, and write better lisps... So, my request is...

 

I want a lisp, to select that blocks, who i have insert with the lisp above, and list then on a .xls file. In that .xls file, i wanna see: x, y coordinates and the attribute "value", the number, defined as "inum".

 

Is that possible???I would be very grateful!!! Thank's for your attention.

Posted

This can be done, but, just a few things:

 

Writing to an .xls file is pretty difficult, you may have to settle for .csv and then save as a .xls.

 

Also, if you wanted to go down another route, does eattext not suffice?

Posted

Another, perhaps simpler option, write it all to simply a text file. You can look up the (open), (write-line) and (close) functions in the LISP help files in AutoCAD.

 

Just make sure the data you're writing is a string (you can use the (itoa) or (rtos) functions for that, if need be) and, here's the kicker, use a delimiter. That is to say, toss in some symbol, like a colon ( : ) or tab between the data you're entering. When you open the text file in Excel, it will recognize the delimiters and sort the data into cells. Though, you might have to specify which delimiter to use. I believe, by default, it recognizes each line in a text file as a row, and each bit of data seperated by a tab as a column.. though I believe you -can- choose which one you want.

Posted

LEE MAC

 

 

My problem is the "number". I'm numbering many areas, delimited by a "pline". Then, i will have many "double point", since my counting start from 1 after i finish a area. I need a lisp who works that way: Select "pline", select "attribute blocks", generate a file, with the informations, x,y coordinates and "attribute value "inum""..i was actualy using dataextraction, but, it's very slow and stressful, I wanted optimize my work time

Posted
Just make sure the data you're writing is a string (you can use the (itoa) or (rtos) functions for that, if need be) and, here's the kicker, use a delimiter. That is to say, toss in some symbol, like a colon ( : ) or tab between the data you're entering. When you open the text file in Excel, it will recognize the delimiters and sort the data into cells. Though, you might have to specify which delimiter to use. I believe, by default, it recognizes each line in a text file as a row, and each bit of data seperated by a tab as a column.. though I believe you -can- choose which one you want.

 

Why not just write to a .csv file (using the same commands "open" "write-line" "close"), and the data will automatically be separated into cells by the comma delimiter.

 

Hence the name: CSV ~ Comma Separated Values

 

*just trying to save some time*

 

Lee

Posted

My problem is the "number". I'm numbering many areas, delimited by a "pline". Then, i will have many "double point", since my counting start from 1 after i finish a area. I need a lisp who works that way: Select "pline", select "attribute blocks", generate a file, with the informations, x,y coordinates and "attribute value "inum""..i was actualy using dataextraction, but, it's very slow and stressful, I wanted optimize my work time

 

Are you saying that you would like a separate file for each pline selected?

Posted
Why not just write to a .csv file (using the same commands "open" "write-line" "close"), and the data will automatically be separated into cells by the comma delimiter.

 

Hence the name: CSV ~ Comma Separated Values

 

*just trying to save some time*

 

Lee

 

Ah, I didn't know what a CSV was ^^' Thanks for clearing that up, and yeah, that would be one less step, eh?

Posted
Are you saying that you would like a separate file for each pline selected?

 

 

Yes:wink:

 

 

I managed to extract the x and y values, but I do not know how to extract the "attribute value "inum""

Posted
Yes:wink:

 

 

I managed to extract the x and y values, but I do not know how to extract the "attribute value "inum""

 

I get the feeling that you would like to write this LISP on your own, and not have someone "spoon-feed" it to you.

 

So I will just show you how to access the value of the attribute "inum" :)

 

If you are still stuck, then just ask :)

 

Lee

 

 

;  Suppose "ent" is the entity name of the block

(setq att (entnext ent))  ; Get the entity name of the Attribute

(while (not (eq "SEQEND" (cdr (assoc 0 (entget att)))))  ; While we are dealing with Attributes

 ;| The SEQEND Entity signifies the end of nested
    definitions. |;
    
 (if (eq "INUM" (cdr (assoc 2 (entget att))))  ; If we get the Attribute we want
   
   (setq val (cdr (assoc 1 (entget att)))))  ; Extract its value
 
 (setq att (entnext att)))  ; Look at the next Nested Definition

;; Our value is hence stored to "val"

Posted

Also, just for pointers, you could shorten your LISP above, like this:

 

(defun c:DSS  (/ bnum pt1)
 ; Define Function and Localise Variables
 (if (setq bnum (getint "\nEntr com um numero: "))
   ; If the user enters a number...
   (while (setq pt1 (getpoint "\nPonto de Desapropriação: "))
     ; While the user has selected a Point...      
     (command "-insert" "ponto" pt1 "1" "1" "0" (itoa bnum) (itoa bnum) "")
     ; Insert the Block at that point
     (setq bnum (1+ bnum))
     ; Increment the number
     ) ; End While
   ) ; End If
 (princ))
 ; Exit Cleanly

Posted

You could also add some "security" to the LISP, by making sure that the ATTREQ is set to 1 (prompting for attributes), and checking for the block before inserting:

 

(defun c:DSS  (/ oldatt bnum pt1)
 (setq oldatt (getvar "ATTREQ"))
 (setvar "ATTREQ" 1)
 (if (and (setq bnum (getint "\nEntr com um numero: "))
          (or (tblsearch "BLOCK" "PONTO")
              (findfile "PONTO.dwg")))
   (while (setq pt1 (getpoint "\nPonto de Desapropriação: "))
     (command "-insert" "ponto" pt1 "1" "1" "0" (itoa bnum) (itoa bnum) "")
     (setq bnum (1+ bnum))))
 (setvar "ATTREQ" oldatt)
 (princ))

Posted

THANKS!!! I'll study this, and bring a feedback to you. I will work on it hard, hehe, i'm grateful, thank you for attention.

 

I will studing, and, wishing someday know a lot, like you. Maybe i can help on this forum in this day...

Posted
THANKS!!! I'll study this, and bring a feedback to you. I will work on it hard, hehe, i'm grateful, thank you for attention.

 

I will studing, and, wishing someday know a lot, like you. Maybe i can help on this forum in this day...

 

No problem, I'm happy to share what I have learnt with you :)

 

I'm sure that you will have something that you can contribute to this forum at some point :)

 

If you do have any questions about anything I have posted, just ask and I shall try my best to explain things. :)

 

Cheers

 

Lee

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...