Author Topic: vla-movetobottom  (Read 3874 times)

0 Members and 1 Guest are viewing this topic.

Reu

  • Guest
vla-movetobottom
« on: March 20, 2013, 09:01:10 AM »
I'm trying to get into using the vl-, vla-, and vlax- functions of AutoLISP. I have looked at the acadauto.chm file until I'm blue in the face (so to speak) and I cannot figure out what the subject function expects me to pass it as an argument. Help please.

Thanks,
    Reuben Shilling

ronjonp

  • Needs a day job
  • Posts: 7531
Re: vla-movetobottom
« Reply #1 on: March 20, 2013, 09:03:16 AM »
Lee has many examples of draw order functions here: http://www.lee-mac.com/draworderfunctions.html

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Reu

  • Guest
Re: vla-movetobottom
« Reply #2 on: March 20, 2013, 09:07:25 AM »
Lee has many examples of draw order functions here: http://www.lee-mac.com/draworderfunctions.html

Thanks Ron. I guess what I'm asking is if I type "(vla-movetobottom" what is AutoLISP  expecting next?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: vla-movetobottom
« Reply #3 on: March 20, 2013, 09:13:49 AM »
From the help file:

Quote
object.MoveToBottom (Objects)

object

SortentsTable
The object this method applies to.

Objects

Variant; the objects to move.

 

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Reu

  • Guest
Re: vla-movetobottom
« Reply #4 on: March 20, 2013, 09:17:18 AM »
From the help file:

Quote
object.MoveToBottom (Objects)

object

SortentsTable
The object this method applies to.

Objects

Variant; the objects to move.

 


So could I put: "(vla-movetobottom (ss) )" where ss is a variable containing a selection set?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: vla-movetobottom
« Reply #5 on: March 20, 2013, 09:25:39 AM »
The help file contents I posted has nothing about selection sets?

Maybe you can pull this apart:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mydraworder (/ doc exd mlines ms sorttbl)
  2.         (setq sorttbl (vl-catch-all-apply 'vla-getobject (list exd "acad_sortents")))
  3.       )
  4.     (setq sorttbl (vla-addobject exd "acad_sortents" "acdbsortentstable"))
  5.   )
  6.   (vlax-for o ms
  7.     (if (= "AcDbMline" (vla-get-objectname o))
  8.       (setq mlines (cons o mlines))
  9.     )
  10.   )
  11.   (if mlines
  12.     (vlax-invoke sorttbl 'movetobottom mlines)
  13.   )
  14.   (vla-regen doc acallviewports)
  15.   (princ)
  16. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Reu

  • Guest
Re: vla-movetobottom
« Reply #6 on: March 20, 2013, 09:26:34 AM »
The help file contents I posted has nothing about selection sets?

Maybe you can pull this apart:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mydraworder (/ doc exd mlines ms sorttbl)
  2.         (setq sorttbl (vl-catch-all-apply 'vla-getobject (list exd "acad_sortents")))
  3.       )
  4.     (setq sorttbl (vla-addobject exd "acad_sortents" "acdbsortentstable"))
  5.   )
  6.   (vlax-for o ms
  7.     (if (= "AcDbMline" (vla-get-objectname o))
  8.       (setq mlines (cons o mlines))
  9.     )
  10.   )
  11.   (if mlines
  12.     (vlax-invoke sorttbl 'movetobottom mlines)
  13.   )
  14.   (vla-regen doc acallviewports)
  15.   (princ)
  16. )

Ok thanks.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: vla-movetobottom
« Reply #7 on: March 20, 2013, 04:21:21 PM »
Not sure if you've understood what's going on, but for those others who might not find it as clear - there's 2 things to note in converting from the VBA example code in the help to VLisp code:

1) Lisp interaction with objects follows the lisp convention of Object Oriented programming. Instead of (like most other languages) breaking the order by placing the object first and then calling its method/property - lisp never breaks the more fundamental convention of first stating the "verb" (method/function, i.e. action) and then what it acts on. To show it more clearly here is equivalent code between C# and Lisp:
Code - C#: [Select]
  1. Val = Func(arg1, arg2); //Set the variable Val to the return value of calling function Func with arg1 & arg2 as parameters.
  2. Object.Method(arg1, arg2); //Call the method Method of the object Object with passing arg1 & arg2 as parameters
  3. Val = Object.Prop1; //Set the variable Val to the value contained in Object's Prop1 property
