Can't exit "-layer" command call in LISP

Can't exit "-layer" command call in LISP

Gorra
Advocate Advocate
1,504 Views
18 Replies
Message 1 of 19

Can't exit "-layer" command call in LISP

Gorra
Advocate
Advocate

Hello,

I am trying thaw and freeze a layer as the first and last actions in a lisp, respectively. However, while it does thaw the target layer, the first -layer command won't exit.

 

(command "-layer" "T" "LTS_VIEWPORT" "")

 

I've tried command-s and putting a space between the 'null' quotes, I've also tried using two nulls, and tried an "EXIT" followed by a null . All I'm getting is the '-layer' prompt or "unable to get ObjectID: nil"

 

Any help would be appreciated

 

Thanks,

Gorra

0 Likes
Accepted solutions (2)
1,505 Views
18 Replies
Replies (18)
Message 2 of 19

pendean
Community Legend
Community Legend

@Gorra wrote:

(command "-layer" "T" "LTS_VIEWPORT" "")

 


You have to finish the command's steps, instead of just stopping mid-task: try it out, type that sequence at the commandline and see how many more steps you need to do to close out of -LAYER command. Like this:

 

-layer <enter>

T <enter>

LTS_VIEWPORT <enter>

....... ?

0 Likes
Message 3 of 19

Gorra
Advocate
Advocate

Hi @pendean 

I have done it from the command line, and needs an extra "enter" keystroke. It doesn't work in the code.

 

In the code, it takes the command, accepts the "T" as thaw, accepts the layername (and thaws it), then gives me an error on "".

If I put "" after the "T" it errors out and doesn't take the layername.

If I put a second "" at the end, it errors out and then tries to run the script again.

 

 

0 Likes
Message 4 of 19

Gorra
Advocate
Advocate

If I use command-s the second "" it gives "error: unable to get ObjectID: nil" at the second "".

0 Likes
Message 5 of 19

Sea-Haven
Mentor
Mentor

Removed misinterpreted.

0 Likes
Message 6 of 19

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

You need "" "". ....


NOT TRUE.  Did you try it?  One Enter "" there does "finish the command's steps" [when working normally -- it does for me] -- the second one only recalls the previous command.

 

@Gorra, what you have in Message 1 should work [and as I said, it does for me].  Even if the Layer doesn't exist, it would simply report that it didn't find any matching Layers, without error.  I think you have something else wrong, but the only thing I can think of [short of re-installing] is that you may have an UNDEFINEd and then differently-defined special-purpose Layer command.  To test that, put the period prefix before the command name to force use of the native command:

(command ".layer" "T" "LTS_VIEWPORT" "")

Does it work then?

