- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a lisp below which can total the selected dimensions, but I would like to add the following feature, after the total is shown the user has the option to divide the total by the inputted amount and display that amount.
It would also be nice to have the dimensions turn blue (as in selected) when selecting each dimension as currently you cant visibly see which dims are selected.
Any help much appreciated
;;;=======================[ Length.lsp ]=========================
;;; Author: Copyright© 2005-2008 Charles Alan Butler
;;; Version: 1.1 Mar. 04,2008
;;; Purpose: display the length of a selected objects
;;; and a running total, objects supported:
;;; LINE, LWPOLYLINE, POLYLINE, SPLINE, ARC, CIRCLE, DIMENSION
;;; Sub_Routines: put_txt add text to dwg
;;; Returns: -NA
;;;==============================================================
;|
I know there are many fine "Length" routines around.
This is my version and it allows the user to pick each object & displays
the length & a running total on the command line.
An option at start up lets the user optionally put the result in the drawing.
The text is placed at the user pick point and the current text style & layer are used.
The options for text insert are:
None - No text is inserted, this is the default
Each - Text is inserted after each object is selected
Total - Text is inserted only at the end of all selections & only the total is inserted.
Exit the routine by pressing Enter or picking nothing
Pressing C enter will clear the total
Pressing U enter will remove the last object
Pressing Enter while placing the text will skip the insert for that object.
|;
(defun c:length (/ en len pt txt ent_allowed total_len typ obj usercmd LenList NewTxt)
(vl-load-com)
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(defun put_txt (txt / pt)
;; Check if the drawing height is set to 0:
(if (setq pt (getpoint "\nPick Text Location..."))
(progn
(if (= 0 (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))))
(command "text" "non" pt "" "0" txt)
(command "text" "non" pt "0" txt)
)
(entlast) ; return ename
)
(prompt "\n*** Text Insert skipped ***")
)
)
(initget "Each Total None" )
(setq txt_opt (getkword "\nPut text in drawing for [Each/Total/None]. <None>"))
(or txt_opt (setq txt_opt "None"))
(setq ent_allowed '("LINE" "LWPOLYLINE" "POLYLINE" "SPLINE" "ARC" "CIRCLE" "DIMENSION")
total_len 0
)
(while (or (initget "Clear Undo")
(setq en (entsel "\nPick object for length, [Clear/Undo]."))
)
(cond
((= "Clear" en)
(if (member txt_opt '("Each" "Total"))
(put_txt (strcat "Total " (rtos total_len)))
)
(setq total_len 0 ; clear length total
LenList nil)
)
((= "Undo" en)
(if LenList
(progn
(setq total_len (- total_len (cadar LenList)))
(princ (strcat "\n** Removed " (caar LenList) " length = "
(rtos (cadar LenList)) " Running total is " (rtos total_len)))
(if (caddar LenList) (entdel (caddar LenList)))
(setq LenList (cdr LenList))
)
(prompt "\n** No more Undo possible.")
)
)
(t
(setq en (car en)
obj (vlax-ename->vla-object en)
)
(if (member (setq typ (cdr (assoc 0 (entget en)))) ent_allowed)
(progn
(cond
((vlax-property-available-p obj 'Measurement)
(setq len (vla-get-measurement obj))
)
((setq len (vlax-curve-getdistatparam en (vlax-curve-getendparam en))))
)
(setq total_len (+ len total_len))
(princ (strcat "\n" typ " length = " (rtos len)
" Running total is " (rtos total_len)))
(if (= txt_opt "Each")
(setq NewTxt (put_txt (rtos len)))
)
(if LenList
(setq LenList (cons (list typ len NewTxt) LenList))
(setq LenList (list (list typ len NewTxt)))
)
) ; progn
(alert "Not a valid object for length")
)
)
)
) ; while
(and (not (zerop total_len))
(princ (strcat "\nTotal length is " (rtos total_len)))
(if (member txt_opt '("Each" "Total"))
(put_txt (strcat "Total " (rtos total_len)))
)
)
(setvar "CMDECHO" usercmd)
(princ)
)
(prompt "\nGet Length loaded, Enter length to run")
(princ)
Solved! Go to Solution.