Author Topic: Object Collections vs Lists of Object References  (Read 3232 times)

0 Members and 1 Guest are viewing this topic.

Ben Clark

  • Newt
  • Posts: 94
Object Collections vs Lists of Object References
« on: December 31, 2017, 12:05:02 AM »
When manipulating properties on graphical entities in a user defined selection set, it seems easiest and best to convert that into a lisp list of the vla object references and go from there. This way you can exploit all lisp has to offer as far as list processing.

I'm new to collections and am wondering if it's possible and worth it to instead create an object collection out of those objects and use vlax-for etc. to manipulate the properties in various ways.

It seems that collections are almost always obtained by functions like vla-get-layers and so on. I don't think I've ever seen anyone create a collection out of objects but I may be wrong.

I'm mainly wondering if there could be some advantage to creating a collection that I'm not seeing and operating on that instead of just a list of object refs.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Object Collections vs Lists of Object References
« Reply #1 on: December 31, 2017, 12:40:36 AM »
Hi,

The name of ObjectCollection is used in .NET programming languages or at least I am aware of that it is in C# but lists used in AutoLISP as well but with different call or collection that it does not need to specify the type of the list as in C# or other .NET languages.

As long as you have a selection set of entities then there is no need to obtain them in a list to iterate through each entity so you just need to iterate through each entity individually and the list is not required at all in this case unless you want to use it for a specific task or so.

Hope this clear.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: Object Collections vs Lists of Object References
« Reply #2 on: December 31, 2017, 12:41:35 AM »
Jürg Menzi has a collection of ActiveX VisualLisp derived methods that may be worth studying.

http://www.menziengineering.ch/Downloads/Download.htm
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Ben Clark

  • Newt
  • Posts: 94
Re: Object Collections vs Lists of Object References
« Reply #3 on: December 31, 2017, 01:10:13 AM »
Hi,

The name of ObjectCollection is used in .NET programming languages or at least I am aware of that it is in C# but lists used in AutoLISP as well but with different call or collection that it does not need to specify the type of the list as in C# or other .NET languages.

As long as you have a selection set of entities then there is no need to obtain them in a list to iterate through each entity so you just need to iterate through each entity individually and the list is not required at all in this case unless you want to use it for a specific task or so.

Hope this clear.


Sorry I guess I wasn't clear. My goal is to iterate through them. I'm currently doing it with a lisp list of object references because I'm using visual lisp functions on them. I didn't know creating an object collection would be better.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: Object Collections vs Lists of Object References
« Reply #4 on: December 31, 2017, 01:31:05 AM »

Quote
>>>> I didn't know creating an object collection would be better.

It may not be better.  You need to consider how the data is being selected/collected and what you want to do with the data and what your skill level and patience level are.

My gut level thought is you should stay with what you know ... the execution time difference either way hinges on many factors.
Learning COM collection manipulation and interfacing with vanilla or Visual lisp is not something you'd want to be doing on a big time critical project.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Object Collections vs Lists of Object References
« Reply #5 on: December 31, 2017, 02:06:18 AM »
... I didn't know creating an object collection would be better.

Sorry, I did not mean is that creating object collection would be the way to go but talking in general that is upon the required process or task and nothing else.

It seems to me is that you need to know firstly how to deal with or in other words how to iterate through objects / entities in a selection set then from that stage you could decide yourself whether you need to have a specific objects in a list to used them for other iteration, modification ... etc or not but this still up to the aim of the program.

One more thing that I forgot to light on in my last reply is that you don't need to convert objects to vla-objects to implement your desired task on them when working with DXF group codes would be the easiest and the fastest as I experienced that in most case and also unless you in need of that convertion.

Good luck.

Ben Clark

  • Newt
  • Posts: 94
Re: Object Collections vs Lists of Object References
« Reply #6 on: December 31, 2017, 02:33:14 AM »
Learning COM collection manipulation and interfacing with vanilla or Visual lisp is not something you'd want to be doing on a big time critical project.


What do you mean by this statement? Are you saying vanilla and vlisp aren't suited for large projects in a general sense?
« Last Edit: December 31, 2017, 02:36:30 AM by Ben Clark »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: Object Collections vs Lists of Object References
« Reply #7 on: December 31, 2017, 05:18:51 AM »

No ... re-read what I said.
I'm saying LEARNING complicated stuff while a project clock is ticking is not an ideal situation.

If you NEED to to make the project work you have no option.
If you just want to change because you are inquisitive that will be your load to bear.
 
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Object Collections vs Lists of Object References
« Reply #8 on: December 31, 2017, 06:13:20 AM »
it seems easiest and best to convert that into a lisp list
this is 100% true

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Object Collections vs Lists of Object References
« Reply #9 on: December 31, 2017, 09:54:39 AM »
It seems that collections are almost always obtained by functions like vla-get-layers and so on. I don't think I've ever seen anyone create a collection out of objects but I may be wrong.

If you did want to iterate over objects in a selection set as an ActiveX Collection, you may wish to refer to Method 5 of my tutorial on Selection Set Processing.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Object Collections vs Lists of Object References
« Reply #10 on: December 31, 2017, 10:16:54 AM »
Couldn't figure out an often case where you have to create an "collection and populate it" (see my 2nd paragraph).
Mostly its about obtaining the collection (not creating it), then obtain all of the objects inside of it in a list or just manipulate them while iterating the collection.
But like everyone here said, depents on the type of the collection and what you wan't to do with the stuff inside of it.