[You don't need the hyphen within an AutoLisp (command) function to get the command-line version instead of the dialog box.]

Kent Cooper, AIA
Message 7 of 19

Sea-Haven
Mentor
Mentor

Kent you are correct misinterpreted the manual test. 

0 Likes
Message 8 of 19

Gorra
Advocate
Advocate

@Kent1Cooper 

Thanks, I didn't know about the "." prefix. There's no change in the result though, still get "error: unable to get ObjectID: nil". 

 

The only code that comes before it is some system variables

 

(defun c:LOUT ( / Lyt LytSS LytCnt LytLst Grdsht MVw VPCnt SL SrtdLst VSL AVal Blck BlckLst Vtag LytArry OvrRf)
    (vl-load-com)
    (command _attdia 0)
    (setq SnapHold (getvar 'osmode)) ; get current snap settings
    (setvar 'osmode 0) ; turn off snaps
    (setvar 'luprec 3)
    (setvar 'pickfirst 1)

 

 Could it be a system variable that's set wrong?

 

The full code is attached as well.

0 Likes
Message 9 of 19

ec-cad
Collaborator
Collaborator

Interesting: Try the code here, just change the layer names for testing.

You may also want to try the (command ".Layer" ... as Kent suggested.

I could also be a system variable that got set to a value that inteferes ?

Modemacro, or Expert ?

 

Bob

; Test Layer Commands

 (defun C:GO ()

; First, use (command "-layer" "T" "BN1" "")
(command "-layer" "T" "BN1" ""); returns nil

; Next, use (command "_layer" "T" "BN1" "")
(command "_layer" "T" "BN1" ""); returns nil

; Next try it on a non-existant Layername
(command "-layer" "T" "XXX" ""); returns nil
(command "_layer" "T" "XXX" ""); returns nil

; Try a couple of layers at the same time
(command "-layer" "T" "BN1" "T" "BN2" ""); returns nil
(command "_layer" "T" "BN1" "T" "BN2" ""); returns nil

; Try using just (command), to interrupt whatever process is running that may be intefering
(command)
(command "-layer" "T" "BN1" ""); returns nil
(command)
(command "_layer" "T" "BN1" "T" "BN2" ""); returns nil

; All above work without hanging
(princ "\nSUCCESS")
(princ)
; and call the function
); function
(C:GO)

;; Only thing I see is:
; 'SUCCESS
0 Likes
Message 10 of 19

Kent1Cooper
Consultant
Consultant
Accepted solution

If it's in a larger context, what makes you think the error is coming from that Layer-thawing line?  Does that line in isolation work?  The message can hardly be coming from anything happening within that, but with all that goes on after it in the larger context, it could well be from something following [I haven't studied].

Kent Cooper, AIA
0 Likes
Message 11 of 19

komondormrex
Mentor
Mentor
Accepted solution

hey,

without command -layer

to thaw the layer "LTS_VIEWPORT"

(vlax-put (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "LTS_VIEWPORT") 'freeze 1)

to freeze the layer "LTS_VIEWPORT"

(vlax-put (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "LTS_VIEWPORT") 'freeze 0)

 

Message 12 of 19

Gorra
Advocate
Advocate

@ec-cad  So all that runs with no error (other than the XXX not found), and prints "success" to the command line, in the same drawing as I've been using.

Which just leaves me more baffled. At least it's not a corrupt AutoCAD or drawing.

0 Likes
Message 13 of 19

ec-cad
Collaborator
Collaborator

In your original (top of this posting), you say:

"All I'm getting is the '-layer' prompt or "unable to get ObjectID: nil"

The 'ObjectID: nil' implies that somewhere else in your code the error occurs,

Looks like a vla-xx call that is sending an error. That might be the issue.

Try commenting out sections of the code, until the -layer command(s) behave.

Once you identify that section of code that causes the 'ObjectID: nil' error,

you can try and isolate what's up with that part of the code.

Good luck - I don't have a drawing to test it on.

 

ECCAD

 

0 Likes
Message 14 of 19

Gorra
Advocate
Advocate

@Kent1Cooper 

Aha. I just put in a bunch of alerts and I have found that the "(command "-layer" etc)" gives the error and stays in the command. Using "(command-s "-layer" etc)" on that line *looked* like it was still in the command but had in fact  finished the command and moved on to the next line. So I'll go with the -s and proceed from there.

 

 

0 Likes
Message 15 of 19

Gorra
Advocate
Advocate

@komondormrex 

Thanks, I was hoping there was an alternate means of getting the job done

 

Gorra

0 Likes
Message 16 of 19

Kent1Cooper
Consultant
Consultant

@komondormrex wrote:

..., without command -layer ....


Here's another way to do it without a Layer command, if the problem is really coming from that line.

 

To Thaw a Layer:

(setq ldata (entget (tblobjname "layer" "TheLayerName")))
(entmod (subst (cons 70 (boole 2 (cdr (assoc 70 ldata)) 1)) (assoc 70 ldata) ldata))

That ensures the 1 bit is not included in the DXF 70 entry in the Layer's entity data, which thaws the Layer if it's frozen, or leaves it thawed if it already is.  It leaves alone any other bits that are part in the value in that entry.

To Freeze it, replace that 2 in line 2 with a 7, which will ensure the 1 bit is included, freezing the Layer if it's thawed, or leaving it frozen if it already is.

 

For a given Layer, of course you can use line 1 there just once, and then use line 2 to thaw it, and later line 2 with the substituion of a 7 for the 2 in it, to freeze it.

Kent Cooper, AIA
Message 17 of 19

Sea-Haven
Mentor
Mentor

May need to look at 62 as well uses +ve or -ve as toggle.

Frozen and Off (70 . 1) (62 . -7) 

On and Thawed (70 . 0) (62 . 7)

Off only (70 . 0) (62 . -7)

Frozen only (70 . 1) (62 . 7)

Message 18 of 19

Kent1Cooper
Consultant
Consultant

I think I see the cause of the Object ID issue.

 

After thawing that Layer, it sets OvrRf to contain a selection set.  Then it tries to apply the (RCM) function to that.  But (RCM) is designed to work on a (vlax-curve)-type object, not a selection set.

 

If you're expecting the selection set to contain only one thing [presumably a rectangular Polyline?], what happens if you replace

(RCM OvrRf)

with

(RCM (ssname OvrRf 0))

?

Kent Cooper, AIA
Message 19 of 19

Gorra
Advocate
Advocate

@Kent1Cooper Yes, thanks, that worked. I figured it was something like that once I got out of my layer tunnel-vision.

0 Likes