Getting Block Insetion point

Getting Block Insetion point

Anonymous
Not applicable
486 Views
3 Replies
Message 1 of 4

Getting Block Insetion point

Anonymous
Not applicable
Hey guys, a thread that's giving me headaches:

- I'm trying, using VBA, to get the insertion point of a block, in order to move it automatically.
I've already read all elements in model space, tested if they were blocks,
got block attibutes, but, when I try to retreive insertionpnt x, y and z,
I only read Zeros.

The next step would move this block to another X,Y position, but a simple "sendcommand MOVE" solves.

Could you please help me?
I can post code here if it would help.
Thx,
0 Likes
487 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hi thilab,

Posting your code would require less guessing and enable a far more
focussed answer.

Regards,

Laurie Comerford

thilab wrote:
> Hey guys, a thread that's giving me headaches:
>
> - I'm trying, using VBA, to get the insertion point of a block, in order to move it automatically.
> I've already read all elements in model space, tested if they were blocks,
> got block attibutes, but, when I try to retreive insertionpnt x, y and z,
> I only read Zeros.
>
> The next step would move this block to another X,Y position, but a simple "sendcommand MOVE" solves.
>
> Could you please help me?
> I can post code here if it would help.
> Thx,
0 Likes
Message 3 of 4

Anonymous
Not applicable
Hey Laurie, its already solved.
Check Code below:

Dim Ar As Variant, i As Long
Ar = Application.GetOpenFilename("Desenhos (*.dwg), *.dwg", , "Selecione o Arquivo dwg", MultiSelect:=True)
If TypeName(Ar) = "Boolean" Then Exit Sub
For t = LBound(Ar) To UBound(Ar)
caminho = Ar(t)
AutoCAD.Documents.Open (caminho)
AutoCAD.Visible = True
Set ThisDrawing = AutoCAD.ActiveDocument

For Each element In ThisDrawing.ModelSpace
If element.EntityType = 7 Then 'Check if its a block.
'Retrieve Insertion point
Var = element.InsertionPoint
MsgBox Var(0)
MsgBox Var(1)
arrayattributes = element.GetAttributes
For i = LBound(arrayattributes) To UBound(arrayattributes)
AttributesCoordinates = arrayattributes(i).InsertionPoint
MsgBox AttributesCoordinates(0)
MsgBox AttributesCoordinates(1)
Next
End If
Next
AutoCAD.ActiveDocument.Close
Next t


Thanks a lot. Edited by: thilab on Apr 14, 2010 11:51 AM
0 Likes
Message 4 of 4

Anonymous
Not applicable
Hi,
Glad you are up and running.

However, instead of looping through every object in model space, you
should look at the filtering tools. You can create a "selectionset"
which contain nothing but "blockreferences" and then process those.
There have been dozens of examples posted here and there are also
examples in the help files.

You also might wish to check the block name, and also check if the
blocks you are processing also "haveattributes"


Regards


Laurie Comerford

thilab wrote:
> Hey Laurie, its already solved.
> Check Code below:
>
> Dim Ar As Variant, i As Long
> Ar = Application.GetOpenFilename("Desenhos (*.dwg), *.dwg", , "Selecione o Arquivo dwg", MultiSelect:=True)
> If TypeName(Ar) = "Boolean" Then Exit Sub
> For t = LBound(Ar) To UBound(Ar)
> caminho = Ar(t)
> AutoCAD.Documents.Open (caminho)
> AutoCAD.Visible = True
> Set ThisDrawing = AutoCAD.ActiveDocument
>
> For Each element In ThisDrawing.ModelSpace
> If element.EntityType = 7 Then 'Check if its a block.
> 'Retrieve Insertion point
> Var = element.InsertionPoint
> MsgBox Var(0)
> MsgBox Var(1)
> arrayattributes = element.GetAttributes
> For i = LBound(arrayattributes) To UBound(arrayattributes)
> AttributesCoordinates = arrayattributes(i).InsertionPoint
> MsgBox AttributesCoordinates(0)
> MsgBox AttributesCoordinates(1)
> Next
> End If
> Next
> AutoCAD.ActiveDocument.Close
> Next t
>
>
> Thanks a lot.
>
> Edited by: thilab on Apr 14, 2010 11:51 AM
0 Likes