Tharwat Posted September 7, 2010 Posted September 7, 2010 Hello, I wonder how to replace the (entsel function) with (ssget function) !!! (vl-load-com) (setq LINE (car (entsel "\n Select a Line: "))) (setq Myline (vlax-ename->vla-object LINE)) (vla-get-length Myline) Many Thanks. Tharwat Quote
Lee Mac Posted September 7, 2010 Posted September 7, 2010 For a single selection, something like this perhaps? (ssget "_+.:E:S" '((0 . "LINE"))) For multiple, you would need to step through the set: (if (setq i -1 ss (ssget '((0 . "LINE")))) (while (setq e (ssname ss (setq i (1+ i)))) (print (vla-get-length (vlax-ename->vla-object e))) ) ) Or perhaps use vlax-for to step through the ActiveSelectionSet in VL (or indeed, you can acquire the SelectionSet in VL). Quote
Tharwat Posted September 7, 2010 Author Posted September 7, 2010 Thank you Lee. I surprised when you've mentioned "perhaps" . But when you added the rest I took a deep breath. So codes are running perfectly for now. (vl-load-com) (if (setq i -1 ss (ssget '((0 . "LINE")))) (while (setq e (ssname ss (setq i (1+ i)))) (setq obj (vlax-ename->vla-object e)) (setq len (vla-get-length obj)) )) Why the following functions are not responding correctly with codes ? (setq start (vla-get-startpoint obj)) (setq end (vla-get-endpoint obj)) Many Thanks. Quote
Lee Mac Posted September 7, 2010 Posted September 7, 2010 Bear in mind that the vla-get-startpoint/endpoint return variants, which would need to be converted to safearrays, then lists if you plan to use them as Vanilla data types, example: (vlax-safearray->list (vlax-variant-value (vla-get-StartPoint <VLA-Object>) ) ) Alternatively, to avoid this conversion: (vlax-get <VLA-Object> 'StartPoint) Quote
Lee Mac Posted September 7, 2010 Posted September 7, 2010 For the benefit of others perhaps, this is how you might obtain the same selection set in VL entirely: [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] [color=black]c:test[/color] [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] _SafearrayVariant _GetUniqueKey SelSet SelSets [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac 2010[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] _SafearrayVariant [b][color=RED]([/color][/b] datatype data [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-make-variant[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-safearray-fill[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-make-safearray[/color][/b] datatype [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]1-[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]length[/color][/b] data[b][color=RED]))))[/color][/b] data [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] _GetUniqueKey [b][color=RED]([/color][/b] collection seed [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] i [b][color=BLUE]/[/color][/b] key [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]not[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-error-p[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-catch-all-apply[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vla-item[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] collection [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] key [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] seed [b][color=RED]([/color][/b][b][color=BLUE]itoa[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] key [b][color=RED])[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-SelectonScreen[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] SelSet [b][color=RED]([/color][/b][b][color=BLUE]vla-Add[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] SelSets [b][color=RED]([/color][/b][b][color=BLUE]vla-get-SelectionSets[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-ActiveDocument[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-get-acad-object[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b]_GetUniqueKey SelSets [b][color=#a52a2a]"SelSet"[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b]_SafearrayVariant [b][color=BLUE]vlax-vbinteger[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b][b][color=RED]))[/color][/b] [b][color=RED]([/color][/b]_SafearrayVariant [b][color=BLUE]vlax-vbvariant[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#a52a2a]"LINE"[/color][/b][b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]<[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-Count[/color][/b] SelSet[b][color=RED]))[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vlax-for[/color][/b] o SelSet [b][color=RED]([/color][/b][b][color=BLUE]print[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-get-length[/color][/b] o[b][color=RED]))[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vla-delete[/color][/b] SelSet[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] Quote
alanjt Posted September 8, 2010 Posted September 8, 2010 Combo of AutoLISP and VisualLISP, cycling through vla-get-activeselectionset... (defun c:Test (/ ss) (if (setq ss (ssget '((0 . "LINE")))) (progn (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)) ) ) (print (vla-get-length x)) ) (vla-delete ss) ) ) (princ) ) or all AutoLISP... (defun c:Test (/ i ss e l) (if (setq i -1 ss (ssget '((0 . "LINE"))) ) (while (setq e (ssname ss (setq i (1+ i)))) (print (distance (cdr (assoc 10 (setq l (entget e)))) (cdr (assoc 11 l)))) ) ) (princ) ) Quote
Tharwat Posted September 8, 2010 Author Posted September 8, 2010 Thanks Alanjt. Would you please tell me what is the difference between the two following codes ? .... .. First . (vl-load-com) (setq i -1 ss (ssget '((0 . "LINE")))) (progn (setq e (ssname ss (setq i (1+ i)))) (setq obj (vlax-ename->vla-object e)) (print (vla-get-length obj)) )) Second . (vl-load-com) (setq ss (ssget '((0 . "LINE")))) (progn (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)) ) ) (print (vla-get-length x)) ) (vla-delete ss) ) Many Thanks Quote
Tharwat Posted September 8, 2010 Author Posted September 8, 2010 Bear in mind that the vla-get-startpoint/endpoint return variants, which would need to be converted to safearrays, then lists if you plan to use them as Vanilla data types, example: Thanks a lot ... . Suppose that I would like to get start and end points, should I repeat the conversion two times to get the two points ? Examples. (vl-load-com) (if (setq i -1 ss (ssget '((0 . "LINE")))) (progn (setq e (ssname ss (setq i (1+ i)))) (setq obj (vlax-ename->vla-object e)) [color="red"](vlax-safearray->list (vlax-variant-value (setq start (vla-get-StartPoint obj)) ) )[/color] [color="blue"](vlax-safearray->list (vlax-variant-value (setq end (vla-get-endPoint obj)) ) )[/color] )) Regards. Quote
Lee Mac Posted September 8, 2010 Posted September 8, 2010 If you want to proceed that way, set the variables after the conversion, hence: (setq start (vlax-safearray->list (vlax-variant-value (vla-get-StartPoint obj) ) ) ) Else you could use this equally: (setq Start (vlax-get obj 'StartPoint)) Lee Quote
Tharwat Posted September 8, 2010 Author Posted September 8, 2010 You're amazing Lee. Thank you so much. That was really fascinating. Tharwat Quote
alanjt Posted September 8, 2010 Posted September 8, 2010 (vl-load-com) (if (setq i -1 ss (ssget '((0 . "LINE"))) ) (while (setq e (ssname ss (setq i (1+ i)))) (setq start (vlax-curve-getStartPoint e) end (vlax-curve-getEndPoint e) ) ) ) Quote
Lee Mac Posted September 8, 2010 Posted September 8, 2010 You're amazing Lee. Thank you so much. That was really fascinating. Tharwat Glad Tharwat, glad you liked it Quote
Tharwat Posted September 8, 2010 Author Posted September 8, 2010 (vl-load-com) (if (setq i -1 ss (ssget '((0 . "LINE"))) ) (while (setq e (ssname ss (setq i (1+ i)))) (setq start (vlax-curve-getStartPoint e) end (vlax-curve-getEndPoint e) ) ) ) All right, Another way to get the two points. Thank you Alanjt. Tharwat Quote
alanjt Posted September 8, 2010 Posted September 8, 2010 All right, Another way to get the two points. Thank you Alanjt. Tharwat What I've given isn't perfect, since it will only store one Start and End point, from your selection set of line(s), but it was just a quick example. You could also just take the DXF 10 and 11 code from an (entget e) Quote
Tharwat Posted September 8, 2010 Author Posted September 8, 2010 Yes, That's right. The DXF 10 & 11 are known to me to deal with. I just wanted to step forward into the VL codes as long as I have a good base of coding . Thanks for your interests. Tharwat Quote
BlackBox Posted September 8, 2010 Posted September 8, 2010 ... I just wanted to step forward into the VL codes... Excellent motivation, Tharwat! Quote
BlackBox Posted September 8, 2010 Posted September 8, 2010 All right, Another way to get the two points. ... For the sake of levity... here's another way to get two points (Ha, ha! ): (if (setq startPoint (getpoint "\n >> Pick the Start Point of a Line: ")) (setq endPoint (getpoint "\n >> Now... Pick the End Point of the Same Line: "))) Note - Error checking (on the user) not included. Quote
Tharwat Posted September 8, 2010 Author Posted September 8, 2010 Excellent motivation, Tharwat! Thank you Renderman. And thanks for your encouragement, I have been learning a lot from you dear Renderman, as well as from the other experts in this GREAT FORUM. But what about your last example . it's really odd and advanced in all words. Thank you once again. Tharwat Quote
Tharwat Posted September 9, 2010 Author Posted September 9, 2010 Here is one more routine does the same with single selection set I made it just for information .... if anyone interesting . (vl-load-com) (if (and (setq ss (car (entsel "\n Select Line :"))) (setq Nme (eq (cdr (assoc 0 (entget ss )))"LINE")) ) (progn (setq obj (vlax-ename->vla-object ss)) (setq len (vla-get-length obj)) ) (alert "Nothing's Selected or Not a LINE") ) Great Thanks for All participators in this thread. Tharwat Quote
alanjt Posted September 9, 2010 Posted September 9, 2010 For single selection, you should give this a read... http://www.cadtutor.net/forum/showthread.php?48058-error-in-using-quot-entsel-quot 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.