dilan Posted April 19, 2019 Posted April 19, 2019 Hello. Trying to make a function that will return a list of coordinates of all selected cogo points. But I can not understand how to add to the list the coordinates of all points. The coordinate of only one point is added. Please help me understand. Thank. (defun cogo_list_coor ( / descr eastng idx northng pnt pntobj ss elev numb ) (vl-load-com) (if (setq ss (ssget '((0 . "AECC_COGO_POINT")))) (progn (setq idx -1) (while (setq pnt (ssname ss (setq idx (1+ idx)))) (setq pntobj (vlax-ename->vla-object pnt)) (setq descr (vlax-get pntobj 'fulldescription) numb (vlax-get pntobj 'Number) eastng (vlax-get pntobj 'easting) northng (vlax-get pntobj 'northing) elev (vlax-get pntobj 'Elevation) ) (list numb eastng northng elev) ); end of while ); end of progn ); end of if ); end of cogo_list_coor Quote
BIGAL Posted April 19, 2019 Posted April 19, 2019 Try this Command: (setq ss (ssget "X" '((0 . "AECC_COGO_POINT")))) <Selection set: 14> Command: (sslength ss) 686 Quote
dlanorh Posted April 19, 2019 Posted April 19, 2019 (edited) Is this what you are after? It returns a list of lists. You are also extracting the description but not using it. (defun cogo_list_coor ( / descr eastng idx northng pnt pntobj ss elev numb p_lst) (vl-load-com) (cond ( (setq ss (ssget '((0 . "AECC_COGO_POINT")))) (setq p_lst nil) (repeat (setq idx (sslength ss)) (setq pntobj (vlax-ename-vla-obj (ssname ss (setq idx (1- idx)))) descr (vlax-get pntobj 'fulldescription);;;;!!Why? Never Used numb (vlax-get pntobj 'Number) eastng (vlax-get pntobj 'easting) northng (vlax-get pntobj 'northing) elev (vlax-get pntobj 'Elevation) p_lst (cons (list numb eastng northng elev) p_lst) );end_setq );end_repeat ) );end_cond p_lst ); end of cogo_list_coor Edited April 19, 2019 by dlanorh 1 Quote
dilan Posted April 19, 2019 Author Posted April 19, 2019 (setq p_lst (cons (list numb eastng northng elev) p_lst)) Yes, I needed this line. thank dlanorh Quote
Lee Mac Posted April 27, 2019 Posted April 27, 2019 FWIW, rather than defining separate variables for each retrieved property, you can use a single mapcar expression to return the desired sublist: (defun cogo_list_coor ( / i l o s ) (if (setq s (ssget '((0 . "AECC_COGO_POINT")))) (repeat (setq i (sslength s)) (setq i (1- i) o (vlax-ename->vla-object (ssname s i)) l (cons (mapcar '(lambda ( p ) (vlax-get o p)) '(number easting northing elevation)) l) ) ) ) l ) 1 Quote
dilan Posted April 27, 2019 Author Posted April 27, 2019 4 hours ago, Lee Mac said: FWIW, rather than defining separate variables for each retrieved property, you can use a single mapcar expression to return the desired sublist: (defun cogo_list_coor ( / i l o s ) (if (setq s (ssget '((0 . "AECC_COGO_POINT")))) (repeat (setq i (sslength s)) (setq i (1- i) o (vlax-ename->vla-object (ssname s i)) l (cons (mapcar '(lambda ( p ) (vlax-get o p)) '(number easting northing elevation)) l) ) ) ) l ) thank Lee Quote
BIGAL Posted April 29, 2019 Posted April 29, 2019 Great idea as usual Lee often getting multiple details from an object using VL-get, can see it as a library defun passing list of item names, so not hard coded. 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.