.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select and move a block?

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
520 Views, 8 Replies

Select and move a block?

Hello!
Sorry the bad english guys, I'm Brazilian and I am having a doubt, I have a design. Dwg with multiple blocks must select a block or automatically without clicking on the block to select and then move to a new position, I use the method selectall() can someone give me a hint in vb or c # .net as this can be done?
Any help is welcome!
Thank you!
8 REPLIES 8
Message 2 of 9
bert.vanpeteghem
in reply to: Anonymous

1. Iterate Entities in Modelspace until you find the block(s) you want
2. Modify the blocks Position

That's it! If you need some code or more explanation, do say.

--

http://cupocadnet.blogspot.com Edited by: bert.vanpeteghem@dolmen.be on May 11, 2009 1:41 PM
Message 3 of 9
chiefbraincloud
in reply to: Anonymous

You did not specify how you are Identifying the blocks that you want to move, but I would use your selectall code with a filter that at least gives you just BlockReferences, instead of looping the whole modelspace. If you are choosing blocks based on the name, among other things, you can make the filter give you only the blocks you want.

As bert said, if you need more, ask, but I would also suggest that if you need more, you should describe exactly what you are doing, so the help you get can be more helpful.
Dave O.                                                                  Sig-Logos32.png
Message 4 of 9
bert.vanpeteghem
in reply to: Anonymous

How does selectall() work? Never seen that before...
Message 5 of 9
chiefbraincloud
in reply to: Anonymous

Autodesk.AutoCAD.EditorInput.Editor.SelectAll()

Autodesk.AutoCAD.EditorInput.Editor.SelectAll(Filter)



returns PromptSelectionResult
Dave O.                                                                  Sig-Logos32.png
Message 6 of 9
Anonymous
in reply to: Anonymous

Thanks. I'm not sure wich one would be faster, I should put that to the
test sometimes...

Querying through a BlockTableRecord works pretty fast, while this
requires the Editor to do actions. On the other hand, the Editor will
probably do the same thing internally, and probably faster than .NET...

I'm curious 🙂

chiefbraincloud schreef:
> Autodesk.AutoCAD.EditorInput.Editor.SelectAll()
>
> Autodesk.AutoCAD.EditorInput.Editor.SelectAll(Filter)
>
>
>
> returns PromptSelectionResult
Message 7 of 9
chiefbraincloud
in reply to: Anonymous


I honestly can't say how the selectall method translates to internal code, but when I use it, my purpose is to reduce the size of the list I have to loop through, not to mention avoiding having to type check the object, because I know they are all blockrefs (or whatever I filtered to).



In theory, using SelectAll without a filter would give you all entities in modelspace, without having to get the ModelSpace ID and open the modelspace BTR. It probably would be similar IL code, but would have a couple fewer lines of VB code, and no transaction neccessary (until you try to do something with the objects).

Dave O.                                                                  Sig-Logos32.png
Message 8 of 9
chiefbraincloud
in reply to: Anonymous

Well, you made me curious, so I threw together a really quick, as simple as possible comparison. Two subs which both ultimately do the same thing, but one uses SelectAll with a filter, and the other Loops the modelspace. Both look for a BlockReference, with Attributes, named "FRED", and moves them by (100, 100, 0). I have attached the class for the benefit of the OP.

The disassembled IL code actually ends up about 20 lines shorter on the Model Loop method, and it is interesting to note that it takes a little over 30 lines of IL code (~10 each) to declare the TypedValues to pass the SelectionFilter constructor.

As for which one is faster, I think you would have to have an enormous model for it to be measurable. I suppose I could have put a stopwatch in both of them, and maybe cause them to iterate 1000 times to exaggerrate the difference, but I did not.

Edited by: chiefbraincloud on May 11, 2009 5:33 PM

BTW: I would have attached the IL code, but you can only attach one file, and I didn't want to throw all of it into one text file. If anyone really wants to see the IL code, you'll just have to build the class and disassemble it yourself.
Dave O.                                                                  Sig-Logos32.png
Message 9 of 9
Anonymous
in reply to: Anonymous


This horse's brother was beat long and hard back in
the day in the VBA group, and it would surprise me if it hasn't been beaten some
more.  Granted, the discussions in the VBA group concerned the COM API, but
the general idea still applies.  The rule of thumb is that a selection set
filter is faster than iterating the database because a wrapper must be created
for each entity that your code processes.  Just how much faster depends how
many items are in the drawing and how many items the filter catches.  The
gap grows as the number of items to search over grows, but
it narrows as the percentage of items the filter catches
grows.

 

That being said, CBC is correct; you'll need a
pretty large data set before an end user will see the difference between the
two methods.

 

I have the good fortune of knowing my drawings very
well and their size is such that I have the freedom to choose whichever
of these methods I prefer, and I prefer to iterate the database doing
my own filtering as I think it produces easier to read, and hence easier to
maintain, code.  If I didn't have that level of control or knowledge of the
datasets my code was iterating, however, I'd opt for a selection set
filter.

 

As a side note, I'm very leery of using a code line
count to determine how fast code is going to run.  I think you'll find it
about as accurate as flipping a coin to pick a winner at the horse track
:-)
--
Bobby C. Jones

href="http://bobbycjones.spaces.live.com">http://bobbycjones.spaces.live.com

 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">Well,
you made me curious, so I threw together a really quick, as simple as possible
comparison. Two subs which both ultimately do the same thing, but one uses
SelectAll with a filter, and the other Loops the modelspace. Both look for a
BlockReference, with Attributes, named "FRED", and moves them by (100, 100,
0). I have attached the class for the benefit of the OP.

The
disassembled IL code actually ends up about 20 lines shorter on the Model Loop
method, and it is interesting to note that it takes a little over 30 lines of
IL code (~10 each) to declare the TypedValues to pass the SelectionFilter
constructor.

As for which one is faster, I think you would have to have
an enormous model for it to be measurable. I suppose I could have put a
stopwatch in both of them, and maybe cause them to iterate 1000 times to
exaggerrate the difference, but I did not.

Edited by: chiefbraincloud
on May 11, 2009 5:33 PM

BTW: I would have attached the IL code, but you
can only attach one file, and I didn't want to throw all of it into one text
file. If anyone really wants to see the IL code, you'll just have to build the
class and disassemble it yourself.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost