Exploding block

Exploding block

Anonymous
Not applicable
432 Views
4 Replies
Message 1 of 5

Exploding block

Anonymous
Not applicable
Hi NG,

I'm having problems with exploding a block. I got this far:
Sub Define_point()

Dim minExt As Variant
Dim maxExt As Variant

For Each ent In ActiveDocument.ModelSpace
With ent
If .ObjectName = "LGDBBORDER" Then
ent.GetBoundingBox minExt, maxExt
'MsgBox minExt(0) & "," & minExt(1) & " en " & maxExt(0) &
"," & maxExt(1)
If minExt(0) > insExtMin(0) Then
insExtMin(0) = minExt(0)
insExtMin(1) = minExt(1)
insExtMin(2) = 0
insExtMax(0) = maxExt(0)
insExtMax(1) = maxExt(1)
insExtMax(2) = 0
End If
End If
End With
Next ent

End Sub

Sub Erase_border()

Dim sstest As AcadSelectionSet
Set sstest = ThisDrawing.PickfirstSelectionSet
sstest.Clear
sstest.Select acSelectionSetCrossing, insExtMin(), insExtMax()
sstest.Erase

End Sub

Sub Insert()
Dim blockname As String
blockname = UserForm1.TextBox1.Value
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insExtMin,
blockname, 1#, 1#, 1#, 0)
End Sub

Sub Test()
UserForm1.Show
End Sub

Private Sub CommandButton1_Click()

With ThisDrawing
.Define_point
.Erase_border
.Insert
End With

Unload UserForm1

End Sub


In the textbox the user types the path name of the block. This works fine,
but when I add the line:
blockRefObj.Explode to the sub Insert I get an automation error.

I think I know the cause of the error, the block, which has to be exploded,
is not yet visible when the macro reached the point where it has to explode
the block.
But I could be wrong, so if I'm wrong can somebody tell me what is the cause
and the solution for the problem?
And if I'm right: can somebody tell me how to solve this?

Frank
0 Likes
433 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
As far as i know, you have to put the objects beeing set free by exploding in an array:
try the following:


Dim blockRefObj as AcadBlockReference

Dim objExploded()

objExploded = blockRefObj.Explode


Note that the Blockreference will stay unchanged - the Elements in objExploded are just copies of the block'
s elements.

fheub
0 Likes
Message 3 of 5

Anonymous
Not applicable
[sorry]I do not have access via Newsreader - once again for readabilty:[/sorry]

As far as i know, you have to put the objects beeing set free by exploding in an array: try the following:

Dim blockRefObj as AcadBlockReference
Dim objExploded()

objExploded = blockRefObj.Explode

Note that the Blockreference will stay unchanged - the Elements in objExploded are just copies of the block' s elements.
fheub
0 Likes
Message 4 of 5

Anonymous
Not applicable
Thanks fheub,

 

But it still isn't of any use the error is still
there and it has explicitly to do with the insert macro. I made it more simple
so it had to work, but even then. The code was as follows:

 

Sub Insert()
   

    Dim insertionPnt(0 To 2) As Double
   
Dim blockRefObj As AcadBlockReference
    Dim
objExploded()
    insertionPnt(0) = 5000: insertionPnt(1) =
5000: insertionPnt(2) = 0
    Set blockRefObj =
ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "Pathname of the block", 1#,
1#, 1#, 0)
    objExploded =
blockRefObj.Explode
   
End Sub

 

But if I run it Acad closes with the warnig fatal
error and after that the option to save the drawing.

So if anybody could help me with this, I would be
thankfull.

 

Frank


style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
As
far as i know, you have to put the objects beeing set free by exploding in an
array:
try the following:


Dim blockRefObj as AcadBlockReference

Dim objExploded()

objExploded = blockRefObj.Explode


Note that the Blockreference will stay unchanged - the Elements in
objExploded are just copies of the block'
s elements.

fheub

0 Likes
Message 5 of 5

Anonymous
Not applicable
Option Explicit

Sub Insert()
Dim insertionPnt(0 To 2) As Double
Dim blockRefObj As AcadBlockReference
Dim objExploded() As AcadObject
insertionPnt(0) = 5000
insertionPnt(1) = 5000
insertionPnt(2) = 0
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
(insertionPnt, "C:\test.dwg", 1, 1, 1, 0)
objExploded = blockRefObj.Explode
End Sub

you need to learn to look in the object browser to see what object type
a method will return. objExploded hsa to be declared as an object - for
which I chose the basic AcadObject. If you don't use the right type the
method is expecting to receive its data, you'll error out.

Also make sure you have Option Explicit declared. With it, your code
bombs before it even runs.
___________________________
Mike Tuersley
AutoCAD Clinic
Rand IMAGINiT Technologies
0 Likes