Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Visual Lisp make layer crashes?

2 views
Skip to first unread message

Andrew Shalley

unread,
Feb 25, 2002, 1:23:51 PM2/25/02
to
With the help of great websites like afralisp and acadx and news group
contributors I have been able to (slowly) make some progress with Visual
Lisp's activex commands. Thanks to all!

I am now having problems with creating new layers and then entmaking new
entities on those newly created layers. I get the following error

; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on exception
; error: Exception occurred: 0xC0000005 (Access Violation)

Here is the code
(defun ax:MakeLayer (LayerName color linetype)
;following line inserted for the test only, otherwise set as a standard
global *LayerTable*
(setq LayerTable (vla-get-layers (vla-get-activedocument
(vlax-get-acad-object))))
;
(cond
( (null (tblsearch "layer" LayerName))
(setq LayerName
(vl-catch-all-apply
'vla-add
(list LayerTable Layername)
)
)
(cond
( (vl-catch-all-error-p LayerName)
nil
)
( t
(if color
(vla-put-color LayerName color)
)
(if linetype
(vla-put-linetype LayerName linetype)
)
LayerName
)
)
)
)
)

Here is the test code I use in a new blank drawing (test 50)
(defun test ( i / n color)
;to ensure layers are created each time
(if (setq ss (ssget "x"))
(command "erase" ss "")
)
(command "-purge" "all" "*" "n")
;
(setq n 1)
(repeat i
(setq layername (strcat "layer" (rtos n)))
(setq color (rtos n))
(ax:MakeLayer LayerName color nil)
;
;***see note below
; (command ".-layer" "_c" 1 layername "_c" color layername "")
;
(entmake
(append
'(
(0 . "LINE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
)
(list(cons 8 layername))
'(
(100 . "AcDbLine")
(10 1506.21 145.703 0.0)
(11 1641.47 263.006 0.0)
(210 0.0 0.0 1.0)
)
)
)
(setq n (1+ n))
)
)

With the line marked *** commented out the program crashes.
With the *** line in the program seems to work?? however the newly created
lines (except for the last one created) are invisible? They list as being
there but once I move the single visible entity out the way none of the
others display. If I use standard lisp to entmake the layer I get the same
(invisible entity) problem.

Although I have called command for testing purposes my completed program is
going to be called by a reactor so I cannot include any command calls.

Any insights to this problem would be greatly appreciated?

(Bobby C. Jones Michael Puckett says to say hello)

Regards
Andrew


John Uhden

unread,
Feb 25, 2002, 1:59:59 PM2/25/02
to
I think using (rtos) is your problem. I don't know what your current units, precision, and dimzin settings are, but (rtos 1) might easily return "1.00" or "0'1\"" which don't make for valid layer names. Try (atoi) instead. The only reason your ax:MakeLayer function doesn't crash is that you've wisely used (vla-catch-all-apply).

Also, how about just (command "._layer" "_c" color layername "")

Also, if you're going to be using this within a reactor, then stick with the AxtiveX approach as (command) will rarely work.

--
John Uhden, Cadlantic/formerly CADvantage
mailto:juh...@cadlantic.com
http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711


"Andrew Shalley" <spa...@bogus.com> wrote in message news:48C4495BA1425DA8...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
Feb 25, 2002, 2:02:02 PM2/25/02
to
Andrew,
You have stumbled across an error, a.k.a. a bug, that our good friend
R.Robert Bell exposed for us. I believe that his original thread was titled
"All or nothing" or something like that?? My memory is going quick! The
thrust of that thread was that you will crash and burn when calling vla-*
functions, like your ax:MakeLayer, just prior to calling certain AutoLISP
functions, one of them being ENTMAKE. I believe some of the others were
ENTMOD, GETVAR, & SETVAR. Hopefully someone that really remembers, or that
wrote them down, will let us know. To continue this route, you will either
have to use vla-* methods to add your entities, or create your layers via
standard AutoLISP. All or nuttin'....

Please tell Michael hello for me....are you working with him, or just
seeking his advice like I have so many times in the past...
--
"Make the most of the best
and the least of the worst."
Robert Louis Stevenson

http://www.acadx.com


R. Robert Bell

unread,
Feb 25, 2002, 2:07:03 PM2/25/02
to
Andrew,

I bet you have stumbled into the "All or nothing" bug. Just for giggles, add
a (command) just before the (entmake). What happens?

--
R. Robert Bell, MCSE
www.AcadX.com


