Author Topic: Help with While loop  (Read 2807 times)

0 Members and 1 Guest are viewing this topic.

jmcshane

  • Newt
  • Posts: 83
Help with While loop
« on: September 02, 2009, 07:12:04 AM »
Hi,

This may sound fairly simple and I'm sure it is, but for some reason I can't seem to figure it out.
Can someone who has some time tell me why I get an error when trying to quit the loop below?

Code: [Select]
(while
     (setq obj (vlax-ename->vla-object (car (entsel))))
     (if (= (vla-get-ObjectName obj) "AcDbBlockReference")
       (vla-put-rotation
obj
(dtr (+ (rtd (vla-get-rotation obj)) 180))
       )
       (princ
"\nSelected Object was not a block!.......Please try again: "
       )
     )
  )

Whenever I hit enter it returns :
Code: [Select]
error: bad argument type: lentityp nil

Any guidance would be gratefully accepted.

John
John.

Civil 3D 2021. Windows 10

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Help with While loop
« Reply #1 on: September 02, 2009, 07:14:32 AM »
vlax-ename->vla-object will error when provided with nil, hence test for a nil entity selection (car (entsel)) before converting it to a vla-object :-)

jmcshane

  • Newt
  • Posts: 83
Re: Help with While loop
« Reply #2 on: September 02, 2009, 07:32:34 AM »
Thank you,
I had better go and look at all the rest of my routines that throw this error.

Many thanks


John
John.

Civil 3D 2021. Windows 10

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Help with While loop
« Reply #3 on: September 02, 2009, 09:55:42 AM »
You could also take out the conversion from radians to degrees with something like this:

(+ pi (vla-get-rotation obj))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jmcshane

  • Newt
  • Posts: 83
Re: Help with While loop
« Reply #4 on: September 02, 2009, 01:07:47 PM »
Mathamatics was never my strongest point, so I never knew that!
So that makes it two useful pieces of information I learned today.

Thanks.
John
John.

Civil 3D 2021. Windows 10

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Help with While loop
« Reply #5 on: September 02, 2009, 01:25:45 PM »

jmcshane

  • Newt
  • Posts: 83
Re: Help with While loop
« Reply #6 on: September 02, 2009, 02:03:55 PM »
Ha Ha  :-o

You guys even throw in a bit of personal development as well as the programming advice. :-D
Back in the day....(way back now that I think of it) I used to work all this out with a pencil and a compass!
No need for maths :wink: (untill today!)

Thanks for the help.

John


John.

Civil 3D 2021. Windows 10

Spike Wilbury

  • Guest
Re: Help with While loop
« Reply #7 on: September 02, 2009, 02:18:35 PM »
Gotta love mathematics  :wink:

This will be an interesting read for you :-)

I loved my math and geometry classes a lot - got the opportunity to have these classes also in my university years (5 years) :)

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Help with While loop
« Reply #8 on: September 02, 2009, 03:52:12 PM »
Gotta love mathematics  :wink:

This will be an interesting read for you :-)

I loved my math and geometry classes a lot - got the opportunity to have these classes also in my university years (5 years) :)

Just curious, what degree did you study Luis?

curmudgeon

  • Newt
  • Posts: 194
Re: Help with While loop
« Reply #9 on: September 02, 2009, 04:04:08 PM »
Gotta love mathematics  :wink:

This will be an interesting read for you :-)

I am sometimes surprised with the usefulness of wikipedia. I had been interested in calculating a centroid from scratch with lisp, and to do that I used their algorithm to get the area in the process.

the unintended consequence you may appreciate, and I will share. if that method is employed for area, you can end up with a negative area. as I recall, a negative area implied the vertexes of the polygon had a clockwise rotation, a positive area counter clockwise.
Never express yourself more clearly than you are able to think.

Spike Wilbury

  • Guest
Re: Help with While loop
« Reply #10 on: September 02, 2009, 06:46:07 PM »
architecture

Gotta love mathematics  :wink:

This will be an interesting read for you :-)

I loved my math and geometry classes a lot - got the opportunity to have these classes also in my university years (5 years) :)

Just curious, what degree did you study Luis?

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Help with While loop
« Reply #11 on: September 03, 2009, 05:27:36 AM »
I see, cool  8-)

architecture

Gotta love mathematics  :wink:

This will be an interesting read for you :-)

I loved my math and geometry classes a lot - got the opportunity to have these classes also in my university years (5 years) :)

Just curious, what degree did you study Luis?