Jump to content

AutoCAD LISP file sometimes getting error: "Object Reference not set to an instance of an object"


Recommended Posts

Posted

Hello all,

 

I'm trying to make some simple functions for AutoCAD 2023 that will allow me to delete and create a standard Group Filter structure for some files, then add specific layers to them. I split this task into three separate functions: deleteGroupFilters, createGroupFilters and addLayersToFilters. I got to the point where all three worked perfectly on my test drawing, so I then added them to the Startup Suite to avoid having to manually load them in the future. I then began using the functions on a bunch of existing drawings. After using them a few times on numerous different drawings, I got an error: "Object Reference not set to an instance of an object".

image.png.ccbd25fc25270a266f87ceebaa6e5427.png

 

I narrowed it down to a problem with the createGroupFilters function (I think). The error is thrown at random apparently. Sometimes the function works and sometimes it just doesn't. I can literally open a drawing, load the LISP file and it will work, then close the drawing (without saving changes), repeat the process and it will give the error. Once the error pops up, I have to force close the program through task manager. I'm aware what the error means, but unsure how the function is getting it and why it only happens sometimes.

 

Can someone please explain why this is happening? I'm new to LISP and this forum, so apologies in advance if I'm missing something obvious.

 

Cheers,

Callum

createGroupFilters.lsp

Posted

Update: The functions tend to work more frequently (about 90% of the time) if I close the application between opening new drawings. If I open multiple drawings at once and attempt to use the functions, they will generally work for the first one, then throw the error for the next drawing.

Posted (edited)

@cal00 If you would like better assistance, I recommend you supply a sample drawing. I personally don't use layer filters, so I am not familiar with any pitfalls. I cannot say whether this is a problem in AutoCAD or in the way your command is supplied.

   1) Have you tried to step through doing each one of the commands manually, and does it cause the same error?

   2) Does it do the same if you separate the (command) calls?

 

FYI: I tried your LISP on several new drawings and it worked every time without error. I am however using AutoCAD 2024.

Edited by pkenewell
Posted

@pkenewell Thanks for the reply. Unfortunately I can't provide a relevant sample drawing. As for your suggestions:

1) I have stepped through the commands manually. They work every time if I step through the entire process of creating a new group filter. However, I can get the error to pop up if I cancel the process (ie press ESC) or just press ENTER after creating the layer filter name, instead of typing "exit" to end the command. Almost as if not finishing the process properly results in a null reference. This also only happens some of the time.

2) Originally, I had one function that deleted current filters, added a parent filter, created and added the child filters to that filter, then added the appropriate layers to the filters in one go. I have split this into 3 different functions to narrow the error down to createGroupFilters, before making this post. I have since then split the createGroupFilters function into many separate command calls (still in one lisp) with a princ in between to see where the program gets to (see attachment). According to the command line, the function runs through every time successfully, even when the error occurs. 

 

At this point I'm stumped so I'm just going to live with it for now. Thanks, I appreciate your input.

createGroupFilters_2.lsp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...