Hello,
I have lisp code, and request to anybody of you, if someone have any time to improve this code.
At a moment code "qwe" can write line length, such as in example "650.2151", can someone of you improve this code, which write length 650.21, and "diameter" which I write manual, such as "d=250 l=650.21". Also I need, that this code will work not only for line, but for line ant polyline.
dwg file here:
http://www18.zippyshare.com/v/41880230/file.html
lisp file here:
at this moment when I click on line with this code, on the line display length (such as 650.2151), I need, that display d=250 l=650.21,
l=650.21 is the same like 650.2151,
and
d=250 is "diameter of pipe", which I want to write manually,
for example I select 5 length, on every line show each line lenght, and near length display diamater (in this example I choosed 250) the same on every lines
dwg file:
(defun c:qwe (/ i sset ename vobj diam len mp ang text mspace)
(vl-load-com) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) ) (setq i 0) (setq sset (ssget '((0 . "*LINE")))) (repeat (sslength sset) (setq ename (ssname sset i)) (setq vobj (vlax-ename->vla-object ename)) (command ".ZOOM" "Object" ename "") (setq diam (getreal "\Enter diametar value:") len (vla-get-length vobj) mp (vlax-curve-getPointAtDist vobj (/ len 2)) ) (if (= "LINE" (cdr (assoc 0 (entget ename))) ) (setq ang (vla-get-angle vobj)) (setq ang 0) ) (setq text (vla-addtext mspace (strcat "d=" (rtos diam 2 0) " l=" (rtos len 2 2)) (vlax-3d-point mp) (getvar 'textsize) ) ) (vla-put-alignment Text acalignmentbottomcenter) (vla-put-textalignmentpoint text (vlax-3d-point mp)) (vla-put-rotation text ang) (setq i (+ i 1)) ) (princ "\nLine Not Selected :") (princ) )
Is this ok for you?
I just don't know what's the best for rotation of text in polyline, so I put that value to be 0.
I can see some things to suggest about the code, but first, some questions: When you say you want it to work with Polylines, do you mean that you want every segment of a multi-segment Polyline labeled with its length, or would they always be a single-segment Polylines, geometrically equivalent to Lines but merely of a different entity type? Or would you want multi-segment Polylines labeled only once, with an overall length? Would they ever contain arc segments?
Thanks dicra for lisp code. One different - diameter should be entered at once, and it would be displayed on all lines.
To Kent1Cooper - I want that it display lengths and dimensions on every segments, if polyline have "n" brakes, program should show "n" lengths and dimensions. This code will be used only for straight lines/polylines.
Also one thing - diameter should be entered at once, and it would be displayed on all lines.
Your code with some modifications
(defun c:qwe (/ ss d) (initget 7) (if (and (setq d (getint "\nEnter the Diameter: ")) (setq ss (ssget "_:L" '((0 . "LINE"))))) ( (lambda (i / ss1 e dis pt1 pt2 pt3) (while (setq ss1 (ssname ss (setq i (1+ i)))) (setq e (entget ss1 )) (setq dis (distance (setq pt1 (cdr (assoc 10 e)))(setq pt2 (cdr (assoc 11 e))))) (cond ((< (car pt1)(car pt2)) (setq pt3 (polar pt1 (setq ang (angle pt1 pt2)) (/ dis 2.))) ) ((> (car pt1)(car pt2))(setq pt3 (polar pt2 (setq ang (angle pt2 pt1)) (/ dis 2.))) ) ) (entmakex (list (cons 0 "TEXT") (cons 10 (polar pt3 ang 0)) (cons 11 (polar pt3 ang 0)) (cons 1 (strcat "d=" (rtos d 2 0) " l="(rtos dis 2 2))) (cons 50 ang) (cons 72 1) (cons 73 1) (cons 40 (getvar 'textsize)))) ) ) -1 ) (princ "\n No Line(s) selected") ) (princ) )
Henrique
@CADGISCODES wrote:.... I want that it display lengths and dimensions on every segments, if polyline have "n" brakes, program should show "n" lengths and dimensions. This code will be used only for straight lines/polylines.
Also one thing - diameter should be entered at once, and it would be displayed on all lines.
This seems to work in limited testing. It does not yet have any error handling, won't work in other than the World Coordinate System, etc., etc. And I assumed Center justification would be better, so that on shorter Polyline segments, the Text is less likely to run into a corner. I would also consider using (polar) to set the Text a little bit up off the Line/Polyline. It could be made to remember your diameter value and offer it as a default on later use [that's why I left dia out of the localized variables list]. See additional comments in the code.
(vl-load-com); if necessary
(defun C:LLD ; = Label Lengths with Diameter
(/ *mark ss ent p1 p2 par)
(defun *mark (/ ang)
(setq ang
(cond
((equal (car p1) (car p2) 1e-6) (/ pi 2)); 90 degrees if vertical in either direction
((< (car p1) (car p2)) (angle p1 p2)); left-to-right
((angle p2 p1)); right-to-left
); cond
); setq
(entmake
(list
'(0 . "TEXT")
'(10 0.0 0.0 0.0);;;; seems to need this, even though it's going to recalculate it relative to the 11 value
(cons 40 (getvar 'textsize));;;; not reliable [i.e. not necessarily constant] -- specify relative to drawing scale?
(cons 1 (strcat "D=" (itoa dia) " L=" (rtos (distance p1 p2) 2 2)))
;;;; use (rtos dia 2 ?) if used (getreal)/(getdist) for diameter [# of decimal places in place of ?]
;;;; use (rtos dia ? ?) for other modes [inches-fractions, etc.]
(cons 50 ang)
(cons 7 "YourTextStyle");;;; default/current not reliable [i.e. not necessarily constant]
'(72 . 1); Centered justification [assumed better] along with 73 below
(cons 11 (mapcar '/ (mapcar '+ p1 p2) '(2 2 2))); halfway [11 is insertion for justifications other than Left]
'(73 . 0)
); list
); entmake
); defun -- *mark
(setq
dia (getint "\nPipe diameter: ");;;; use (getreal) or (getdist) if not always integer value
ss (ssget '((0 . "LINE,*POLYLINE")))
); setq
(if ss ; it found some
(repeat (sslength ss); then
(setq ent (ssname ss 0))
(if (= (cdr (assoc 0 (entget ent))) "LINE")
(progn ; then
(setq
p1 (vlax-curve-getStartPoint ent)
p2 (vlax-curve-getEndPoint ent)
); setq
(*mark)
); progn -- then [Line]
(progn ; else [Polyline]
(setq par 0)
(repeat (fix (vlax-curve-getEndParam ent))
(setq
p1 (vlax-curve-getPointAtParam ent par)
p2 (vlax-curve-getPointAtParam ent (setq par (1+ par)))
); setq
(*mark)
); repeat
); progn -- else [Polyline]
); if -- Line or not
(ssdel ent ss); on to the next
); repeat -- then
(prompt "\nNo Lines or Polylines selected."); else
); if
(princ)
); defun
Thanks Kent1Cooper
could I request you the last help for me,
I have lisp code, which count total lenth, but I need that it count and multiply by constant which I choose manual (such as in example, total lines yellow length * y + total blue lines * x = ... , example 50*2 + 60 * 3=280),
remember the another code, such as I have d200 with total l=1000 and d250 with total l=1500, i need to count total cost such as 1000*y+1500*x
one think, diamaters numbers is not only 1 or 2, it can be many differents diamaters
dwg file here:
http://www7.zippyshare.com/v/57800829/file.html
lisp file here:
http://www7.zippyshare.com/v/65689587/file.html
@CADGISCODES wrote:Thanks Kent1Cooper
could I request you the last help for me,
....
You're welcome [be sure to mark it as a Solution if it does what you were looking for].
I would suggest starting a new thread with the other question, which seems different enough to justify that. Someone who may already have code that does what you want may see it, even if they are not following this thread [especially if the Subject line is more descriptive than here -- this thread's Subject could apply to a large percentage of threads on this forum].