Code - Lisp: [Select]
  1. (setf Val (Func arg1 arg2)) ;Set the variable Val to the return value of calling function Func with arg1 & arg2 as parameters.
  2. (Method Object arg1 arg2) ;Call the method Method of the object Object with passing arg1 & arg2 as parameters
  3. (setf Val (get Object 'Prop1)) ;Set the variable Val to the value contained in Object's Prop1 property
See how Lisp is always putting the "verb" first? I.e. the function and the method is the "action" to be applied to the parameters - even if one of the parameters is the object. Actually due to this, I find lisp more consistent in its grammar than other languages - lisp never deviates from the Polish notation (i.e. prefix notation) where action is first followed by the parameters, other languages tend to mix-and-match a form of infix with prefix and postfix combined.

So in all cases where lisp is using some form of OOP code, the 1st argument is always the object on which the action should be applied.

2) MoveToBottom is a method of the SortentsTable class. So no you can't simply sent a selection set to it. You need the SorentsTable object reference to be able to make use of its MoveToBottom method - same as you would need in VBA. Note, there can be many SortentsTable objects in the DWG - one for the Model Space, one each for the Paper Space Layouts, and one for each block definition - so you have to find the correct one.

Only after you've got hold of the Sortents can you tell it what to do. And from the help it's expecting a variant array of objects to be passed as the arguments for the MoveToBottom method. So you need to pass a variant safearray of object references to it. But the vlax-invoke function automatically converts a list of objects for you - so you don't need to fiddle with all that as you'd have needed to do if you used vla-MovetoBottom directly or vlax-invoke-method.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Reu

  • Guest
Re: vla-movetobottom
« Reply #8 on: March 20, 2013, 04:27:15 PM »
Not sure if you've understood what's going on, but for those others who might not find it as clear - there's 2 things to note in converting from the VBA example code in the help to VLisp code:

1) Lisp interaction with objects follows the lisp convention of Object Oriented programming. Instead of (like most other languages) breaking the order by placing the object first and then calling its method/property - lisp never breaks the more fundamental convention of first stating the "verb" (method/function, i.e. action) and then what it acts on. To show it more clearly here is equivalent code between C# and Lisp:
Code - C#: [Select]
  1. Val = Func(arg1, arg2); //Set the variable Val to the return value of calling function Func with arg1 & arg2 as parameters.
  2. Object.Method(arg1, arg2); //Call the method Method of the object Object with passing arg1 & arg2 as parameters
  3. Val = Object.Prop1; //Set the variable Val to the value contained in Object's Prop1 property
Code - Lisp: [Select]
  1. (setf Val (Func arg1 arg2)) ;Set the variable Val to the return value of calling function Func with arg1 & arg2 as parameters.
  2. (Method Object arg1 arg2) ;Call the method Method of the object Object with passing arg1 & arg2 as parameters
  3. (setf Val (get Object 'Prop1)) ;Set the variable Val to the value contained in Object's Prop1 property
See how Lisp is always putting the "verb" first? I.e. the function and the method is the "action" to be applied to the parameters - even if one of the parameters is the object. Actually due to this, I find lisp more consistent in its grammar than other languages - lisp never deviates from the Polish notation (i.e. prefix notation) where action is first followed by the parameters, other languages tend to mix-and-match a form of infix with prefix and postfix combined.

So in all cases where lisp is using some form of OOP code, the 1st argument is always the object on which the action should be applied.

2) MoveToBottom is a method of the SortentsTable class. So no you can't simply sent a selection set to it. You need the SorentsTable object reference to be able to make use of its MoveToBottom method - same as you would need in VBA. Note, there can be many SortentsTable objects in the DWG - one for the Model Space, one each for the Paper Space Layouts, and one for each block definition - so you have to find the correct one.

Only after you've got hold of the Sortents can you tell it what to do. And from the help it's expecting a variant array of objects to be passed as the arguments for the MoveToBottom method. So you need to pass a variant safearray of object references to it. But the vlax-invoke function automatically converts a list of objects for you - so you don't need to fiddle with all that as you'd have needed to do if you used vla-MovetoBottom directly or vlax-invoke-method.

Beautiful irneb!

Thanks so very much,
     Reuben Shilling

TheMaster

  • Guest
Re: vla-movetobottom
« Reply #9 on: April 12, 2013, 11:43:27 AM »

1) Lisp interaction with objects follows the lisp convention of Object Oriented programming. Instead of (like most other languages) breaking the order by placing the object first and then calling its method/property - lisp never breaks the more fundamental convention of first stating the "verb" (method/function, i.e. action) and then what it acts on. To show it more clearly here is equivalent code between C# and Lisp:
Code - C#: [Select]
  1. Val = Func(arg1, arg2); //Set the variable Val to the return value of calling function Func with arg1 & arg2 as parameters.
  2. Object.Method(arg1, arg2); //Call the method Method of the object Object with passing arg1 & arg2 as parameters
  3. Val = Object.Prop1; //Set the variable Val to the value contained in Object's Prop1 property
Code - Lisp: [Select]
  1. (setf Val (Func arg1 arg2)) ;Set the variable Val to the return value of calling function Func with arg1 & arg2 as parameters.
  2. (Method Object arg1 arg2) ;Call the method Method of the object Object with passing arg1 & arg2 as parameters
  3. (setf Val (get Object 'Prop1)) ;Set the variable Val to the value contained in Object's Prop1 property
See how Lisp is always putting the "verb" first? I.e. the function and the method is the "action" to be applied to the parameters - even if one of the parameters is the object. Actually due to this, I find lisp more consistent in its grammar than other languages - lisp never deviates from the Polish notation (i.e. prefix notation) where action is first followed by the parameters, other languages tend to mix-and-match a form of infix with prefix and postfix combined.

So in all cases where lisp is using some form of OOP code, the 1st argument is always the object on which the action should be applied.


Code - Text: [Select]
  1.  
  2.    (vlax-invoke-method <object> <method> [<args>...])
  3.  
  4. verses
  5.  
  6.   (<method> <object> [<args>...] )
  7.  
  8.  

The latter being the method defined by importing a type library.

Of course, dynamic objects don't have type libraries, so the only way to invoke their members is via (vlax-invoke/get/put ...), so what is consistent and not 'mix-and-match' about that ?

On the subject of verb/noun verses noun/verb....

Do you rely on noun-verb UI's in AutoCAD (for example, right-click context menus, contextual ribbon tabs, etc.), or do you have the entire command set memorized and use the command line mostly ?