TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: vincent.r on September 17, 2019, 01:32:52 AM

Title: Invalid Entity. What is that ?
Post by: vincent.r on September 17, 2019, 01:32:52 AM
I received a message from watch window of VL console. Do anybody gone through this error ? What is that ? Screenshot attached.
Title: Re: Invalid Entity. What is that ?
Post by: roy_043 on September 17, 2019, 04:21:08 AM
You should indent your code better. And there is no reason to quote integers.

Code: [Select]
(setq LST (entget ent))Is perhaps the problem. Initially ent is nil.
Title: Re: Invalid Entity. What is that ?
Post by: VovKa on September 17, 2019, 05:08:37 AM
What is that ?
there's something in your block that 'Inspect window' doesn't like
i don't think it could be fixed
Title: Re: Invalid Entity. What is that ?
Post by: Marc'Antonio Alessi on September 17, 2019, 08:30:12 AM
setq closest nil before run
Title: Re: Invalid Entity. What is that ?
Post by: jtoverka on September 17, 2019, 09:02:07 AM
setq closest nil before run

To build on this answer I would wrap the entire function in a lambda statement like so:

Code: [Select]
((lambda ( / ) ; insert local variables here

; insert all of your code here

)) ; close lambda function

The reason I use lambda is I don't need to make a function, however I need to localize my variables. I see that your code evaluates the variable closest in an if statement. When closest is not localized it will run "correctly" the first time, however if it is not set to nil the next time, it will run incorrectly. If you use lambda and put all the variables you use past the "/" the variables will be nil at the start of the program.
Title: Re: Invalid Entity. What is that ?
Post by: roy_043 on September 17, 2019, 09:24:12 AM
The reason I use lambda is I don't need to make a function, however I need to localize my variables.
A lambda is also a function.
Title: Re: Invalid Entity. What is that ?
Post by: jtoverka on September 17, 2019, 09:57:01 AM
The reason I use lambda is I don't need to make a function, however I need to localize my variables.
A lambda is also a function.

In this context it is single use, notice how I didn't save it to a variable. Additionally, it is created then it is called once and never used again.
The defun creates a callable function and saves it to a variable. That is what I meant with "make a function."
Title: Re: Invalid Entity. What is that ?
Post by: Marc'Antonio Alessi on September 17, 2019, 11:19:40 AM
The reason I use lambda is I don't need to make a function, however I need to localize my variables.
A lambda is also a function.

In this context it is single use, notice how I didn't save it to a variable. Additionally, it is created then it is called once and never used again.
The defun creates a callable function and saves it to a variable. That is what I meant with "make a function."
)) ; close lambda function    :)
Title: Re: Invalid Entity. What is that ?
Post by: vincent.r on September 18, 2019, 05:53:14 AM
Thanks guys for your efforts. I tried in many ways but result was same. Then created block newly and it works fine. I believe problem was with block. Don't know why.
Thanks a lot guys for your kind help.