Author Topic: help with this routine Please  (Read 7256 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: help with this routine Please
« Reply #15 on: June 02, 2011, 04:57:44 PM »
Perhaps a little pseudo code would help paint a clearer picture.  8-)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12937
  • London, England
Re: help with this routine Please
« Reply #16 on: June 02, 2011, 05:02:39 PM »
I tried to write my earlier code as verbose and clear as possible to show the method

yarik

  • Newt
  • Posts: 32
Re: help with this routine Please
« Reply #17 on: June 02, 2011, 05:20:51 PM »
Many thanks Lee
You code its very clear , I'm just learning but very slowly

 :-)


Coder

  • Swamp Rat
  • Posts: 827
Re: help with this routine Please
« Reply #18 on: June 02, 2011, 05:53:37 PM »
Yarik,

Be aware that your code iterates through the SelectionSet twice (the first time doesn't do anything), furthermore, it iterates through each block definition for every insert in the drawing (when this only needs to happen once), and will iterate through the block collection for every insert (you could use vla-item to get the block definition).

The following code is what my previous post was hinting at, also incorporating Alan's suggestion to exclude XRefs:

Code: [Select]
([color=BLUE]defun[/color] c:test ( [color=BLUE]/[/color] blockcollection blockdefinition blockname i processedblocks selectionset ) ([color=BLUE]vl-load-com[/color])

    ([color=BLUE]setq[/color] BlockCollection
         ([color=BLUE]vla-get-blocks[/color]
             ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))
         )
    )

    ([color=BLUE]if[/color] ([color=BLUE]setq[/color] SelectionSet ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"INSERT"[/color]))))
        ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] i ([color=BLUE]sslength[/color] SelectionSet))
            ([color=BLUE]setq[/color] BlockName ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] SelectionSet ([color=BLUE]setq[/color] i ([color=BLUE]1-[/color] i)))))))

            ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]member[/color] BlockName ProcessedBlocks))
                ([color=BLUE]progn[/color]
                    ([color=BLUE]setq[/color] BlockDefinition ([color=BLUE]vla-item[/color] BlockCollection BlockName))

                    ([color=BLUE]if[/color] ([color=BLUE]eq[/color] [color=BLUE]:vlax-false[/color] ([color=BLUE]vla-get-isxref[/color] BlockDefinition))
                        ([color=BLUE]vlax-for[/color] object BlockDefinition
                            ([color=BLUE]vla-put-color[/color] object [color=BLUE]acbylayer[/color])
                        )
                    )
                    ([color=BLUE]setq[/color] ProcessedBlocks ([color=BLUE]cons[/color] BlockName ProcessedBlocks))
                )
            )
        )
    )
    ([color=BLUE]princ[/color])
)


That's really great Lee .

The way you named the variables is very useful for me to understand the process of the routine .

Great thanks .

Lee Mac

  • Seagull
  • Posts: 12937
  • London, England
Re: help with this routine Please
« Reply #19 on: June 02, 2011, 06:06:54 PM »
That's really great Lee .

The way you named the variables is very useful for me to understand the process of the routine .

Excellent, that was my intention  :-)