Jump to content

Difference between two VLA functions


RepCad

Recommended Posts

Hi all, can anyone tell me what the difference is between two VLA functions?

 

(vla-put -INSERTIONPOINT Obj mypoint)

(vlax-put Obj 'INSERTIONPOINT mypoint)

 

I tested two functions in a program for change Mtext point and I realized the functions don't similar in result , for example this code is working right :

 

(VLA-PUT-INSERTIONPOINT
       MTextObj
       (vlax-3D-point (list 0 0 0))
     )

 

But I get "Exceptons occurred" error for another functions :

 

   (vlax-put MTextObj
        'INSERTIONPOINT
       (vlax-3D-point (list 0 0 0))
     )

 

 

 

Edited by amir0914
Link to comment
Share on other sites

vla-put-insertionpoint requires a variant input as a list of coordinates but the vlax-put does not require a variant, but a list of coordinates only.

Edited by Tharwat
typo
  • Like 1
Link to comment
Share on other sites

1 hour ago, amir0914 said:

Hi all, can anyone tell me what the difference is between tow VLA functions?

 

(vla-put -INSERTIONPOINT Obj mypoint)

(vlax-put Obj 'INSERTIONPOINT mypoint)

 

I tested two functions in a program for change Mtext point and I realized the functions don't similar in result , for example this code is working right :

 

(VLA-PUT-INSERTIONPOINT
       MTextObj
       (vlax-3D-point (list 0 0 0))
     )

 

But I get "Exceptons occurred" error for another functions :

 

   (vlax-put MTextObj
        'INSERTIONPOINT
       (vlax-3D-point (list 0 0 0))
     )

 

 

 

 

To be pedantic 😛 one is a vla function and the other is a vlax function

 

As @Tharwat mentions the vla function requires the point as a variant thus (vlax-3d-point (list 0 0 0)) whilst the vlax just the list (list 0 0 0). The vlax is therefore slightly quicker as it doesn't require the point to be converted.

 

Conversely the (vla-get-insertionpoint) function will return a variant which must be converted to a list whilst the vlax-get returns a list. However take care when using on properties that return boolean property values, using (vla-get-closed obj) or (vlax-get-property obj 'closed) on a polyline will return :vlax-true or :vlax-false whilst vlax-get obj 'closed will return -1 or 0

  • Like 1
Link to comment
Share on other sites

vla-put-insertionpoint uses early binding meaning that access to the property is defined by the Type Library for the AutoCAD ActiveX Component Object Model (COM), whereas vlax-put-property or the undocumented vlax-put function uses late binding, meaning that access to the property is resolved at run-time.

 

The difference between the late-bound functions vlax-put-property and vlax-put is simply that vlax-put will accept native Vanilla AutoLISP data types, thereby allowing you to supply lists of doubles in place of a safearray variant used by vlax-put-property, however, I've experienced issues in the past when using vlax-put with some properties and so tend to opt for vlax-put-property where possible.

 

The differences between early & late binding become more apparent when interfacing with objects outside of the AutoCAD Object Model, for example, such as the Excel Object Model. Here, unless you import the relevant Type Library to define the properties & methods of objects within the Object Model, you will not be able to access properties or invoke methods using the early-bound vla-get-*/vla-put-* or vla-* functions respectively, but only by referencing the property or method by name using the late-bound vlax-get-property/vlax-put-property or vlax-invoke-method functions (or the equivalent undocumented vlax-get/vlax-put & vlax-invoke functions).

 

In terms of performance, since AutoLISP is interpreted at run-time, you'll only take advantage of the performance benefits of early binding if you compile & optimise your program, and even then, the differences are close to negligible.

 

 

Edited by Lee Mac
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Great, thank you so much to Tharwat,dlanorh,Lee Mac.
Your explanation was perfect, and also the explanation of lee mac was very deep and professional.

I read your reply for several times and what I found is that vla functions get or give result as a variant, but the vlax functions work directly with list of points,  therefore I  tested the functions with add point method :

 

(vla-AddPoint modelSpace (vlax-3D-point (list 0 0 0)))                                ;;; This is work right

(vlax-invoke modelSpace 'AddPoint (list 0 0 0))                                            ;;; But this one is not working  and give  ""Exceptons occurred"", as you all said vlax accept a list.

 

Link to comment
Share on other sites

11 hours ago, Tharwat said:

You need to have the list of coordinates with decimal numbers. eg : (list 0.0 0.0 0.0) or '(0.0 0.0 0.0)

Thank  you again. my problem has been resolved. you all are great.

Edited by amir0914
Link to comment
Share on other sites

On 1/19/2020 at 11:37 AM, Tharwat said:

You're welcome anytime.

Hello again, I have another problem with vla and  vlax get user input functions, for example

 

(vlax-invoke utility 'getinteger "\nEnter an Integer: ")

 

it works well when I enter an integer value but it gives this error when nothing enter in the function :  "; error: Automation Error. User input is a keyword" 

I rewrite it to this form :

 

  (if (= (setq k (vlax-invoke utility 'getinteger "\nEnter an Integer: "))
     nil
      )
    (setq k 0)
  )

 

but it gives same error yet.

Link to comment
Share on other sites

The getXXX methods of the utility object will throw an exception for invalid input (which you would need to catch using vl-catch-all-apply/vl-catch-all-error-p) rather than gracefully returning nil.

 

Why not use getint?

Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

1 hour ago, amir0914 said:

Hello again, I have another problem with vla and  vlax get user input functions, for example

 

(vlax-invoke utility 'getinteger "\nEnter an Integer: ")

 

it works well when I enter an integer value but it gives this error when nothing enter in the function :  "; error: Automation Error. User input is a keyword" 

I rewrite it to this form :

 

  (if (= (setq k (vlax-invoke utility 'getinteger "\nEnter an Integer: "))
     nil
      )
    (setq k 0)
  )

 

but it gives same error yet.

 

You would need to use the "utility" 'InitializeUserInput method before using the 'getinteger method. This controls what can be entered and is the VL equivalent to the Autolisp (initget) 

 

(initget 7);; disallow null input (bit 1) disallow 0 (zero) input (bit 2) and disallow negative iteger (bit 4)
(setq integer (getint "\nEnter an Integer Value))

An (initget) only works for the next "getxxx" statement

 

  • Like 1
Link to comment
Share on other sites

On 1/23/2020 at 10:09 PM, Lee Mac said:

The getXXX methods of the utility object will throw an exception for invalid input (which you would need to catch using vl-catch-all-apply/vl-catch-all-error-p) rather than gracefully returning nil.

 

Why not use getint?

 Thank you for  vl-catch-all-apply/vl-catch-all-error-p, this code resolved my problem.

 

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