"Andrew Shalley" <spa...@bogus.com> wrote in message
news:48C4495BA1425DA8...@in.WebX.maYIadrTaRb...

Paul

unread,
Feb 25, 2002, 2:10:40 PM2/25/02
to
btw
example

;;create a layer
(vla-put-Color (vla-add (vla-get-Layers (vla-get-ActiveDocument
(vlax-get-acad-object))) "TestLayer") 2)
;;create a line
(vla-put-Layer (vla-AddLine (vla-get-ModelSpace (vla-get-ActiveDocument
(vlax-get-Acad-Object)))(vlax-3d-point '(15 15 0)) (vlax-3d-point '(115 15
0))) "TestLayer")


Andrew Shalley

unread,
Feb 25, 2002, 4:00:10 PM2/25/02
to
THANKS ALL for the tips.

I will try changing my code to use vla* functions for creating the entities
as per Paul's posted code. Will also try and track down the "all or nothing"
post.

Robert: If you check out the *** in my test code you'll see I had tried your
command suggestion, not that I have any clue why it works :)

Does anyone know why the second problem occurs (only the last entity is
visible) when I substitute the ax:makelayer with entmake (this same problem
occurs when adding a command call after the ax:makelayer)?

Bobby: I have had the privilege of working with Michael for about 5 years.
He got me going with this programming stuff and has been some what of a
mentor. As you know he is on a temporary leave of absence, I look forward
to his return.

Regards

Andrew


"Andrew Shalley" <spa...@bogus.com> wrote in message
news:48C4495BA1425DA8...@in.WebX.maYIadrTaRb...

Andrew Shalley

unread,
Feb 25, 2002, 4:20:48 PM2/25/02
to
I had a search for the "all or nothing" post but came up empty. Does anyone
have a copy of the post or a list of the functions to stay clear of when
using vla*

Thanx

"Bobby C. Jones" <bob...@acadx.com> wrote in message
news:BBA159E0BF8A8F6B...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Feb 25, 2002, 4:31:01 PM2/25/02
to
"Andrew Shalley" <spa...@bogus.com> wrote in message
news:D22E6563EE73BAF5...@in.WebX.maYIadrTaRb...

> THANKS ALL for the tips.
>
> Robert: If you check out the *** in my test code you'll see I had tried
your
> command suggestion, not that I have any clue why it works :)
>

What I meant was, use your un-commented-out code, but just add a plain
(command) right before the (entmake). You'll get a *Cancel* at the command
prompt that doesn't mean anything, but that sometimes permits the (entmake)
to work. I'm just curious if it does work then (not that I recommend this as
a final solution!).


R. Robert Bell

unread,
Feb 25, 2002, 4:26:56 PM2/25/02
to
I have found these to be trouble spots:

entget, entmod, and setvar (!, but I can't remember if getvar is one
also...)

--
R. Robert Bell, MCSE
www.AcadX.com

"Andrew Shalley" <spa...@bogus.com> wrote in message

news:C734773BDD3C8AB9...@in.WebX.maYIadrTaRb...

Andrew Shalley

unread,
Feb 25, 2002, 5:16:33 PM2/25/02
to
If I understand you correctly this is what I tried,

(defun test ( i / n color)
;to ensure layers are created each time
(if (setq ss (ssget "x"))
(command "erase" ss "")
)
(command "-purge" "all" "*" "n")
;
(setq n 1)
(repeat i
(setq layername (strcat "layer" (rtos n)))
(setq color (rtos n))
(ax:MakeLayer LayerName color nil)
;

(command)


;
(entmake
(append
'(
(0 . "LINE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
)
(list(cons 8 layername))
'(
(100 . "AcDbLine")
(10 1506.21 145.703 0.0)
(11 1641.47 263.006 0.0)
(210 0.0 0.0 1.0)
)
)
)
(setq n (1+ n))
)
)

This still crashes the drawing


; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on exception
; error: Exception occurred: 0xC0000005 (Access Violation)

(command ".-layer" "_c" 1 layername "_c" color layername "") in place of
(command) for some reason doesn't crash the drawing? However still all the
entities created are invisible except the last.

Thanks once again, I appreciate your help.

Regards

Andrew

"R. Robert Bell" <rob...@acadx.com> wrote in message
news:A0E916197613F0C0...@in.WebX.maYIadrTaRb...

Bobby C. Jones

unread,
Feb 25, 2002, 5:28:45 PM2/25/02
to
We are all looking forward to his return :-) It's good to have you 'in the
group'.

LEsquivel

