Jump to content

Recommended Posts

Posted
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). 8)

 

 

...

But what about your last example . :shock: it's really odd and advanced in all words. :lol:

...

 

 

That is exactly what I was going for... odd, and advanced! :P:lol:

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    13

  • alanjt

    10

  • Lee Mac

    10

  • BlackBox

    5

Top Posters In This Topic

Posted

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...

Posted

Thank you Se7en for your several examples.

 

Your last example is really unique .

 

Very nice, Appreciated.

 

Tharwat

Posted

 

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

Posted

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]

Posted

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

Posted
(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!"))
     )
   )
 )
)

Posted

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*

Posted

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.

Posted

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

Posted

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)
 )
)

Posted
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:

Posted
Why not? :?

 

Command: TEST
Select object:
Command:
Error: Automation Error. Description was not provided.
Command:

Posted
Command: TEST
Select object:
Command:
Error: Automation Error. Description was not provided.
Command:

 

:oops: I swear that didn't do that when I tested it - how embarassing

Posted

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)
 )
)

Posted
:oops: I swear that didn't do that when I tested it - how embarassing
A minor fix. I won't tell.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...