BlackBox Posted September 9, 2010 Posted September 9, 2010 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. ... You're welcome. However, let there be no mistake... I am NO expert (yet). ... But what about your last example . it's really odd and advanced in all words. ... That is exactly what I was going for... odd, and advanced! :lol: Quote
Se7en Posted September 9, 2010 Posted September 9, 2010 Reference code snip: (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: "))) Nice logic example (intension is to get the second point if the first point is picked). Here are several other ways you can replicate that intension. (and (setq sp (getpoint "\nPick first point")) (setq ep (getpoint "\nPick second point"))) not exact, because of the use of a boolean in place of a conditional. (cond ((setq sp (getpoint "\nPick first point")) (setq ep (getpoint "\nPick second point")))) However, if you wanted to add to the critera "hygenic variable creation", you can use a method like: (if (setq sp (cond ((getpoint "\nPick first point")))) (setq ep (cond ((getpoint "\nPick second point")))) ) and so on... Quote
Tharwat Posted September 11, 2010 Author Posted September 11, 2010 Thank you Se7en for your several examples. Your last example is really unique . Very nice, Appreciated. Tharwat Quote
Tharwat Posted September 12, 2010 Author Posted September 12, 2010 For single selection, you should give this a read...http://www.cadtutor.net/forum/showthread.php?48058-error-in-using-quot-entsel-quot Hello. Is the following codes are better than my previous one in use of single selection set which would not return nil ? (vl-load-com) (if (and (setq ss (entsel "\n Select Line :")) (setq ss (car ss)) (setq Nme (eq (cdr (assoc 0 (entget ss)))"LINE")) ) (progn (setq obj (vlax-ename->vla-object ss)) (setq len (vla-get-length obj)) ) ) Thanks Tharwat Quote
BlackBox Posted September 13, 2010 Posted September 13, 2010 If you want a vla-object without using the (if (ssget) (vlax-for)) combo, you might try this: (vl-load-com) [color=black](if (and (setq eName (car (entsel "\n Select Line :")))[/color] [color=black] (= "AcDbLine"[/color] [color=black] (vla-get-objectname[/color] [color=black] (setq lineObj[/color] [color=black] (vlax-ename->vla-object eName)))))[/color] [color=black](setq len (vla-get-length lineObj))[/color] [color=black](prompt "\n <!> Object Selected is Not a Line <!> "))[/color] Quote
Tharwat Posted September 13, 2010 Author Posted September 13, 2010 YES. Renderman. Really very nice example, I like it with the "AcDbLine" . And my previous example was indicated to Alanjt because of the use of (car (entsel ..... together and he asked me to read the link that he uploaded to me some posts back. So I realized or thought that he may mean not to use car with entsel at the same time. For example, get the entsel first and get the selection later with car as I did in my example ...Maybe. Hope that he may reply. Thanks a lot for your reply. Tharwat Quote
alanjt Posted September 13, 2010 Posted September 13, 2010 (defun foo (/ e l) (setvar 'errno 0) (while (and (not l) (/= (getvar 'errno) 52)) (if (setq e (car (entsel "\nSelect line: "))) (if (eq "AcDbLine" (vla-get-objectname (setq e (vlax-ename->vla-object e)))) (setq l (vla-get-length e)) (setq l (prompt "\nInvalid object!")) ) ) ) ) Quote
BlackBox Posted September 13, 2010 Posted September 13, 2010 If I were to speculate at Alanjt's meaning... It is perfectly acceptable to combine functions into one line of code to be succinct. One should simply try to avoid errors where possible. Examples: (car nil) = nil (vla-get-layer nil) = *error* Quote
alanjt Posted September 13, 2010 Posted September 13, 2010 RenderMan is correct. There's nothing wrong with combining functions, as long as they will not error if fed 'nil'. (car (entsel)) OK (vlax-ename->vla-object (car (entsel))) NOT OK (entget (car (entsel))) NOT OK Tharwat, I was referring you to the link because there were a lot of really good single selection methods posted. Quote
Tharwat Posted September 13, 2010 Author Posted September 13, 2010 Thanks Alanjt. I did understand your point at the beginning but after reading lots of examples, I could not concentrate well at mine and I thought that I should give it a try in another way, so that's why I changed it in post 24 with separation of ( car ) as you can see it in there So according to your last information I can say that both are correct regarding to (car(entsel...)) and except the condition status with *if* must be more accurate or used to check for availability. Thank you so much for your efforts and your time. Tharwat Quote
Lee Mac Posted September 13, 2010 Posted September 13, 2010 Just to add some variation to the mix (defun c:test ( / foo o ) (vl-load-com) (defun foo ( utils / e p ) (vla-getEntity utils 'e 'p) (if (and e (eq "AcDbLine" (vlax-get e 'ObjectName))) e (foo utils)) ) (if (setq o (foo (vla-get-Utility (vla-get-ActiveDocument (vlax-get-acad-object))))) (vla-get-length o) ) ) Quote
alanjt Posted September 13, 2010 Posted September 13, 2010 Just to add some variation to the mix (defun c:test ( / foo o ) (vl-load-com) (defun foo ( utils / e p ) (vla-getEntity utils 'e 'p) (if (and e (eq "AcDbLine" (vlax-get e 'ObjectName))) e (foo utils)) ) (if (setq o (foo (vla-get-Utility (vla-get-ActiveDocument (vlax-get-acad-object))))) (vla-get-length o) ) ) I hope you don't miss. :wink: Quote
Lee Mac Posted September 13, 2010 Posted September 13, 2010 I hope you don't miss. :wink: Why not? Quote
alanjt Posted September 13, 2010 Posted September 13, 2010 Why not? Command: TEST Select object: Command: Error: Automation Error. Description was not provided. Command: Quote
Lee Mac Posted September 13, 2010 Posted September 13, 2010 Command: TEST Select object: Command: Error: Automation Error. Description was not provided. Command: I swear that didn't do that when I tested it - how embarassing Quote
Lee Mac Posted September 13, 2010 Posted September 13, 2010 An attempt to retain my dignity: (defun c:test ( / foo o ) (vl-load-com) (defun foo ( utils / e p ) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getEntity (list utils 'e 'p)) ) ) (if (eq "AcDbLine" (vlax-get e 'ObjectName)) e (foo utils)) ) ) (if (setq o (foo (vla-get-Utility (vla-get-ActiveDocument (vlax-get-acad-object))))) (vla-get-length o) ) ) Quote
alanjt Posted September 13, 2010 Posted September 13, 2010 I swear that didn't do that when I tested it - how embarassingA minor fix. I won't tell. Quote
Lee Mac Posted September 13, 2010 Posted September 13, 2010 A minor fix. I won't tell. lol thanks mate Quote
alanjt Posted September 13, 2010 Posted September 13, 2010 An attempt to retain my dignity: LoL 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.