unread,
Feb 25, 2002, 5:30:33 PM2/25/02
to
What version of AutoCAD are you using?

If you have A2000 then also is a problem when you use the purge command all.

LE.


R. Robert Bell

unread,
Feb 25, 2002, 5:55:15 PM2/25/02
to
Andrew,

It is occurring in the purge portion. And thanks for trying the plain
(command), yes you understood!

And as far a visibility goes, it's because you are drawing each line on top
of the other!

(defun test ( i / n color)
;to ensure layers are created each time
(if (setq ss (ssget "x"))
(command "erase" ss "")
)
(command "-purge" "all" "*" "n")
;
(setq n 1)
(repeat i
(setq layername (strcat "layer" (rtos n)))
(setq color (rtos n))
(ax:MakeLayer LayerName color nil)
;
(command)
;
(entmake

(list
'(0 . "LINE")


'(100 . "AcDbEntity")
'(67 . 0)
'(410 . "Model")

(cons 8 layername)
'(100 . "AcDbLine")
(list 10 (+ 1506.21 n) 145.703 0.0)


'(11 1641.47 263.006 0.0)
'(210 0.0 0.0 1.0)
)
)

(setq n (1+ n))
)
)

--


R. Robert Bell, MCSE
www.AcadX.com


"LEsquivel" <arch...@onebox.com> wrote in message
news:8DF1A836DE783674...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Feb 25, 2002, 5:57:25 PM2/25/02
to
Ok, maybe *not* the purge, but this is the bug I tracked down (or very
similar). BTW, use Google.com newsgroup search to find that thread Bobby
mentioned.

--
R. Robert Bell, MCSE
www.AcadX.com

"R. Robert Bell" <rob...@acadx.com> wrote in message

news:E346A9D30CEF1284...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Feb 25, 2002, 7:06:46 PM2/25/02
to
That probably due to your SORTENTS setting. I always keep mine all the way up to 127.

--
John Uhden, Cadlantic/formerly CADvantage
mailto:juh...@cadlantic.com
http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711


"Andrew Shalley" <spa...@bogus.com> wrote in message news:6CEF8076488B3D2B...@in.WebX.maYIadrTaRb...
> I know I am drawing one on top of the other but when I move the line on
> screen (picking a single entity) to the side do a regent (a regenall even) I
> only ever see the moved line. When I do a list with a crossing window the
> remaining lines appear and tell me I have 50 lines in total, then when the
> list command exits the 49 lines disappear leaving only the moved one?
>
> Does it work correctly for you?


>
>
> "R. Robert Bell" <rob...@acadx.com> wrote in message

> news:5BC3769AE0F09FD9...@in.WebX.maYIadrTaRb...

Andrew Shalley

unread,
Feb 25, 2002, 6:55:38 PM2/25/02
to
John

Thanks for your input. The test program crashes without the command call to
purge. I only added this line in prior to my post (maybe in doing so I
confused the issue) to ensure that each time someone runs the test function
that the layers are in fact being re-created. If the layers already exist
there is no problem. Maybe as you say there is a problem with the purge
command but this is not the problem I have, sorry for any confusion.

Did you manage to find a way around your purge crash? (I may need to use
this later).

Regards

Andrew


"John Uhden" <juh...@cadlantic.com> wrote in message
news:9B10E69E39B0D76E...@in.WebX.maYIadrTaRb...
> You guys have spent 1/2 my afternoon!
>
> The PURGE *is* the thing. And it's not just the "Purge" command. I used
my own C:PURGEALL routine which employs (vla-delete) and got the same
crashes. I figure it's some violation or failure of AutoCAD's Undo stack or
mechanism. The crash occurs on the entmake, even if buffered by another
(vl-catch-all...).


>
> --
> John Uhden, Cadlantic/formerly CADvantage
> mailto:juh...@cadlantic.com
> http://www.cadlantic.com
> 2 Village Road
> Sea Girt, NJ 08750
> Tel. 732-974-1711
>
>

> "R. Robert Bell" <rob...@acadx.com> wrote in message

news:5BC3769AE0F09FD9...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Feb 25, 2002, 6:42:06 PM2/25/02
to
You guys have spent 1/2 my afternoon!

The PURGE *is* the thing. And it's not just the "Purge" command. I used my own C:PURGEALL routine which employs (vla-delete) and got the same crashes. I figure it's some violation or failure of AutoCAD's Undo stack or mechanism. The crash occurs on the entmake, even if buffered by another (vl-catch-all...).

