Error handling

Error handling

NirantarVidyarthee
Advocate Advocate
1,163 Views
8 Replies
Message 1 of 9

Error handling

NirantarVidyarthee
Advocate
Advocate

1. It seems that command function does not work with vl-catch-all-apply. The following does not work.

 

(vl-catch-all-apply
    'Command
    '("Insert"
      "D:\\A600.dwg"
      (list 0 0 0)
      1
      1
      1
      0
      "x"
      "5"
      ""
      ""
     )
  )

 

Am I missing something.

 

2. Following works but does not execute the command )block not inserted).

 

(vl-catch-all-apply
    'vl-cmdf
    '("Insert"
      "D:\\A600.dwg"
      (list 0 0 0)
      1
      1
      1
      0
      "x"
      "5"
      ""
      ""
     )
  )

 

 

0 Likes
1,164 Views
8 Replies
Replies (8)
Message 2 of 9

DannyNL
Advisor
Advisor

Not sure what you are trying to achieve, but you have way too many arguments for the INSERT command as far as I can tell or at least in the wrong order.

 

COMMAND does not work with vl-catch-all-apply as each argument is passed in the order you provide it. If one of them is wrong it will cause an error.

Reason why VL-CMDF does work is because this first analyses all the arguments and if all are valid runs the command.

 

And in fact the second code with VL-CMDF works perfectly fine, but it throws an catch-all-apply-error exception, because the number of arguments are incorrect for the INSERT command. So you first have to make sure the number of arguments are correct and in the right order.

 

But if you just want to check for an existing block file, why not use:

 

(if
   (setq file (findfile "D:\\A600.dwg"))
   (command "_.INSERT" file "0,0" 1 1 0)
)

Or do you want something else to happen?

0 Likes
Message 3 of 9

roland.r71
Collaborator
Collaborator

@DannyNL wrote:

Not sure what you are trying to achieve, but you have way too many arguments for the INSERT command as far as I can tell or at least in the wrong order.

 

COMMAND does not work with vl-catch-all-apply as each argument is passed in the order you provide it. If one of them is wrong it will cause an error.

Reason why VL-CMDF does work is because this first analyses all the arguments and if all are valid runs the command.

 

And in fact the second code with VL-CMDF works perfectly fine, but it throws an catch-all-apply-error exception, because the number of arguments are incorrect for the INSERT command. So you first have to make sure the number of arguments are correct and in the right order.

 

But if you just want to check for an existing block file, why not use:

 

(if
   (setq file (findfile "D:\\A600.dwg"))
   (command "_.INSERT" file "0,0" 1 1 0)
)

Or do you want something else to happen?


Not necessarily. As it will ask for attribute values, the number of arguments can vary.

However, it now says:

Insertpoint: 0,0,0 - X scale: 1 - Y scale:1 - Rotation angle: 1

Enter attribute values

"first attrib": 0

2nd: x

3rd: 5

4th: ""

5th: ""

 

For example, this is how i insert my page frame and set it to "A3":

(command "_.-insert" blockfile "0,0" 1 "" "" "A3")

 

Note: i also omit setting the scale for Y (as it will be the same as X) and rotation angle (as 0 is default)

 

This does obviously not work if you don't know the block & it's attributes to be inserted.

The reason i rarely do it this way.

0 Likes
Message 4 of 9

DannyNL
Advisor
Advisor

Yes, you are right if there are attributes in your block.

I didn't consider that option anymore since I would not choose to provide the attribute values as arguments as well, as it would make your code just fixed for one specific block. Creating code that can be easily reused is much more efficient in the end.

0 Likes
Message 5 of 9

roland.r71
Collaborator
Collaborator

The problem is your coordinate list (list 0 0 0)

 

(vl-catch-all-apply  'vl-cmdf '("Insert" "D:\\A600.dwg" (list 0 0 0) 1  1 0)) - does not work

(vl-catch-all-apply  'vl-cmdf '("Insert" "D:\\A600.dwg" "0,0" 1  1 0)) - does work

 

0 Likes
Message 6 of 9

NirantarVidyarthee
Advocate
Advocate

I don't think there is no error with '(0 0 0). The following works perfectly.

 

(command "Insert" "D:\\600.dwg" '(0 0 0) 1 1 1 0 "x" "5" "" "")

 

But if there is error in the file name I want to report it to the user. But it seems I am not able to catch the error (and the error message) using vl-catch-all-apply with 'Command or vl-cmdf.

 

0 Likes
Message 7 of 9

DannyNL
Advisor
Advisor

@NirantarVidyarthee wrote:

I don't think there is no error with '(0 0 0). The following works perfectly.

 

(command "Insert" "D:\\600.dwg" '(0 0 0) 1 1 1 0 "x" "5" "" "") 


Yes, in the example you give here it will work perfectly. However, in the code below it will not work.

 

(vl-catch-all-apply  'vl-cmdf '("Insert" "D:\\A600.dwg" (list 0 0 0) 1  1 0))

 

You are passing the list '("Insert" "D:\\A600.dwg" (list 0 0 0) 1  1 0) literally here by preceding it with the ' sign. In that case everything that follows will not be evaluated and (list 0 0 0) will not be processed.

 

 

So you will need to use:

 

(vl-catch-all-apply  'vl-cmdf '("Insert" "D:\\A600.dwg" "0,0,0" 1  1 0))

 

or

 

(vl-catch-all-apply  'vl-cmdf (list "Insert" "D:\\A600.dwg" (list 0 0 0) 1  1 0))

 

 

Message 8 of 9

JamesMaeding
Advisor
Advisor

I've always used lambda for this, like:

(vl-catch-all-apply '(lambda () (COMMAND*  ".SWEEP" CIRCENAME "" PL-ENAME)))

 

is 'vl-cmdf better or worse or same?

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

@NirantarVidyarthee wrote:

....

    '("Insert"
      "D:\\A600.dwg"
      (list 0 0 0)
      1
      1
      1
      0
      "x"
....

Am I missing something.


You're missing the fact that the Insert command does not ask for  a Z scale factor unless  you specify the XYZ option  at the point where it's asking for the X scale factor.

Kent Cooper, AIA
0 Likes