Jump to content

Error when adding custom drawing property


lfe011969

Recommended Posts

I'm using code from VVA found here to retrieve and set custom drawing properties and I'm trying to figure out how to trap out errors.

 

The typical error I get is:

** ERROR: ActiveX Server returned an error: Parameter not optional **

 

This happens when I think I've assigned a value to a variable then try to set a custom drawing property to that value but in reality the variable is nil.

 

I know I can use (vl-catch-all-apply) but I'm having a tough time figuring it out the correct way to use it. Can anyone give me a generic example of using (vl-catch-all-apply) or some other way to trap out errors while setting these values? Thanks.

Link to comment
Share on other sites

It's usually not a great idea to rely on the vl-catch-all-apply, it's better to check your variables as Lee & VVA shows ... bbbuuuutttt :shock: ... since no-one's shown you the vlcatch-all-apply thingy ... here goes:

 

Say you're using using VVA's _dwgru-dwgprops-set-custom-prop, but instead of trying to test the key and value 1st you simply want it to continue:

(if (vl-catch-all-error-p
     (vl-catch-all-apply '_dwgru-dwgprops-set-custom-prop (list key vale doc))
   )
 (princ "The value wasn't saved.")
 (princ "The setting was saved sucsessfully.")
)

Basically it evaluates the 1st argument (therefore you need to quote the defun's name). Then it passes the 2nd argument as arguments to the evaluated function - that's why it needs to be in a list.

 

What happens is it returns whatever the function would normally return, except if there's an error. Then it returns an error object - that's what the vl-catch-all-error-p tests for.

Link to comment
Share on other sites

Test for a nil variable?

 

(if <variable>
(dosomestuff)
)

 

Or test for a string variable

(if (eq (type <variable>) 'STR)
(dosomestuff)
)

 

 

:oops:

I'm embarrassed to say I didn't even think to do as either of you say. I saw the error and immediately thought to myself this isn't your typical error so I must need to do something special.

 

 

It's usually not a great idea to rely on the vl-catch-all-apply, it's better to check your variables as Lee & VVA shows ... bbbuuuutttt :shock: ... since no-one's shown you the vlcatch-all-apply thingy ... here goes:

 

Say you're using using VVA's _dwgru-dwgprops-set-custom-prop, but instead of trying to test the key and value 1st you simply want it to continue:

(if (vl-catch-all-error-p
(vl-catch-all-apply '_dwgru-dwgprops-set-custom-prop (list key vale doc))
)
(princ "The value wasn't saved.")
(princ "The setting was saved sucsessfully.")
)

Basically it evaluates the 1st argument (therefore you need to quote the defun's name). Then it passes the 2nd argument as arguments to the evaluated function - that's why it needs to be in a list.

 

What happens is it returns whatever the function would normally return, except if there's an error. Then it returns an error object - that's what the vl-catch-all-error-p tests for.

 

Irneb,

 

Thanks for the example and your advice!!

Link to comment
Share on other sites

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...