--
John Uhden, Cadlantic/formerly CADvantage
mailto:juh...@cadlantic.com
http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711


"R. Robert Bell" <rob...@acadx.com> wrote in message news:5BC3769AE0F09FD9...@in.WebX.maYIadrTaRb...

Andrew Shalley

unread,
Feb 25, 2002, 7:01:59 PM2/25/02
to
I know I am drawing one on top of the other but when I move the line on
screen (picking a single entity) to the side do a regent (a regenall even) I
only ever see the moved line. When I do a list with a crossing window the
remaining lines appear and tell me I have 50 lines in total, then when the
list command exits the 49 lines disappear leaving only the moved one?

Does it work correctly for you?

"R. Robert Bell" <rob...@acadx.com> wrote in message

news:5BC3769AE0F09FD9...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Feb 25, 2002, 7:08:30 PM2/25/02
to
Can't (yet) find a way stop the crashes after "purging." Has anyone yet tried to (vla-add) the lines instead of (entmake)ing them?

--
John Uhden, Cadlantic/formerly CADvantage
mailto:juh...@cadlantic.com
http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711


"Andrew Shalley" <spa...@bogus.com> wrote in message news:40205A09A9CEB4C2...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Feb 25, 2002, 7:07:06 PM2/25/02
to
See your modified code in my prior post.

--
R. Robert Bell, MCSE
www.AcadX.com

"Andrew Shalley" <spa...@bogus.com> wrote in message

news:6CEF8076488B3D2B...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Feb 25, 2002, 7:22:47 PM2/25/02
to
Boy, that's a royal PITA. I've always regarded (entmake) as too cool because you can make it complete in one shot. Anyway, thanks Robert & Luis for the info.

--
John Uhden, Cadlantic/formerly CADvantage
[ mailto:juh...@cadlantic.com ]
[ http://www.cadlantic.com ]
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711

"R. Robert Bell" <rob...@acadx.com> wrote in message news:197FA62306E7E3B2...@in.WebX.maYIadrTaRb...
> Yes, and there was no trouble, even with the (command "purge") left in.


>
> --
> R. Robert Bell, MCSE
> www.AcadX.com
>
>

> "John Uhden" <juh...@cadlantic.com> wrote in message

> news:1B3268DC461B3920...@in.WebX.maYIadrTaRb...

LEsquivel

unread,
Feb 25, 2002, 7:14:46 PM2/25/02
to
I did one, not exactly with Andrew sample, but I'm aware of the purge all (3
times call) *bug*

If I use plain activex works just fine.

LE.

R. Robert Bell

unread,
Feb 25, 2002, 7:13:12 PM2/25/02
to
Yes, and there was no trouble, even with the (command "purge") left in.

--


R. Robert Bell, MCSE
www.AcadX.com

"John Uhden" <juh...@cadlantic.com> wrote in message

news:1B3268DC461B3920...@in.WebX.maYIadrTaRb...

LEsquivel

unread,
Feb 25, 2002, 7:34:26 PM2/25/02
to
Rare,

I tested more than 30 times here in A2Ki and still no problem or crash, but
in A2000 if I purge all 3 times it crashes.

I do not have TuTu here (or "YouYou" just to translate "TuTu" to English
since the word "Tu" means "You") ;^)

LE

"R. Robert Bell" <rob...@acadx.com> wrote in message

news:3E82218A01FE8FBE...@in.WebX.maYIadrTaRb...
> I crashed it running the 2nd time on TuTu...


>
> --
> R. Robert Bell, MCSE
> www.AcadX.com
>
>
> "LEsquivel" <arch...@onebox.com> wrote in message

> news:2C9435CEE72C217D...@in.WebX.maYIadrTaRb...
> > Actually I did tested Andrew's sample in A2Ki and works fine no problem
at
> > all, except on A2000
> >
> > LEsquivel
> >
> >
>
>


LEsquivel

unread,
Feb 25, 2002, 7:23:32 PM2/25/02
to

R. Robert Bell

unread,
Feb 25, 2002, 7:25:22 PM2/25/02
to
I crashed it running the 2nd time on TuTu...

--


R. Robert Bell, MCSE
www.AcadX.com


"LEsquivel" <arch...@onebox.com> wrote in message

news:2C9435CEE72C217D...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Feb 25, 2002, 7:20:48 PM2/25/02
to
We are gonna get dragged, kickin' and a' screamin', into the object
model.... ;-)

--
R. Robert Bell, MCSE
www.AcadX.com