I could think of creating a block definition, and add objects inside of it - since the vla-object of block definition is technically a collection.
Or creating an empty selection set object (collection again) which can be populated - but thats a rather unusual approach.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Ben Clark

  • Newt
  • Posts: 94
Re: Object Collections vs Lists of Object References
« Reply #11 on: December 31, 2017, 05:27:43 PM »

No ... re-read what I said.
I'm saying LEARNING complicated stuff while a project clock is ticking is not an ideal situation.

If you NEED to to make the project work you have no option.
If you just want to change because you are inquisitive that will be your load to bear.

I did misunderstand you then. I do indeed just want to change because I'm inquisitive. Using a lisp list of object references is working just fine for what I'm doing. I'm just overly curious and wondered if iterating over a collection had any advantages.




It seems that collections are almost always obtained by functions like vla-get-layers and so on. I don't think I've ever seen anyone create a collection out of objects but I may be wrong.

If you did want to iterate over objects in a selection set as an ActiveX Collection, you may wish to refer to Method 5 of my tutorial on Selection Set Processing.

Lee, that's exactly what I was wondering about. I may try using that method sometime. I really like how well you laid out all those methods of selection set processing. Thank you for that.

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Object Collections vs Lists of Object References
« Reply #12 on: December 31, 2017, 07:45:32 PM »
It seems that collections are almost always obtained by functions like vla-get-layers and so on. I don't think I've ever seen anyone create a collection out of objects but I may be wrong.

If you did want to iterate over objects in a selection set as an ActiveX Collection, you may wish to refer to Method 5 of my tutorial on Selection Set Processing.

Lee, that's exactly what I was wondering about. I may try using that method sometime. I really like how well you laid out all those methods of selection set processing. Thank you for that.

You're most welcome Ben - I'm glad it helped.

The various different ways of iterating over items in a selection set that I describe on that page is of course not exhaustive, but hopefully provides some food for thought.

Lee

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Object Collections vs Lists of Object References
« Reply #13 on: January 07, 2018, 06:18:33 AM »
I apologize for the delay, I do not know if I have understood the question of the OP and
maybe can be interesting this comparison.

Problem: Process the blocks collection several times to make changes (also with ODBX)

Questions:
  1) is ALE_Block_Edit_TablePropsA better than ALE_Block_Edit_TablePropsB?
  2) it is better to create a list of objects and then pass it several times?
Code: [Select]
(defun ALE_Block_Edit_TablePropsA (VlaDoc BlkNms PrpLst / )
  (vlax-for BlkFor (vla-get-blocks VlaDoc)
    (and
      (= :vlax-false (vla-get-IsXref BlkFor) (vla-get-IsLayout BlkFor)) 
      (wcmatch (vla-get-name BlkFor) BlkNms)
      (vlax-for ObjFor BlkFor
        (vl-catch-all-apply
          (function (lambda ( ) (vla-Put-Layer ObjFor (car PrpLst)) (vla-put-Color ObjFor (cadr PrpLst)) (vla-put-Linetype ObjFor (caddr PrpLst))))
        )
      )
    )
  )
  (princ)
)
(defun ALE_Block_GetDefList (VlaDoc BlkNms / OutLst)
  (vlax-for BlkFor (vla-get-blocks VlaDoc)
    (and
      (= :vlax-false (vla-get-IsXref BlkFor) (vla-get-IsLayout BlkFor))
      (wcmatch (vla-get-name BlkFor) BlkNms)
      (setq OutLst (cons BlkFor OutLst))
    )
  )
  OutLst
)
(defun ALE_Block_Edit_TablePropsB (BlkLst BlkNms PrpLst / OutLst BlkNam)
  (foreach ForElm BlkLst
    (if (wcmatch (vla-get-name ForElm) BlkNms)
      (vlax-for ObjFor ForElm
        (vl-catch-all-apply
          (function (lambda ( ) (vla-Put-Layer ObjFor (car PrpLst)) (vla-put-Color ObjFor (cadr PrpLst)) (vla-put-Linetype ObjFor (caddr PrpLst))))
        )
      )
      (setq OutLst (cons ForElm OutLst))
    )
  )
  OutLst
)
(defun TestA ( )
  (ALE_Block_Edit_TablePropsA (vla-get-activedocument (vlax-get-acad-object)) "ABC*" '("Mylayer1" 100 "ByLayer"))
  (ALE_Block_Edit_TablePropsA (vla-get-activedocument (vlax-get-acad-object)) "DEF*" '("Mylayer2" 200 "ByLayer"))
)
(defun TestB ( / BlkDfs)
  (setq BlkDfs (ALE_Block_GetDefList (vla-get-activedocument (vlax-get-acad-object)) "*"))
  (setq BlkDfs (ALE_Block_Edit_TablePropsB BlkDfs "ABC*" '("Mylayer2" 160 "ByLayer")))
               (ALE_Block_Edit_TablePropsB BlkDfs "DEF*" '("Mylayer1" 190 "ByLayer"))
)
Code: [Select]
; about 20000 blocks with different name
(Benchmark '(
  (TestA)
  (TestB)
  (TestA)
  (TestB)
))

(TESTB).....3390 / 1.08 <fastest>
(TESTB).....3422 / 1.07
(TESTA).....3656 / 1
(TESTA).....3672 / 1 <slowest>