joykutty Posted February 16, 2007 Posted February 16, 2007 I need to find the length of a spline during the run of an autolisp program to compare it with some other value. I know that I can physically find it from properties, I need to get it to a variable. I use autocad 2007 and relatively new programmer in autolisp - joy kutty Quote
Adesu Posted February 16, 2007 Posted February 16, 2007 Hi joy, try this ;| From Turvill.com TLEN.LSP - Total LENgth of selected objects (c) 1998 Tee Square Graphics |; (defun C:TLEN (/ ss tl n ent itm obj l) (setq ss (ssget) tl 0 n (1- (sslength ss))) (while (>= n 0) (setq ent (entget (setq itm (ssname ss n))) obj (cdr (assoc 0 ent)) l (cond ((= obj "LINE") (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent)))) ((= obj "ARC") (* (cdr (assoc 40 ent)) (if (minusp (setq l (- (cdr (assoc 51 ent)) (cdr (assoc 50 ent))))) (+ pi pi l) l))) ((or (= obj "CIRCLE")(= obj "SPLINE")(= obj "POLYLINE") (= obj "LWPOLYLINE")(= obj "ELLIPSE")) (command "_.area" "_o" itm) (getvar "perimeter")) (T 0)) tl (+ tl l) n (1- n))) (alert (strcat "Total length of selected objects is " (rtos tl))) (princ) ) I need to find the length of a spline during the run of an autolisp program to compare it with some other value. I know that I can physically find it from properties, I need to get it to a variable. I use autocad 2007 and relatively new programmer in autolisp - joy kutty Quote
ASMI Posted February 16, 2007 Posted February 16, 2007 To calculate length of ANY CURVE: (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) where 'ent' is entity. Example with check on empty selection and an opportunity of definition of length: (defun c:lent(/ ent enPar) (vl-load-com) (and (setq ent (entsel "\nSelect curve > ")) (not (vl-catch-all-error-p (setq enPar (vl-catch-all-apply 'vlax-curve-getEndParam (list(car ent)))))) (princ (strcat "\nLength = " (rtos (vlax-curve-getDistAtParam(car ent) enPar)) ); end stracat ); end princ ); end and (princ) ); end of c:lent Do not foget (vl-load-com) for VisualLISP extension loading. Quote
joykutty Posted February 17, 2007 Author Posted February 17, 2007 Thank u Adesu, Thank u Asmi; this solved my problem except that I have to still physically select the curve. Is there any way I can select item by by the program itself rather than physical selection Joy Kutty Quote
CarlB Posted February 17, 2007 Posted February 17, 2007 What do you know about the spline to be able to identify it? Does the routine create it? If so, after creation you can save the entity name with; (setq ent (entlast)) then use that 'ent' variable as shown in the examples. Quote
ASMI Posted February 17, 2007 Posted February 17, 2007 If you already have one or many splines, to you are necessary to create a set by function SSGET. Here a short example of creation of the list (( 'length).......) from all splines of the drawing: (defun test(/ splSet splLst lenLst) (vl-load-com) (if ; create selection set with splines (setq splSet (ssget "_X" '((0 . "SPLINE")))) ; if selection set is present (progn ; transform selection set to list (setq splLst (vl-remove-if 'listp (mapcar 'cadr(ssnamex splSet))) ; create empty list lenLst '() ); end setq ; foreach entity in list (foreach ent splLst ; add to list 'lenLst' list ('entity' 'entity length') (setq lenLst (cons (list ent (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) ); end list lenLst ); end cons ); end setq ); end foreach ); end progn ); end if ); end of test If I have 3 splines: Command: (test) ((<Entity name: 7ef8ee98> 4209.15) (<Entity name: 7ef8eea0> 4088.42) (<Entity name: 7ef8eeb0> 1993.6)) Now you can sort and compare length values with each spline. Look more detailed information of function SSGET. It allows to create very complex filters. Quote
joykutty Posted February 17, 2007 Author Posted February 17, 2007 The routine defines following points and draws a spline by the command (command "spline" F U V S2 S "" "" "") I tried (setq ent (entlast)) but it doesn't work in the routine given by ASMI. It shows "error: bad argument type: consp " Joy Kutty Quote
ASMI Posted February 17, 2007 Posted February 17, 2007 You something do wrong. See I draw spline and measure it length: (defun c:test2(/ pt1 pt2 pt3 pt4 pt5 ent sLen) (vl-load-com) (princ "\n<<<Specify five points of spline >>> ") (if (and (setq pt1(getpoint "\nPoint 1 of 5 > ")) (setq pt2(getpoint "\nPoint 2 of 5 > ")) (setq pt3(getpoint "\nPoint 3 of 5 > ")) (setq pt4(getpoint "\nPoint 4 of 5 > ")) (setq pt5(getpoint "\nPoint 5 of 5 > ")) ); end and (progn (command "_.spline" pt1 pt2 pt3 pt4 pt5 "" "" "") (setq ent(entlast) sLen(vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) ); end setq (princ (strcat "\nYour spline length = " (rtos sLen)) ); end princ ); end progn ); end if (princ) ); end of c:test2 Command: test2 <<<Specify five points of spline >>> Point 1 of 5 > Point 2 of 5 > Point 3 of 5 > Point 4 of 5 > Point 5 of 5 > Your spline length = 157.6277 Quote
chykoxp Posted October 10, 2007 Posted October 10, 2007 Hi, sorry to open the discussion again, but i need a code that makes the addition of several splines length. Hopr for reply Quote
ASMI Posted August 19, 2008 Posted August 19, 2008 This http://www.asmitools.com/Files/Lisps/Elen.html Quote
Recommended Posts
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.