View Full Version : automatic distance
gazzalp
10th Dec 2008, 08:15 am
Hi everyone, im wondering if theres a way in autocad 2007/2009, to be able to click on a straight line and autocad givoing me the length, without doing a distance and selecting the two end points. Ideally i want to be able to click on 50 different lines all differnet lengths and have autocad tell me how long they are (i want to do this quickly, so clicking on a line one by one and looking at properties isnt really an option.. Also if this is possible is there a way to get autocad to make a quick table, IE: line 1= 500mm, line 2=470mm. or even better if it could put it into an excel file.
Thanks
Ritch7
10th Dec 2008, 10:55 am
i would just type DISTANCE or re-assign the command to d like what iv'e done because if im right d is for Dia. as default (Note only when drawing circles) it brings up the dim style manager as default!
gazzalp
10th Dec 2008, 11:02 am
Thanks, but that doesn't really help. I know how to do a distance to get the length of a line, but with what im doing ill have 50-100 lines drawn, all of varying lengths. Rather than typing D, then clicking the start of the first line, then the end of the line and it telling me the distance, and then repeating those steps for the other lines, i want to be able to click on a line once, and autocad tell me the length of the line. Then continue this for the other hundred or so lines and hopefully have autocad either list down all the lengths to the side, or put it into an excel file. Even having the properties menu up doesnt make this process any quicker, because id still have to click on a line, look at the length and write it down, press escape (to deselect that line) then select the next line. Hope this clarifies what im looking for.
gazzalp
10th Dec 2008, 11:40 am
Found out how to do it everyone, no need to reply now thanks
LifeoRiley0
10th Dec 2008, 04:16 pm
Are you going to share this piece of info with us? I know I will probably need to do this at some point. Thanks
gazzalp
10th Dec 2008, 08:40 pm
Sure, i didnt think about putting it in here because i found it on this site (after quite a bit of searching)
Im not sure how to do it in the box most people use, but this is what the code is:
(defun c:LST( / name file ss ssi enl ln ar ci c2s)
;----------------------------
(defun ln (l f) ;To record a LINE l in the file f
(write-line (strcat "LINE,"
(c2s (cdr (assoc 10 l)))
(c2s (cdr (assoc 11 l)))
(rtos (distance
(cdr (assoc 10 l))
(cdr (assoc 11 l))))) f)
)
;----------------------------
(defun ar (l f / c r u1 u2) ;Record an ARC
(setq c (cdr (assoc 10 l)) ;Center
r (cdr (assoc 40 l)) ;Radius
u1 (cdr (assoc 50 l)) ;Start...
u2 (cdr (assoc 51 l)) ;...and End angle
)
(write-line (strcat "ARC,"
(c2s (polar c u1 r))
(c2s (polar c u2 r))
(rtos (* r (abs (- u2 u1)))) ","
(c2s c) (rtos r)) f)
)
;-----------------------------
(defun ci (l f / r) ;To record a CIRCLE
(setq r (cdr (assoc 40 l))) ;Radius
(write-line (strcat "CIRCLE,,,,,,,"
(rtos (* 2 PI r)) ","
(c2s (cdr (assoc 10 l)))
(rtos (cdr (assoc 40 l)))) f)
)
;----------------------------
(defun c2s (x) ;Used to transform Coords in String
(strcat (rtos (car x)) "," (rtos (cadr x)) "," (rtos (caddr x)) ",")
)
;----------------------------
(setq name (getvar "dwgname"))
(if (= "." (substr name (- (strlen name) 3) 1))
(setq name (substr name 1 (- (strlen name) 4))))
(setq file (open (getfiled "Output file..." name "CSV" 1) "w")
ss (ssget) ssi -1)
(write-line
"Typ,Start X,Start Y,Start Z,End X,End Y,EndZ,Length,cen X,cen Y,cenZ,Radius"
file)
(if ss
(progn
(repeat (sslength ss)
(setq enl (entget (ssname ss (setq ssi (1+ ssi)))))
(cond
((= "LINE" (cdr (assoc 0 enl))) (ln enl file))
((= "ARC" (cdr (assoc 0 enl))) (ar enl file))
((= "CIRCLE" (cdr (assoc 0 enl))) (ci enl file))
)
))) ;end IF SS
(close file)
(princ)
)
that will put the info in a seperate excel sheet. Now that ive done that, im wondering if anyonhe could help me with another two things: I want the code to be able to add another column on the end of the excel spreadsheet (after line length) which multiplies the length by 6.2 IE: length shows up as 200mm, the end column will say 1240. Also With what im doing each line represents a number of lines, ie one line is drawn but it represents between 2-5 lines. Id like the code to be able to ask me how many lines each represents after i click on each line. so the excel spreadsheet by the end will have everything it does now, as well as a column which multilpies the length by 6.2 and a column which has the number of lines that it represents. Hope that makes sense and any help would be greatly appreciated.
Lee Mac
10th Dec 2008, 09:01 pm
Just as a side point, could you post your code in [ code] [/ code] brackets, as it makes it easier to read. :P
Cheers
gazzalp
10th Dec 2008, 09:15 pm
Will do from now on, i didnt realise it was just the code tags that needed to be selected, im still new to this :)
Lee Mac
11th Dec 2008, 01:44 am
No probs gazzalp
gazzalp
11th Dec 2008, 11:28 am
Does anyone know how to get the code to add a cell to the spreadsheet that would multiply the line length by 6.2? thanks for any help
BIGAL
12th Dec 2008, 02:27 am
just multiply your lines by the amount you want before sending to excel
(rtos (distance
(rtos (* 6.2 (distance
gazzalp
12th Dec 2008, 02:32 am
Thanks, but that doesnt exactly help me. Im completely new to lisp, never looked at how they work or tried writing even the simplest of routines. Where exactly do i put that? thanks
Lee Mac
12th Dec 2008, 12:27 pm
Something like this:
(defun c:LST (/ name file ss ssi enl ln ar ci c2s)
;----------------------------
(defun ln (l f) ;To record a LINE l in the file f
(write-line
(strcat "LINE,"
(c2s (cdr (assoc 10 l)))
(c2s (cdr (assoc 11 l)))
(rtos (* 6.2
(distance
(cdr (assoc 10 l))
(cdr (assoc 11 l))
) ;_ end distance
) ;_ end *
) ;_ end rtos
) ;_ end strcat
f
) ;_ end write-line
) ;_ end defun
;----------------------------
(defun ar (l f / c r u1 u2) ;Record an ARC
(setq c (cdr (assoc 10 l)) ;Center
r (cdr (assoc 40 l)) ;Radius
u1 (cdr (assoc 50 l)) ;Start...
u2 (cdr (assoc 51 l)) ;...and End angle
) ;_ end setq
(write-line
(strcat "ARC,"
(c2s (polar c u1 r))
(c2s (polar c u2 r))
(rtos (* r (abs (- u2 u1))))
","
(c2s c)
(rtos r)
) ;_ end strcat
f
) ;_ end write-line
) ;_ end defun
;-----------------------------
(defun ci (l f / r) ;To record a CIRCLE
(setq r (cdr (assoc 40 l))) ;Radius
(write-line
(strcat "CIRCLE,,,,,,,"
(rtos (* 2 PI r))
","
(c2s (cdr (assoc 10 l)))
(rtos (cdr (assoc 40 l)))
) ;_ end strcat
f
) ;_ end write-line
) ;_ end defun
;----------------------------
(defun c2s (x) ;Used to transform Coords in String
(strcat (rtos (car x)) "," (rtos (cadr x)) "," (rtos (caddr x)) ",")
) ;_ end defun
;----------------------------
(setq name (getvar "dwgname"))
(if (= "." (substr name (- (strlen name) 3) 1))
(setq name (substr name 1 (- (strlen name) 4)))
) ;_ end if
(setq file (open (getfiled "Output file..." name "CSV" 1) "w")
ss (ssget)
ssi -1
) ;_ end setq
(write-line
"Typ,Start X,Start Y,Start Z,End X,End Y,EndZ,Length,cen X,cen Y,cenZ,Radius"
file
) ;_ end write-line
(if ss
(progn
(repeat (sslength ss)
(setq enl (entget (ssname ss (setq ssi (1+ ssi)))))
(cond
((= "LINE" (cdr (assoc 0 enl))) (ln enl file))
((= "ARC" (cdr (assoc 0 enl))) (ar enl file))
((= "CIRCLE" (cdr (assoc 0 enl))) (ci enl file))
) ;_ end cond
) ;_ end repeat
) ;_ end progn
) ;end IF SS
(close file)
(princ)
) ;_ end defun
gazzalp
12th Dec 2008, 08:57 pm
Thanks alot for your help Lee, i can see your going to a bit of trouble to help me its much appreciated. I tried that above code, but for some reason it only did the same thing it had done before and didnt add the extra cell. Any idea why this might be? anyway now that our company has found out we can do that, we want to take it one step further. If you see the picture attached, what we ultimately want to do is kind of have 3 things linked to the excel spreadsheet. We want to be able to click on the line, and the length be taken to excel, but not only that but for it to somehow realise that each line is linked to one of the balloons and one of the numbers. so in the excel spreadsheet id like to see: Line 100 - 32.6m - 4, Line 101 - 14.7m - 4, Line 102 -18.4m - 5. Does this seem possible? I cant make the 3 items a block (because we want to be able to stretch it etc) so im not sure if this is too difficult ( also would be easier if each time we clicked on a line we didnt have to input the number, and instead the code realises what its linked to). Any help would be appreciated. Thanks heaps
Lee Mac
12th Dec 2008, 09:00 pm
Sorry, I didn't make my earlier post clear - I just stumbled upon the last post asking how to incorporate the 6.2 factor and just showed you where to put it.
gazzalp
12th Dec 2008, 09:09 pm
argh i really dont think im the person to be trying lisps, now i get this error: ; error: malformed list on input
I think i may hold off that part anyway, and see if the last thing i asked for can be done, that will save us alot more time. Anyone have any ideas how to do it?
Lee Mac
13th Dec 2008, 01:17 am
Malformed list on input normally means you have simply left off a right parenthesis ;)
gazzalp
13th Dec 2008, 10:51 pm
Still can't seem to get it working... ANyway i think ill hold off until i see if there's a way to link all 3 things together (like in one of my previous posts). Does anyone know how to do it? thanks
Lee Mac
13th Dec 2008, 11:29 pm
I think the user would have to select all three items, and not just the line for ACAD to be able to recognise what to do with them.
Using the ssget function, one could quite easily deal with the data once the user has selected the items, but I cannot see how ACAD would recognise which line belonged to which circle and text.. etc etc
gazzalp
13th Dec 2008, 11:37 pm
So you dont think there is a way in autocad that it could kind of be a block, without actually being a block? IE i would have thought i could create a button that when selected, it asks for the start of a line, end of the line, bubble position and bubble number. Then once that is done it recognises that those 3 things were input at once so they are all connected. So in a way its like a block, but obviously i cant make it a block because i need to be able to lengthen/shorten the line etc. Otherwise if worse comes to worse maybe i will just select all 3 items (the line, bubble number, and number outside the bubble). So if the code could be something like: "select first line": (click on the first line) "enter number" (enter 100) "enter bubble number" (type in 4); "select second line" (click second line) "enter bubble number" (type in 4) and have the code realise that if the first number is 100, the next will be 101, then 102 etc, so after the first line im only clicking on the line, then typing in the bubble number. Anyone have any ideas on how to do this?
Lee Mac
14th Dec 2008, 12:07 am
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?
Lee Mac
14th Dec 2008, 12:12 am
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?
Lee Mac
14th Dec 2008, 12:13 am
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
gazzalp
14th Dec 2008, 12:15 am
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
Lee Mac
14th Dec 2008, 12:20 am
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
Lee Mac
14th Dec 2008, 12:22 am
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..
Lee Mac
14th Dec 2008, 12:33 am
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
Lee Mac
14th Dec 2008, 12:34 am
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.
gazzalp
14th Dec 2008, 02:04 am
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
Lee Mac
14th Dec 2008, 02:35 am
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
Lee Mac
14th Dec 2008, 02:42 am
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
gazzalp
14th Dec 2008, 03:23 am
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
Lee Mac
14th Dec 2008, 02:31 pm
Hi Gazzalp,
Sorry if the posts were a bit waffly - I was doing it late last night...
In the drawing, I changed the blocks into single-line text on their own layer.
Lee Mac
14th Dec 2008, 02:35 pm
I don't get a problem - see attached:
Lee Mac
14th Dec 2008, 06:19 pm
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)
Lee Mac
14th Dec 2008, 07:55 pm
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
gazzalp
14th Dec 2008, 08:59 pm
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
Lee Mac
14th Dec 2008, 11:13 pm
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.
Lee Mac
14th Dec 2008, 11:23 pm
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"
"C:/"
"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.
gazzalp
15th Dec 2008, 01:03 am
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
Lee Mac
15th Dec 2008, 01:03 pm
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...
This really would be pretty difficult - ACAD is a pretty "dumb" program - and I don't mean that in the offensive way - its a useful program to use. But it just sees entities as lines, and circles. Unlike other programs, it won't recognise one line as being, say, a pipe, or a valve etc etc and realise that they are linked.
The only way I would say that you could link entities in this way is by use of a block or xref - which, as stated earlier is out of the question in this situation.
But I think my skills have been tested enough, and it has been fun to work through this problem with you Gazzalp, and I hope it saves you some time in the future.
gazzalp
16th Dec 2008, 02:10 am
No problems Lee, i figured it would be pretty difficult. And cheers for all the help, it has and will save us alot of time. :)
Lee Mac
17th Dec 2008, 01:49 am
Another thought - Using my LISP you have to select each and every set of four objects - two lines, block and text.
For future use, why not add two more attributes to your block, namely the line length and line number, and enter these attributes upon drafting the lines.
Then, although slightly tedious at first, one can extract all the data in one swoop (using eattext), and if any updates need to be made, these can be made and then the data hastily extracted again without having to go through the process of selecting all the items.
Lee Mac
17th Dec 2008, 01:52 am
You could even use a quick LISP to enter the line length into an attribute.
gazzalp
17th Dec 2008, 02:17 am
Good idea about adding the line number to the block of the bubble, but i still cant see the line length attribute working. We always draw the line first, so would there be a way we could draw the line; insert our block, it asks us for what line that block represents, and puts the block in a certain position. That way all elements are linked.... The way you suggested it seems like we couldnt have the line drawn, but wed have to input the length of the line (not easy as it goes from one end of our plan to the other, ie 42705.6mm) and all lines vary in length.
Lee Mac
17th Dec 2008, 10:10 am
I'll see what I can do :P
Lee Mac
17th Dec 2008, 01:36 pm
Ok, try this:
It will insert your block and prompt you to select the line to be "linked" with it.
(defun c:bub () (c:bubbleblock)) ; Program Shortcut
(defun c:bubbleblock (/ *error* varLst oldVars pt lin linnum bub ent linlen)
; --- Error Trap ---
(defun *error* (msg)
(mapcar 'setvar varLst oldVars)
(if (= msg "")
(princ "\nFunction Complete.")
(princ "\nError or Esc pressed... ")
) ;_ end if
(princ)
) ; end of *error*
(setq varLst (list "CMDECHO" "CLAYER")
oldVars (mapcar 'getvar varLst)
) ; end setq
; --- Error Trap ---
(setvar "cmdecho" 0)
(while
(and
(setq pt (getpoint "\nSpecify Point for Bubble: "))
(setq lin (car (entsel "\nSelect Associated Line: ")))
(setq linnum (getstring "\nSpecify Line Number: "))
(setq bub (getstring "\nSpecify Bubble Number: "))
) ;_ end and
(setq ent (entget lin))
(setq linlen (rtos (distance (cdr (assoc 10 ent)) (cdr (assoc 11 ent)))))
(makelay "Text")
(command "-insert" "C:\\" ;; Insert Filepath here
pt "" ""
"0" bub linlen
linnum
) ;_ end command
) ;_ end while
(*error* "")
(princ)
) ;_ end defun
(defun makelay (y)
(if (not (tblsearch "Layer" y))
(command "-layer" "m" y "")
(setvar "clayer" y)
) ;_ end if
) ;_ end defun
You will need to specify the filepath of the block, and I have attached the block that you will need to use.
gazzalp
17th Dec 2008, 08:36 pm
Lee, it looks like it starts tyo weork but then comes up with:
Command: bub
Specify Point for Bubble:
Select Associated Line:
Specify Line Number: 100
Specify Bubble Number: 4
Unknown command "BUB". Press F1 for help.
Unknown command "BUB". Press F1 for help.
Unknown command "0". Press F1 for help.
Unknown command "4". Press F1 for help.
Unknown command "1413.585". Press F1 for help.
Unknown command "100". Press F1 for help.
Not sure if i'm not putting in the filepath correctly, but ive put it in where you had the red text. The location for this example is just: C:\Distill
which i put in place of the red text. Not sure if im doing something wrong...
gazzalp
17th Dec 2008, 08:45 pm
Now that im a bit more awake i realised i put it in the wrong spot, so ive put it in the right spot but still get an error. It looks through all my search paths, and then says Error or Esc pressed...
Ive put the block in an area my computer is looking for and changed the lisp file to look there, so not sure what is wrong....
gazzalp
17th Dec 2008, 08:59 pm
OK its 7am, and i must also be blonde, ive figured out what i was doing wrong. So now that weve inserted that block and its assigned to that line, im guessing the old lisp routine wont work (because its asking for the lines and bubble and number to be picked, whereas the whole point of this was to only pick one thing...
Also, if this all gets working it will be great, but will there be a way that we can do this lisp for the first line, then instead of picking each line again and where we want the balloon (this will look quite messy, all balloons wont line up exactly), we can copy the balloon to another line, and just change the properties to be looking at another line (hope that makes sense)
Lee Mac
17th Dec 2008, 11:18 pm
OK its 7am, and i must also be blonde, ive figured out what i was doing wrong. So now that weve inserted that block and its assigned to that line, im guessing the old lisp routine wont work (because its asking for the lines and bubble and number to be picked, whereas the whole point of this was to only pick one thing...
I'm just providing another option.
Also, if this all gets working it will be great, but will there be a way that we can do this lisp for the first line, then instead of picking each line again and where we want the balloon (this will look quite messy, all balloons wont line up exactly), we can copy the balloon to another line, and just change the properties to be looking at another line (hope that makes sense)
The block provided is just that - a block. You can copy it to where you like and edit the attributes.
gazzalp
18th Dec 2008, 02:29 am
With editing the attributes, again thats what i was hoping the program would do - save us time by knowing the line length. Currently what we have to do is measure our lines, put them in an excel spreadsheet next to the line number, and add the bubble number. Ultimately id like to have to only click on one line, and the program recognises there is a block linked to that line, and extract the info to excel. However we have all our lines drawn first, and then come later and add our block (add one block, and copy it up the page from one line to the next) which is alot quicker and simpler than adding the block for each line. I was hoping once we added one block and linked the two items(like your prgram does) we could then copy the block to the next line, but maybe do a command to say that this new block that weve created (by copying) is linked to the next line.
BIGAL
18th Dec 2008, 03:06 am
Do your bubbles have a line connecting the bubble to the line ? if so read my other response on this forum re tables and chairs about storing a known point and saving it the block. Routine 1 insert new block routine 2 copy a block but update attributes.
gazzalp
18th Dec 2008, 07:50 am
Just read it then, seems quite complicated.... No we dont have a line connecting the bubble to the block, but if need be i guess we could always add one...
Lee Mac
18th Dec 2008, 12:13 pm
Again, its that issue of ACAD recognising which block goes with which line - I suppose its a toss up between using the LISP to insert the block for each line - that way you won't have to measure the line yourself; or not using the attributed block and selecting the three items to write it to Excel.
Lee Mac
18th Dec 2008, 12:46 pm
But then I suppose anything is better than measuring the line manually and inputting that information into Excel - that must have been tedious...
gazzalp
18th Dec 2008, 08:27 pm
Yeah it is, we can have 100 lines or more, all of varying lengths. Ill have a think about it, but now that ive done all this work my boss wants me to get into VBA anyway.... thanks for all your help though Lee
Lee Mac
19th Dec 2008, 12:49 am
Well its been interesting working it through with you anyway :P
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.