Jump to content

automatic distance


gazzalp

Recommended Posts

From your last post I got the impression that you require a LISP that helps you to draw these lines and bubbles - not extract the info from pre-drawn ones... can you verify which of these is your request?

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    30

  • gazzalp

    24

  • BIGAL

    2

  • Ritch7

    1

Top Posters In This Topic

Posted Images

If you were to select the items, an ssget function with a cond function could filter out the various elements in the selection set and extract the necessary data from them to maybe write to an excel spreadsheet.

 

i.e. select all the objects using the ssget, then, find the size of the selection set using the sslength command.

 

from this you could go through the selection set using a repeat function and cond function i.e.

 

(setq ss (ssget))
(setq xth 0)
(repeat (sslength ss))
(setq ent (entget (ssname ss xth))
(cond
  ((= (cdr (assoc 0 ent)) "TEXT")
   (setq txt (cdr (assoc 1 ent)))
  ) ; end condition 1 
etc etc

(setq xth (+ 1 xth))
) ; end repeat
.... etc etc

 

Something like that maybe?

Link to comment
Share on other sites

But i must admit, I am not very good at making LISPs that write data to spreadsheets or txt files, I believe you use a "write-line" command, but to be honest, I do not know..

 

So if it is that you would like, someone else may have to contribute... :D

Link to comment
Share on other sites

Lee, thanks very much for your help. What i require is to extract info from pre drawn lines etc. IE we will have the lines, bubbles and numbers all drawn, and then i want to take all that info into excel (line length, bubble number number outside bubble) so the spreadsheet would look like:

 

number 100 - length 470mm - 4

Number 101 - length 376mm - 4

number 102 - length 402mm - 5

 

etc. but i would rather not have to choose all 3 items and instead be able to select just the lines and have the code realise that each line has also a buble and number attached to it. However if there is no way to do this and i need to select all 3 items then that will suffice.

 

thanks again

Link to comment
Share on other sites

In that case, as a start a LISP similar to the one posted above should do the trick.

 

If the object is made from:

 

two lines

a circle

some text

 

the LISP will need some way to determine which line needs to be measured - so are these lines on different layers?

 

i.e. one could then use:

 

(cond
 ((and
      (= "LAYER1" (cdr (assoc 8 ent)))
      (= "LINE" (cdr (assoc 0 ent)))
  ) ; end and
) ; end cond

Link to comment
Share on other sites

But maybe I am approaching this from too complicated a way.... I am just trying to determine how to extract the necessary data from the selection set - but the user would need to make sure that the selection was accurate - so this may not be the best method - maybe there is an Active X method to accomplish the same thing..

Link to comment
Share on other sites

If the objects were like the attached diagram, the information could be extracted with the following code (untested):

 

(defun c:bubble    (/ ss ssl xth ent txt1 txt2 len)
   (setq ss (ssget))
   (setq ssl (sslength ss)
     xth 0
   ) ;_  end setq
   (repeat ssl
   (setq ent (entget (ssname ss xth)))
   (cond
       ((and
        (= "TEXT" (cdr (assoc 0 ent)))
        (= "6" (cdr (assoc 8 ent)))
        ) ;_  end and
        (setq txt1 (cdr (assoc 1 ent)))
       )
       ((and
        (= "TEXT" (cdr (assoc 0 ent)))
        (= "2" (cdr (assoc 8 ent)))
        ) ;_  end and
        (setq txt2 (cdr (assoc 1 ent)))
       )
       ((and
        (= "LINE" (cdr (assoc 0 ent)))
        (= "4" (cdr (assoc 8 ent)))
        ) ;_  end and
        (setq len (distance
              (cdr (assoc 10 ent))
              (cdr (assoc 11 ent))
              ) ;_  end distance
        ) ;_  end setq
       )
   ) ;_  end cond
   (setq xth (+ 1 xth))
   ) ;_  end repeat
   (princ)
) ;_  end defun

example.jpg

Link to comment
Share on other sites

In the above example, the two different lines are on separate layers, and so are the two different texts.

 

This means the different entities can be extracted using the different values of the DXF code 8.

Link to comment
Share on other sites

Thanks Lee, not sure if it worked properly (didnt send it to excel). I have attached the kind of drawing i need to do the excel spreadsheet on. The only thing that may be a problem is that the bubble and the number in the bubble are a block, but if need be we can change that and just have a circle with single line text. Will your code be able to send the info for this dwg to an excel file? your help is very much appreciated

Drawing1.dwg

Link to comment
Share on other sites

Hi Gazzalp,

 

The posted LISP is just an example of how the info can be obtained, I am not too good at writing data to Excel as such... will have to read up on it... :P

 

but all the necessary data is stored in variables: txt1, txt2, len... etc etc

Link to comment
Share on other sites

OK,

 

I have edited your drawing slightly, and am making some headway - but its 2:05am here and I am tired... *but addicted to LISP*....

 

Try this code:

 

(defun c:bubble    (/ ss ssl xth ent txt1 txt2 len)
   (setq ss (ssget))
   (setq ssl (sslength ss)
     xth 0
   ) ;_  end setq
   (repeat ssl
   (setq ent (entget (ssname ss xth)))
   (cond
       ((and
        (= "TEXT" (cdr (assoc 0 ent)))
        (= "Text" (cdr (assoc 8 ent)))
        ) ;_  end and
        (setq txt1 (cdr (assoc 1 ent)))
       )
       ((and
        (= "TEXT" (cdr (assoc 0 ent)))
        (= "Text 2" (cdr (assoc 8 ent)))
        ) ;_  end and
        (setq txt2 (cdr (assoc 1 ent)))
       )
       ((and
        (= "LINE" (cdr (assoc 0 ent)))
        (= "Reo & Stress" (cdr (assoc 8 ent)))
        ) ;_  end and
        (setq len (distance
              (cdr (assoc 10 ent))
              (cdr (assoc 11 ent))
              ) ;_  end distance
        ) ;_  end setq
       )
   ) ;_  end cond
   (setq xth (+ 1 xth))
   ) ;_  end repeat
   (alert (strcat "Number: "
          txt1
          "\nLength: "
          (rtos len)
          "\nBubble: "
          txt2
      ) ;_  end strcat
   ) ;_  end alert
   (princ)
) ;_  end defun

 

And select the sets of objects in the attached drawing - let me know if this is nearer what you are after :P

Test.dwg

Link to comment
Share on other sites

not sure if thats what im after, i get an error: bad argument type: stringp nil. What am i doing wrong?

 

what exactly do i need to select and in what order? also what exactly did you change in the drawing? thanks heaps

Link to comment
Share on other sites

Ok, I've made some advancement on the problem - try the following LISP:

 

(defun c:bubble    (/ ss ssl xth ent txt1 txt2 len file1)
   (selfile)
   (setq file1 (open file "w"))
   (while
   (/= (setq ss (ssget)) nil)
      (setq ssl (sslength ss)
        xth 0
      ) ;_  end setq
      (repeat ssl
          (setq ent (entget (ssname ss xth)))
          (cond
          ((and
           (= "TEXT" (cdr (assoc 0 ent)))
           (= "Text" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq txt1 (cdr (assoc 1 ent)))
          )
          ((and
           (= "TEXT" (cdr (assoc 0 ent)))
           (= "Text 2" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq txt2 (cdr (assoc 1 ent)))
          )
          ((and
           (= "LINE" (cdr (assoc 0 ent)))
           (= "Reo & Stress" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq len (distance
                 (cdr (assoc 10 ent))
                 (cdr (assoc 11 ent))
                 ) ;_  end distance
           ) ;_  end setq
          )
          ) ;_  end cond
          (setq xth (+ 1 xth))
      ) ;_  end repeat    
      (write-line
          (strcat "Number: "
              txt1
              "\nLine Length: "
              (rtos len 2 2)
              "\nBubble Number: "
              txt2
              "\n"
          ) ;_  end strcat
          file1
      ) ;_  end write-line
   ) ;_  end while
   (close file1)
   (princ)
) ;_  end defun


(defun selfile ()
   (setq file (getfiled "Select a Text File"
            "C:/"
            "txt"
            9
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

 

This will write the data to a txt file. --->> We're getting there 8)

Link to comment
Share on other sites

Ok,

 

I think I have got it -

 

This will write all your required data to Excel.

 

(defun c:bubble    (/ ss ssl xth ent txt1 txt2 len file1)
   (selfile)
   (setq file1 (open file "w"))
   (write-line "Line Number, Line Length, Bubble Number" file1)
   (while
   (/= (setq ss (ssget)) nil)
      (setq ssl (sslength ss)
        xth 0
      ) ;_  end setq
      (repeat ssl
          (setq ent (entget (ssname ss xth)))
          (cond
          ((and
           (= "TEXT" (cdr (assoc 0 ent)))
           (= "Text" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq txt1 (cdr (assoc 1 ent)))
          )
          ((and
           (= "TEXT" (cdr (assoc 0 ent)))
           (= "Text 2" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq txt2 (cdr (assoc 1 ent)))
          )
          ((and
           (= "LINE" (cdr (assoc 0 ent)))
           (= "Reo & Stress" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq len (distance
                 (cdr (assoc 10 ent))
                 (cdr (assoc 11 ent))
                 ) ;_  end distance
           ) ;_  end setq
          )
          ) ;_  end cond
          (setq xth (+ 1 xth))
      ) ;_  end repeat    
      (write-line
          (strcat txt1
              ","
              (rtos len 2 2)
              ","
              txt2
          ) ;_  end strcat
          file1
      ) ;_  end write-line
   ) ;_  end while
   (close file1)
   (princ)
) ;_  end defun


(defun selfile ()
   (setq file (getfiled "Select Location & Name of Excel File"
            "C:/"
            "csv"
            9
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

Link to comment
Share on other sites

Looks good Lee, works a treat. Only problem now is weve got hundreds of drawings with the circle and number as a block, is it possible to make the routine work for it? I would have thought its not much harder, the number in the buble is just an attribute, and i know excel can extract attributes.

 

Thanks heaps Lee

Link to comment
Share on other sites

I can make the LISP extract the attribute, but this seems to overide the other functions used to write the line length and line number. And also, you are left with all the other data from the block, including all the base points and other data like that.

 

Also, I have used a "while" function, so that the user can write more than one of these diagrams to the excel sheet. but with the attribute extraction, ACAD does not like to add some more attributes to the same file when you re-invoke the -eattext function.

Link to comment
Share on other sites

OK OK.... Forget that last post - complete nonsense... I went about it the complete wrong way!

 

Try this:

 


;   .: Bubble Data Extractor LISP :.
;
;         .: by Lee McDonnell :.
;
;          .: December 2008 :.


(defun c:bubble    (/ file1 ss ssl xth ent txt1 txt2 len)
   (selfile)
   (setq file1 (open file "w"))
   (write-line "Line Number, Line Length, Bubble Number" file1)
   (while
   (/= (setq ss (ssget)) nil)
      (setq ssl (sslength ss)
        xth 0
      ) ;_  end setq
      (repeat ssl
          (setq ent (entget (setq ent1 (ssname ss xth))))
          (cond
          ((and
           (= "TEXT" (cdr (assoc 0 ent)))
           (= "Text" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq txt1 (cdr (assoc 1 ent)))
          )
          ((and
           (= "LINE" (cdr (assoc 0 ent)))
           (= "Reo & Stress" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq len (distance
                 (cdr (assoc 10 ent))
                 (cdr (assoc 11 ent))
                 ) ;_  end distance
           ) ;_  end setq
          )
          ((and
           (= "INSERT" (cdr (assoc 0 ent)))
           (= "Text" (cdr (assoc 8 ent)))
           ) ;_  end and
           (setq att (entget (entnext ent1)))
           (setq txt2 (cdr (assoc 1 att)))
          )
          ) ;_  end cond
          (setq xth (+ 1 xth))
      ) ;_  end repeat    
      (write-line
          (strcat txt1
              ","
              (rtos len 2 2)
              ","
              txt2
          ) ;_  end strcat
          file1
      ) ;_  end write-line
   ) ;_  end while
   (close file1)
   (princ)
) ;_  end defun


(defun selfile ()
   (setq file (getfiled "Create an Excel File"
            "[b][color=Red]C:/[/color][/b]"
            "csv"
            9
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

By the way, if you want to change the default location of where it prompts you to save the Excel file, change the highlighted text to a valid filepath.

Link to comment
Share on other sites

Thanks alot Lee works like a charm :) thanks alot for your help. If you really want to test out your skills, see if you can think of a way to link the three items together, so we would only have to click on the line, and have the command recognise the bubble number and other number belongs to that. I believe this would be pretty difficult, so what youve done so far is awesome. thanks alot

Link to comment
Share on other sites

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...