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

Modificating lisp- measuring polylines length

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jahbgd
2541 Views, 8 Replies

Modificating lisp- measuring polylines length

I have found this free lisp on http://www.surveydrawing.net/ but I need it to be slightly modified...

 

It calculates and prints lenght of each segment of a selected polyline- which is perfect for me.

Problem is that my drawings are in mm and I need lenght in m.

 

Simple divide by 100 would do a job... but I dont have a clue how to do it.

 

;This lisp is developed as part of Survey Drawing project, which aims to help people prepare survey drawings easily.
;You may find more such lisps at www.surveydrawing.net and www.esurveying.net

(vl-load-com)
(defun c:MLin()
(setvar "luprec" 2)
(Cre_Lay "dist" 6)
(setq disttot 0)
(setq lines(ssget (list (cons 0 "line,pline,lwpolyline"))))
(setq ctr 0)
(if (/= lines nil)
(progn
(setq len(sslength lines))
(repeat len
(setq ent(ssname lines ctr))
(setq pntList(ReadPline ent))
(setq ptCntr 0)
(repeat (1- (length pntList))
(setq fpoint(nth ptCntr pntList))
(setq epoint(nth (1+ ptCntr) pntList))
(setq thr(distance fpoint epoint))
(setq fou(angle fpoint epoint))
(setq ang(* (/ fou pi) 180))
(if (and (>= ang 90) (<= ang 270)) (setq ang(rtos (+ ang 180))) (setq ang(rtos ang)))
(setq txt_ins(MidP fpoint epoint))
(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos thr))
(command "._Change" (entlast) "" "p" "la" "dist" "") 
(setq disttot(+ disttot (distance fpoint epoint)))
(setq ptCntr(1+ ptCntr))
)
(setq ctr(1+ ctr))
)
(princ (strcat "\nTotal distance :" (rtos disttot 2 4)))
)
)
(princ)
)
(princ "\nType \"MLin\" to Measure each Segment of the Polyline.") (princ)
; Function to find the mid point of two points.
(defun MidP(midp_fpo midp_spo)
(setq midp_mpo(list (/ (+ (car midp_fpo) (car midp_spo)) 2) (/ (+ (cadr midp_fpo) (cadr midp_spo)) 2)))
)
;Function to Create a Layer with given color.
(defun Cre_Lay(lay_layn lay_laycol)
(if (= (tblsearch "Layer" lay_layn) nil)
(command "._Layer" "n" lay_layn "c" lay_laycol lay_layn "")
(command "._Layer" "t" lay_layn "on" lay_layn "c" lay_laycol lay_layn "")
)
(princ)
)
;Function to Read Vertices of Selected Lines.
(defun ReadPline(imp_Ent)
(setq glb_obj(vlax-ename->vla-object imp_Ent))
(setq glb_PntCnt(vlax-curve-getEndParam glb_obj))
(setq returnPTList '())
(setq ptCntr 1)
(setq glb_oName(vlax-get-property glb_obj 'ObjectName))
(setq glb_OClosed nil)
(if (= glb_oName "AcDbLine")
(progn
(setq glb_EnDetails(entget imp_Ent))
(setq big_Point3d(cdr (assoc 10 glb_EnDetails)))
(setq end_Point3d(cdr (assoc 11 glb_EnDetails)))
(setq returnPTList(append returnPTList (list big_Point3d)))
(setq returnPTList(append returnPTList (list end_point3d)))
)
(progn
(setq glb_OClosed(vlax-curve-isClosed glb_obj))
(setq glb_2dDist 0)
(setq old_Point nil)
(repeat (1+ (fix glb_PntCnt))
(setq cur_Point3d(vlax-curve-getPointAtParam glb_obj (1- ptCntr)))
(setq returnPTList(append returnPTList (list cur_Point3d)))
(setq ptCntr(1+ ptCntr))
)
)
)
(setq return returnPTList)
)

 

Cheers

Jan

8 REPLIES 8
Message 2 of 9
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

.... 

It calculates and prints lenght of each segment of a selected polyline- which is perfect for me.

Problem is that my drawings are in mm and I need lenght in m.

 

Simple divide by 100 would do a job... but I dont have a clue how to do it.

....


[Better divide by 1000 instead...]

 

You should be able to do it by changing this:

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos thr))

 

to this:

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos (/ thr 1000)))

 