"John Uhden" <juh...@cadlantic.com> wrote in message

news:D78BF4ED91E56E4F...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Feb 25, 2002, 7:27:06 PM2/25/02
to
I hear ya, and it vaccuums.

--
John Uhden, Cadlantic/formerly CADvantage
[ mailto:juh...@cadlantic.com ]
[ http://www.cadlantic.com ]
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711


"R. Robert Bell" <rob...@acadx.com> wrote in message news:9CC6DD41AF19C017...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Feb 25, 2002, 7:31:45 PM2/25/02
to
Exactly. Just to set the record straight. The first time you run it in a drawing, everything is fine. It's the second time in the same session that's a killer.

--
John Uhden, Cadlantic/formerly CADvantage
[ mailto:juh...@cadlantic.com ]
[ http://www.cadlantic.com ]
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711


"R. Robert Bell" <rob...@acadx.com> wrote in message news:3E82218A01FE8FBE...@in.WebX.maYIadrTaRb...

michael puckett

unread,
Feb 25, 2002, 7:15:19 PM2/25/02
to
Sorry Andrew + company -- I don't have the time to peruse
this thread, but ...

If this is about fatalaties related to entmaking layers and
the issue of a subsequent purge command, I too found this.
The unscientific explanation is that an entmake created
layer that has never been refererenced by at least one
entity seems to have an incomplete entry in the drawing
database. A subsequent purge causes *kaboom* when said
command accesses the layer's incomplete database entry
</guess>.

The cheesy work around I've been using for a couple years
was to entmake a layer by actually entmaking a point entity
with the layer name I wanted, then entdel-eting the newly
created point (all wrapped up in one method). This prevented
the crashes.

If I've missed the mark of your discussion I apologize. Best
of luck friend. Doh, back to class ...

"Andrew Shalley" <spa...@bogus.com> wrote in message
news:40205A09A9CEB4C2...@in.WebX.maYIadrTaRb...

Bill McLamb

unread,
Feb 26, 2002, 7:32:14 AM2/26/02
to
Andrew
FYI the thread is It's either "all" or "nothing" date 10 8 01
Bill

Andrew Shalley

unread,
Feb 26, 2002, 9:53:52 AM2/26/02
to
Ahhh I missed that.

With your modified code all the lines show up (in a pretty fan :-)

Do you know the reason that it doesn't work entmaking one on top of the
other?

"R. Robert Bell" <rob...@acadx.com> wrote in message

news:106BB8A6647B045A...@in.WebX.maYIadrTaRb...

Andrew Shalley

unread,
Feb 26, 2002, 10:19:07 AM2/26/02
to
Egg on face!!!

One of the other guys I work with pointed out that as I cycled through test
50 times I was ending up with black lines on top that where masking all the
lines underneath!!!!

Oh the shame.

"Andrew Shalley" <spa...@bogus.com> wrote in message

news:73A97A17034468F1...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Feb 26, 2002, 10:47:26 AM2/26/02
to
<snort> *I* wasn't going to tell you... BwaHaHa!

--
R. Robert Bell, MCSE
www.AcadX.com


"Andrew Shalley" <spa...@bogus.com> wrote in message

news:E493EB031E64A0B9...@in.WebX.maYIadrTaRb...

R. Robert Bell

unread,
Feb 26, 2002, 10:29:36 AM2/26/02
to
"LEsquivel" <arch...@onebox.com> wrote in message
news:B4C1C29AD3A56E6D...@in.WebX.maYIadrTaRb...

> I do not have TuTu here (or "YouYou" just to translate "TuTu" to English
> since the word "Tu" means "You") ;^)

That pun just loses all it's meaning outside of English... ;-)


R. Robert Bell

unread,
Feb 26, 2002, 10:32:26 AM2/26/02
to
Michael, if you have the chance to peruse the thread 'It's either "all" or
"nothing"', 2001-10-08, you'll see the problem goes *much* deeper...

Thanks for popping in!

--
R. Robert Bell, MCSE
www.AcadX.com


"michael puckett" <~> wrote in message
news:05991569B85F531D...@in.WebX.maYIadrTaRb...

michael puckett

unread,
Feb 26, 2002, 12:09:45 PM2/26/02
to
Thanks RB. Found the thread; perhaps I can read it in April
:(

Back to java servlet bashing ...

"R. Robert Bell" <rob...@acadx.com> wrote in message

news:D9D59931CDBCFF52...@in.WebX.maYIadrTaRb...

0 new messages