Sharper Posted March 21 Posted March 21 Hi Guys I've made this lisp routine for getting the area of a shape using ssget... Sometimes it works fine and sometimes it fails with the following error Autolisp Error: ActiveX Server returned the error: unknown name: Area Could someone please take a look and let me know where i've gone wrong? many thanks ;Checks area. min size of 30000mm2 set. (defun c:ChkMinArea (/ ss1 Limit a b c) (setq Limit 30000) (setq ss1 (ssget "x" '((0 . "LWPOLYLINE")(8 . "FinalTrim" )))) (setq a (entlast)) (setq b (vla-get-area (vlax-ename->vla-object a))) (setq c ( - Limit b)) (if (>= b Limit) (princ "\nArea is Okay... proceeding....") (Alert (strcat "Plate needs extending by\n" (rtos c) "mm2 Area")) ) (Princ) );end defun Test Upload.dwg Quote
devitg Posted March 21 Posted March 21 (edited) 19 minutes ago, Sharper said: Hi Guys I've made this lisp routine for getting the area of a shape using ssget... Sometimes it works fine and sometimes it fails with the following error Autolisp Error: ActiveX Server returned the error: unknown name: Area Could someone please take a look and let me know where i've gone wrong? many thanks ;Checks area. min size of 30000mm2 set. (defun c:ChkMinArea (/ ss1 Limit a b c) (setq Limit 30000) (setq ss1 (ssget "x" '((0 . "LWPOLYLINE")(8 . "FinalTrim" )))) (setq a (entlast)) (setq b (vla-get-area (vlax-ename->vla-object a))) (setq c ( - Limit b)) (if (>= b Limit) (princ "\nArea is Okay... proceeding....") (Alert (strcat "Plate needs extending by\n" (rtos c) "mm2 Area")) ) (Princ) );end defun Test Upload.dwg 40.52 kB · 0 downloads .. Edited March 21 by devitg my error Quote
EnM4st3r Posted March 21 Posted March 21 you set ss1 using ssget but you are proccessing "a" by entlast. This is why it sometimes works and sometimes not, since the last entity is diffrent and errors out for wrong types 1 Quote
devitg Posted March 21 Posted March 21 The Entlast , is the last entity made at the DWG, and NOT the last ent at the selection set Quote
Sharper Posted March 21 Author Posted March 21 Ahh this makes sense Staring me right in the face for the last 3 days... Thank you guys, really appreciate the help Quote
devitg Posted March 21 Posted March 21 (setq ss1 (ssget "x" '((0 . "POLYLINE")(8 . "FinalTrim" )))) (setq ent (ssname ss1 0)) (setq a ent) Test it , as it is a only one "POLYLINE" 1 Quote
EnM4st3r Posted March 21 Posted March 21 i would go like this (defun c:ChkMinArea (/ ss1 Limit i a b c) (setq Limit 30000) (setq ss1 (ssget "_X" '((0 . "POLYLINE")(8 . "FinalTrim")))) (setq i 0) (while (< i (sslength ss1)) (setq a (ssname ss1 i)) (setq b (vla-get-area (vlax-ename->vla-object a))) (setq c ( - Limit b)) (if (>= b Limit) (princ "\nArea is Okay... proceeding....") (progn (command "_zoom" "_obj" a "") (Alert (strcat "Plate needs extending by\n" (rtos c) "mm2 Area")) ) ) (setq i (1+ i)) ) (Princ) );end defun 1 Quote
Sharper Posted March 21 Author Posted March 21 Hey EnM4st3r I originally started off using sslength count, but removed it once i realised it would only ever be one closed rectangular shape on each file. I suppose it wouldn't have hurt if i left it in there Quote
Sharper Posted March 21 Author Posted March 21 My routine is now updated and working perfectly. Thank you once again for the assistance 1 Quote
BIGAL Posted March 21 Posted March 21 If only one entity at a time, you can add a Has-Property 'Area check. (while (setq obj (vlax-ename->vla-object (car (entsel "Pick obj for area ")))) (setq a (vlax-get obj 'Area)) (setq lay (vlax-get obj 'layer)) (alert (strcat "The Area is " (rtos a 2 2) " on layer " lay)) ) 1 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.