[It could also be done by dividing the value at the point where the 'thr' variable is set instead, but I like the idea of that remaining a distance value in current drawing units, and adjusting it only in the assigning of the content to the Text.]

Kent Cooper, AIA
Message 3 of 9
jahbgd
in reply to: Kent1Cooper

1000, of course, I dropped one zero 🙂

 

Thank you!

 

 

Message 4 of 9
jahbgd
in reply to: jahbgd

Also , would it be possible to assign text a certain style (ie. PBA-1.8...) that already exist in the drawing, or at least make text bigger.  

 

Is "1.75" size of the text? I tried putting 20 but nothing happened

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos (/ thr 1000)))

 

Thanks

Jan

Message 5 of 9
jahbgd
in reply to: jahbgd

sorry, putting 200 instead 1.75 works...

 

how ever choosing text style would be great.

Message 6 of 9
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

Also , would it be possible to assign text a certain style (ie. PBA-1.8...) that already exist in the drawing, or at least make text bigger.  

 

Is "1.75" size of the text? I tried putting 20 but nothing happened

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos (/ thr 1000)))

 

Thanks

Jan


You can put in the Style option where you would if you were doing the Text command manually.

 

(command "._Text" "_style" "PBA-1.8" "j" "bc" txt_ins "1.75" ang (rtos (/ thr 1000)))

 

Or instead of that change, you can precede the (command) function with a setting of the TEXTSTYLE System Variable:

 

(setvar 'textstyle "PBA-1.8")

 

Yes, the 1.75 is the answer to the Height prompt, assuming the current Style does not have a fixed height.  If you are [or might sometimes be] using a Style that isn't defined with zero height, the Height prompt will not occur, so you will need to handle it differently -- there are several ways to do that.  [By the way, if the height is expressed as an integer or real number, it doesn't need to be in double quotes -- it can be an actual number rather than a text string.]

 

I don't know why changing 1.75 to 20 wouldn't work, unless there are also other effects.  If it's not asking for a Height because the current Style has a fixed height, then the 1.75 should be fed in as the rotation, and the ang variable's contents as the content, and maybe there would be an unknown-command error because the intended content will arrive at the Command: prompt.  Or, is it an Annotative Text Style whose size is affected by other settings?  I haven't had a new-enough version long enough yet to get used to those, but maybe that would have an effect -- others can address that question better than I can.

Kent Cooper, AIA
Message 7 of 9
jahbgd
in reply to: Kent1Cooper

Kent, sorry to bother you, but I just realized that since I inserted /1000 it stopped aligning text with lines

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos (/ thr 1000)))

 

also is it possible to round dist to integer (to round it) and add "m"

 

thanks alot

Message 8 of 9
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

.... since I inserted /1000 it stopped aligning text with lines

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (rtos (/ thr 1000)))

 

also is it possible to round dist to integer (to round it) and add "m"

....


On the alignment, do you by any chance have running Object Snap modes on?

 

On the rounding and meter indication, yes, you can do that:

 

(command "._Text" "j" "bc" txt_ins "1.75" ang (strcat (rtos (/ thr 1000) 2 0) "m"))

Kent Cooper, AIA
Message 9 of 9
jahbgd
in reply to: Kent1Cooper

Couldn't solve the text alignment issue. I copied polylines into new drawing and it worked. I through that it could be related with UCS but it wasn't. Anyway I got it done.

 

Thanks for all help

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

Post to forums  

Autodesk Design & Make Report

”Boost