Avcit Posted June 24, 2016 Posted June 24, 2016 (edited) Hello guys, I couldn't add the length of the line to csv. I want to extract like this: K5172, 60/60, 720 Can anyone help me with this code? (defun c:rp2 (/ ent1 ent2 ent3 len fh fname) (setq fname (strcat (getvar "dwgprefix") (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4 )) ".csv") fh (open fname "a") ) (command "_-LAYER" "_M" "SELECTED" "_C" 2 "" "") (while (setq en1 (car (entsel "\nPick Text: "))) (setq ent1 (entget en1) ent1 (subst (cons 8 "SELECTED") (assoc 8 ent1) ent1) ) (entmod ent1) (setq en2 (car (entsel "\nPick another text: "))) (setq ent2 (entget en2) ent2 (subst (cons 8 "SELECTED") (assoc 8 ent2) ent2) ) (entmod ent2) (setq en3 (car (entsel "\nPick the line: "))) (setq ent3 (entget en3) len (distance (cdr (assoc 10 ent3)) (cdr (assoc 11 ent3)) ) ) (write-line (strcat (cdr (assoc 1 ent1)) ", " (cdr (assoc 1 ent2))) fh) ) (princ (strcat "\nFile: " fname " Created.")) (close fh) ) Edited June 25, 2016 by Avcit Quote
Tharwat Posted June 24, 2016 Posted June 24, 2016 Add this part: (write-line (strcat (cdr (assoc 1 ent1)) ", " (cdr (assoc 1 ent2)) [color="blue"]", " (rtos len 2 4)[/color]) fh) Quote
Avcit Posted June 24, 2016 Author Posted June 24, 2016 Thanks. It works How can I define length and area for polyline? I just want to click just one polyline and it will export its length and area to csv. Quote
Tharwat Posted June 24, 2016 Posted June 24, 2016 (edited) Thanks. It works You are welcome. Thanks. It works How can I define length and area for polyline? I just want to click just one polyline and it will export its length and area to csv. Try the following and hope you are able to add it to your codes: (if (and (setq s (car (entsel "\nSelect Polyline :"))) (= (cdr (assoc 0 (entget s))) "LWPOLYLINE") ) (setq lgth (vlax-curve-getdistatparam s (vlax-curve-getendparam s)) area (vlax-curve-getarea s) ) (princ "\nNull selection or object is not a LWpolyline !") ) Edited June 25, 2016 by Tharwat Quote
Avcit Posted June 25, 2016 Author Posted June 25, 2016 It gives an error. Pick Text: Pick another text: Pick the line: Select Polyline :; error: no function definition: [color="blue"]VLAX-CURVE-GETENDPOINT[/color] I don't need to "if loop", because all my polylines are closed. (Shown in picture) Quote
Tharwat Posted June 25, 2016 Posted June 25, 2016 Just add the following function to load the VL* functions library at the top or at the end of your routine. (vl-load-com) Quote
Avcit Posted June 25, 2016 Author Posted June 25, 2016 (vl-load-com) Thank you for your interest. It works except length. It gives the length of closed polyline 0.0000 . I need a length code for closed polyline Quote
Tharwat Posted June 25, 2016 Posted June 25, 2016 Thanks. You are a great coder You are most welcome. It is nice of you to say that 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.