Author Topic: Entmake after layer creation throws exception!  (Read 7343 times)

0 Members and 1 Guest are viewing this topic.

zoltan

  • Guest
Entmake after layer creation throws exception!
« on: December 18, 2005, 05:17:12 PM »
This is driving me nuts!  I create a line with EntMakeX and in the DXF list I have a routine that checks if a layer exists.  If not it creates the layer and assignes it the color specified.
like this.

(EntMakeX (List '(0 . "LINE") (Cons 8 (CheckLayerName "Maintained" 8)) '(10 0.0 0.0 0.0) '(11 0.0 0.0 0.0)))

The layer is created correctly and the color is set, but when it gets back to the EntMakeX, it thows an exception:
; error: Exception occurred: 0xC0000005 (Access Violation)
; warning: unwind skipped on exception
; error: Exception occurred: 0xC0000005 (Access Violation)

when you try to save the drawing, AutoCAD crashes with a CER.

This is AutoCAD 2006

I have attached the file, let me know if you guy get the same result.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Entmake after layer creation throws exception!
« Reply #1 on: December 18, 2005, 05:35:07 PM »
Nope....

Command: crashme
<Entity name: 7ef7df10>

Worked first time/everytime.....although this isn't Vanilla Acad. This was tested with the "Land Enabled Map" option of Land Desktop 2006, SP1.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entmake after layer creation throws exception!
« Reply #2 on: December 18, 2005, 06:19:40 PM »
Why are you defining the line with zero length ?

I seems to work as expected if there is a differential between start and endpoints.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entmake after layer creation throws exception!
« Reply #3 on: December 18, 2005, 06:31:21 PM »
..and yes, in AC2006 the posted code spits the dummy

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

.. continuable sometimes ..
then FATAL ERROR if save attempted
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #4 on: December 18, 2005, 07:48:49 PM »
It's most likely crashing because you haven't assigned an owner to the newly created object - then when it goes to save...BOOM!
EntMakeX creates an entity, but it DOES NOT assign an owner to that entity. Try using EntMake instead.

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entmake after layer creation throws exception!
« Reply #5 on: December 18, 2005, 08:11:11 PM »
DUH ! I Couldn't see the forest for the trees ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #6 on: December 18, 2005, 08:26:53 PM »
That twice in less than a week Kerry  :-D :-D :-D

Merry Xmas,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entmake after layer creation throws exception!
« Reply #7 on: December 18, 2005, 09:15:11 PM »
 :cry:


Seasons Greeting to you too Glenn

Be Well
Kerry

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

zoltan

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #8 on: December 18, 2005, 10:56:21 PM »
I am defining a line with 0 length because I will be moving the endpoints later with EntMod.  Making them different still crashes for me.  Also I need the ENAME so I don't want to use EntMake, beside it still crashes.  I just installed Service Pack 1a for Mechanical Desktop and it still crashes.  I have Inventor Series 10 loaded.

Glenn, please explain to me this idea of assigning an owner to an object after making it, because that is new to me.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entmake after layer creation throws exception!
« Reply #9 on: December 18, 2005, 11:43:29 PM »
Just change the EntMakeX to EntMake.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SMadsen

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #10 on: December 19, 2005, 05:25:13 AM »
Zoltan, if the only thing you want is to have an ename returned you should be able to grab it after using ENTMAKE. For built-in functions that mess with the drawing database, it's far more important what the function does than what it returns.

A simple inline example of grabbing the ename could be:
Code: [Select]
(cond ((entmake (list '(0 . "LINE")
                      (cons 8 (CheckLayerName "Maintained" 8))
                      '(10 0.0 0.0 0.0)
                      '(11 20.0 10.0 0.0)
                )
       )
       (setq ename (entlast))
      )
)

zoltan

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #11 on: December 19, 2005, 09:34:58 AM »
Using Entmake instead of EntmakeX still causes an exception for me.

 So what is the difference between EntMake and EntMakeX.  I always thaught that the first returns the EData and the latter returns the EName.  So what is this stuff about assigning an owner? How do you do thais in Lisp?

LE

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #12 on: December 19, 2005, 09:53:21 AM »
I do not have A2006.

What happens if you use visual lisp activex function instead of entmake ?

zoltan

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #13 on: December 19, 2005, 09:58:54 AM »
Ok, I figured out this stuff about owning objects.

When I use VLA-AddLine, it thows and exception and crashes imediatelly with a CER

zoltan

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #14 on: December 19, 2005, 10:16:01 AM »
ok, Sorry, VLA-AddLine works, I just did'nt change it for all of them.

That is the way it will have to be then.

LE

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #15 on: December 19, 2005, 10:34:59 AM »
ok, Sorry, VLA-AddLine works, I just did'nt change it for all of them.

That is the way it will have to be then.

Also, test this:
Code: [Select]
(Defun C:CrashMe  ()
  (CheckLayerName "Maintained" 8)
  (vla-update zf_Acad-Object)
  (EntMakeX
    (List '(0 . "LINE")
  (cons 8 "Maintained")
;;;   (Cons 8 (CheckLayerName "Maintained" 8))
  '(10 0.0 0.0 0.0)
  '(11 0.0 0.0 0.0)))
  )

Must work, I tested your code and was crashing also on autocad 2005, and even tried with my own functions following the same steps as yours and the same crashing, until I took out the layer definition and by forcing an update to the acad object.
« Last Edit: December 19, 2005, 10:38:04 AM by LE »

zoltan

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #16 on: December 19, 2005, 11:57:47 AM »
Now THAT makes sense!  Thanks LE.  Also should I clear the value of zf_Acad-Object so (ZF_Get-Acad-Object) gets a new instance, or is the pointer the same after the object is updated?

LE

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #17 on: December 19, 2005, 12:10:26 PM »
Now THAT makes sense!  Thanks LE.  Also should I clear the value of zf_Acad-Object so (ZF_Get-Acad-Object) gets a new instance, or is the pointer the same after the object is updated?

I followed your code.... I normally used to simple make a call of:

Code: [Select]
(vlax-get-acad-object)

Anytime I needed and never got any problems.

I also every time I access an activeX automation server via getinterfaceobject or xxx-create-object, I make a call to release and gc...

Have fun.

zoltan

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #18 on: December 19, 2005, 12:42:42 PM »
Don't you find it tedious to get a reference to the Acad-Object, the ActiveDocument, and Modelspace every time you want to creat an entity?  I use the ZF_Get-* functions to save alot of typing.  It caches the object in a variable that it can return instead of getting a new reference every time.  It's faster and I've never had a problem...until now.

Concerning releasing the object after the GetInterfaceObject: that is a good point.  I always made a habit of it when getinng an instance of Excel of other APIs, but I kinda forgot that AutoCAD.AcCmColor.16 is another API.  I guess I should write a subroutine that releases the color object stored in zf_AcadColor and set it to nil, so the next call to (ZF_Get-AcadColor) has to get a new instance every time.

it would look like this:
Code: [Select]

(VLA-Put-TrueColor oEntity (GetColor iColor))
(ReleaseColor)


It might be a good idea to wait on releasing the color untill the end of processing alot of entities, since getting an interface object if kinda slow.  What do you folks think?


good stuff, I learned alot today.

LE

  • Guest
Re: Entmake after layer creation throws exception!
« Reply #19 on: December 19, 2005, 12:53:26 PM »
Don't you find it tedious to get a reference to the Acad-Object, the ActiveDocument, and Modelspace every time you want to creat an entity?  I use the ZF_Get-* functions to save alot of typing.  It caches the object in a variable that it can return instead of getting a new reference every time.  It's faster and I've never had a problem...until now.

I was referring to only make a call to (vlax-get-acad-object) instead of having a global, for the other ones you mentioned is what I normally do.

 :-)