Discussion:
Xref bind and explode problem
(too old to reply)
sjohnson100
2004-11-23 20:54:41 UTC
Permalink
Hi All,

I'm creating an app that will attach, bind and then explode several xrefs. The code to attach and bind works but when I explode, I get run time error "Not applicable". If I run the explode portion of the code separately, it works fine.

What seems to happen is that the database doesn't get updated after the xref is bound and, while the sub is still running it thinks the object is still an xref.

I've tried the block.update and Application.update method with no sucess. Is there another way to refresh the database after my xref is bound?

fyi. I tried just inserting and exploding but it leads to dealing with other overlayed xrefs and stuff that I don't want in the drawing.

Thanks in Advance

Scott
Paul Turvill
2004-11-23 21:02:20 UTC
Permalink
Why go through all those extra steps? Just INSERT (-insert) the file as a
block. If you prefix the filename with an asterisk (*), it will be inserted
already exploded.
___
Post by sjohnson100
I'm creating an app that will attach, bind and then explode several xrefs
sjohnson100
2004-11-23 21:55:19 UTC
Permalink
I need to delete objects from selected layers and It seemed simple enough to explode the object and walk through the returned array, deleting what I need without fear of deleting something unexpectedly.
Paul Turvill
2004-11-23 22:48:45 UTC
Permalink
I don't understand what you hope to accomplish. Physically and logically
there's no difference between Attaching and Binding an XRef and simply
INSERTing it as a block.
___
Post by sjohnson100
I need to delete objects from selected layers and It seemed simple enough
to explode the object and walk through the returned array, deleting what I
need without fear of deleting something unexpectedly.
sjohnson100
2004-11-24 00:35:09 UTC
Permalink
I agree that both methods are the same, except, if the drawing you're inserting has xrefs overlayed in it or even xref that are unloaded. Those overlayed/unloaded xrefs become standard blocks and it just adds another layer of checking and cleanup.

The main purpose of the app is to build survey related drawings from pieces of many different drawings, which, others in the company use as xrefs for working drawings. Personally, I would prefer to attach the needed files as xrefs, freeze some layers and be done. But, they need to edit the data for their field crews. They currently open each drawing, freeze layers and copy/paste the entities they need to another dwg. I want to accomplish the same task.
Art Cooney
2004-11-24 00:55:24 UTC
Permalink
I don't know what version of Acad you're working with, so this may be of no
use to you, but in Acad 2005, xrefs in inserted drawings stay as xrefs and
are resolved if possible.
Post by sjohnson100
I agree that both methods are the same, except, if the drawing you're
inserting has xrefs overlayed in it or even xref that are unloaded. Those
overlayed/unloaded xrefs become standard blocks and it just adds another
layer of checking and cleanup.
The main purpose of the app is to build survey related drawings from
pieces of many different drawings, which, others in the company use as
xrefs for working drawings. Personally, I would prefer to attach the
needed files as xrefs, freeze some layers and be done. But, they need to
edit the data for their field crews. They currently open each drawing,
freeze layers and copy/paste the entities they need to another dwg. I want
to accomplish the same task.
sjohnson100
2004-11-24 22:17:34 UTC
Permalink
I'm using AutoCAD 2004 (Civil series)

To test things I separated into two subs, one to attach and bind while the other explodes and it works. I'm puzzled why the database isn't updated immediately but for now it's a work around. So to recap, these two subs work as they are but if the code is combined to one sub, it fails.

Here are the two subs if anyone is curious:

Sub test1()
Dim acXref As AcadExternalReference
Dim InsertPoint(0 To 2) As Double

InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0

Set acXref = ThisDrawing.ModelSpace.AttachExternalReference("C:\foo.dwg", "foo", InsertPoint, 1, 1, 1, 0, True)
ThisDrawing.Blocks("foo").Bind True
End Sub

Sub test2()
Dim gpCode(1) As Integer
Dim dataValue(1) As Variant
Dim groupCode As Variant, dataCode As Variant
Dim vEnts As Variant
Dim ssXref As AcadSelectionSet

On Error Resume Next
ThisDrawing.SelectionSets("SSET").Delete
On Error GoTo 0
Set ssXref = ThisDrawing.SelectionSets.Add("SSET")
sXrefName = "foo"
gpCode(0) = 0
gpCode(1) = 2
dataValue(0) = "INSERT"
dataValue(1) = sXrefName
groupCode = gpCode
dataCode = dataValue
ssXref.Select acSelectionSetAll, , , groupCode, dataCode
If ssXref.Count > 0 Then
vEnts = ssXref.Item(0).Explode
Set acBlockRef = ssXref.Item(0)
vEnts = acBlockRef.Explode
End If
Ted Schaefer
2004-12-06 17:35:53 UTC
Permalink
I created a bind/purge/compact app a couple year ago, and found that explode
didn't work worth a hoot.
Not sure why this AutoCAD well known bug has persisted through so many
version of AutoCAD.

Just use the in-elegant sendcommand:


Public Sub ExplodeEX(oBlkRef As AcadBlockReference, odwg As AcadDocument)
Dim strCmd As String
Const DbQt As String = """"

On Error Resume Next
SetObjectSpace oBlkRef, odwg
If Not ThisDrawing.Blocks(oBlkRef.Name).IsXRef Then
strCmd = "(command " & DbQt & "explode" & DbQt & " (handent " & DbQt &
oBlkRef.Handle & DbQt & "))" & vbCr
odwg.SendCommand strCmd
End If

End Sub

Public Sub SetObjectSpace(varEnt As Variant, odwg As AcadDocument)
Dim varPnt As Variant
Dim oBlk As AcadBlock

Set oBlk = ThisDrawing.ObjectIdToObject(varEnt.OwnerID)
If StrComp(oBlk.Name, "*Paper_Space", vbTextCompare) = 0 Then
odwg.ActiveSpace = acPaperSpace
ElseIf StrComp(oBlk.Name, "*Model_space", vbTextCompare) = 0 Then
odwg.ActiveSpace = acModelSpace
End If
End Sub
Post by sjohnson100
I'm using AutoCAD 2004 (Civil series)
To test things I separated into two subs, one to attach and bind while the
other explodes and it works. I'm puzzled why the database isn't updated
immediately but for now it's a work around. So to recap, these two subs work
as they are but if the code is combined to one sub, it fails.
Post by sjohnson100
Sub test1()
Dim acXref As AcadExternalReference
Dim InsertPoint(0 To 2) As Double
InsertPoint(0) = 0: InsertPoint(1) = 0: InsertPoint(2) = 0
Set acXref =
ThisDrawing.ModelSpace.AttachExternalReference("C:\foo.dwg", "foo",
InsertPoint, 1, 1, 1, 0, True)
Post by sjohnson100
ThisDrawing.Blocks("foo").Bind True
End Sub
Sub test2()
Dim gpCode(1) As Integer
Dim dataValue(1) As Variant
Dim groupCode As Variant, dataCode As Variant
Dim vEnts As Variant
Dim ssXref As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets("SSET").Delete
On Error GoTo 0
Set ssXref = ThisDrawing.SelectionSets.Add("SSET")
sXrefName = "foo"
gpCode(0) = 0
gpCode(1) = 2
dataValue(0) = "INSERT"
dataValue(1) = sXrefName
groupCode = gpCode
dataCode = dataValue
ssXref.Select acSelectionSetAll, , , groupCode, dataCode
If ssXref.Count > 0 Then
vEnts = ssXref.Item(0).Explode
Set acBlockRef = ssXref.Item(0)
vEnts = acBlockRef.Explode
End If
Loading...