How to copy entities from a XRef to modelspace?

How to copy entities from a XRef to modelspace?

Anonymous
Not applicable
710 Views
7 Replies
Message 1 of 8

How to copy entities from a XRef to modelspace?

Anonymous
Not applicable
Hello, everybody...
I'm trying actually to recover a file wich couldn't be opened in a normal
way (fatal error, internal error ...)

I can insert it as XRef in a new drawing. To recover the drawing, I would
like to copy all the entities from the XRef to the empty modelspace.

I use this code :

Sub xrefcopy()
Dim objSS As AcadSelectionSet
Dim entity As AcadEntity
Dim xref As AcadBlock
Dim NewEntity As AcadEntity

Set objSS = ThisDrawing.SelectionSets.Add("all")
objSS.Select acSelectionSetAll

For Each entity In objSS
If entity.ObjectName = "AcDbBlockReference" Then
Set xref = ThisDrawing.Blocks(entity.Name)
End If
Next entity

For Each entity In xref
Set NewEntity = entity.Copy
NewEntity.Layer = "0"
Next entity

If Not objSS Is Nothing Then
objSS.Delete
End If

ThisDrawing.Regen acAllViewports
End Sub

It works... But not as I would like... Every entity is copied, but INSIDE
the XRef !
When I remove it, nothing stays on the screen. So it doesn't help me...
I've thought it was maybe because I send the entities on the "0" layer. But
it doesn't work. If I try to send an entity on a new layer from the
modelspace, it makes an error;

What can I do? Thanks for your help...

Alexis Perdaen
AM4D
Brussels, Belgium
0 Likes
711 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
When you insert it, all you have in modelspace to copy is the insert itself.
Try to bind, then explode it. Not even a need for VB.

Brian D.


"AM4D" wrote in message
news:[email protected]...
> Hello, everybody...
> I'm trying actually to recover a file wich couldn't be opened in a normal
> way (fatal error, internal error ...)
>
> I can insert it as XRef in a new drawing. To recover the drawing, I would
> like to copy all the entities from the XRef to the empty modelspace.
>
> I use this code :
>
> Sub xrefcopy()
> Dim objSS As AcadSelectionSet
> Dim entity As AcadEntity
> Dim xref As AcadBlock
> Dim NewEntity As AcadEntity
>
> Set objSS = ThisDrawing.SelectionSets.Add("all")
> objSS.Select acSelectionSetAll
>
> For Each entity In objSS
> If entity.ObjectName = "AcDbBlockReference" Then
> Set xref = ThisDrawing.Blocks(entity.Name)
> End If
> Next entity
>
> For Each entity In xref
> Set NewEntity = entity.Copy
> NewEntity.Layer = "0"
> Next entity
>
> If Not objSS Is Nothing Then
> objSS.Delete
> End If
>
> ThisDrawing.Regen acAllViewports
> End Sub
>
> It works... But not as I would like... Every entity is copied, but INSIDE
> the XRef !
> When I remove it, nothing stays on the screen. So it doesn't help me...
> I've thought it was maybe because I send the entities on the "0" layer.
But
> it doesn't work. If I try to send an entity on a new layer from the
> modelspace, it makes an error;
>
> What can I do? Thanks for your help...
>
> Alexis Perdaen
> AM4D
> Brussels, Belgium
>
>
0 Likes
Message 3 of 8

Anonymous
Not applicable
The problem is that the file is corrupted. When I bind it, I get a fatal
error...
I think the only way to recover my drawing is to find a method to export
each entity of my XRef, one by one, to the modelspace...

You maybe have another idea...

Thanks
"Brian D." a écrit dans le
message de news: [email protected]...
> When you insert it, all you have in modelspace to copy is the insert
itself.
> Try to bind, then explode it. Not even a need for VB.
>
> Brian D.
>
>
> "AM4D" wrote in message
> news:[email protected]...
> > Hello, everybody...
> > I'm trying actually to recover a file wich couldn't be opened in a
normal
> > way (fatal error, internal error ...)
> >
> > I can insert it as XRef in a new drawing. To recover the drawing, I
would
> > like to copy all the entities from the XRef to the empty modelspace.
> >
> > I use this code :
> >
> > Sub xrefcopy()
> > Dim objSS As AcadSelectionSet
> > Dim entity As AcadEntity
> > Dim xref As AcadBlock
> > Dim NewEntity As AcadEntity
> >
> > Set objSS = ThisDrawing.SelectionSets.Add("all")
> > objSS.Select acSelectionSetAll
> >
> > For Each entity In objSS
> > If entity.ObjectName = "AcDbBlockReference" Then
> > Set xref = ThisDrawing.Blocks(entity.Name)
> > End If
> > Next entity
> >
> > For Each entity In xref
> > Set NewEntity = entity.Copy
> > NewEntity.Layer = "0"
> > Next entity
> >
> > If Not objSS Is Nothing Then
> > objSS.Delete
> > End If
> >
> > ThisDrawing.Regen acAllViewports
> > End Sub
> >
> > It works... But not as I would like... Every entity is copied, but
INSIDE
> > the XRef !
> > When I remove it, nothing stays on the screen. So it doesn't help me...
> > I've thought it was maybe because I send the entities on the "0" layer.
> But
> > it doesn't work. If I try to send an entity on a new layer from the
> > modelspace, it makes an error;
> >
> > What can I do? Thanks for your help...
> >
> > Alexis Perdaen
> > AM4D
> > Brussels, Belgium
> >
> >
>
>
0 Likes
Message 4 of 8

Anonymous
Not applicable
Look at the CopyObjects method instead of Copy.
--
Bobby C. Jones
http://www.acadx.com
0 Likes
Message 5 of 8

Anonymous
Not applicable
Hello, Bobby,

I have already tried it... with the same problem. The copied object stays
inside of the XRef...


"Bobby C. Jones" a écrit dans le message de news:
[email protected]...
> Look at the CopyObjects method instead of Copy.
> --
> Bobby C. Jones
> http://www.acadx.com
>
>
>
0 Likes
Message 6 of 8

Anonymous
Not applicable
I haven't tried it, but I believe you can get to the objects in the Xref
through the "XRefDatabase" property.

An Xref is a block insert. Find the block record in the blocks collection,
then take the XRefDatabase property from it. Dig through it for your
entities.

Brian D.


"AM4D" wrote in message
news:[email protected]...
> The problem is that the file is corrupted. When I bind it, I get a fatal
> error...
> I think the only way to recover my drawing is to find a method to export
> each entity of my XRef, one by one, to the modelspace...
>
> You maybe have another idea...
>
> Thanks
> "Brian D." a écrit dans le
> message de news: [email protected]...
> > When you insert it, all you have in modelspace to copy is the insert
> itself.
> > Try to bind, then explode it. Not even a need for VB.
> >
> > Brian D.
> >
> >
> > "AM4D" wrote in message
> > news:[email protected]...
> > > Hello, everybody...
> > > I'm trying actually to recover a file wich couldn't be opened in a
> normal
> > > way (fatal error, internal error ...)
> > >
> > > I can insert it as XRef in a new drawing. To recover the drawing, I
> would
> > > like to copy all the entities from the XRef to the empty modelspace.
> > >
> > > I use this code :
> > >
> > > Sub xrefcopy()
> > > Dim objSS As AcadSelectionSet
> > > Dim entity As AcadEntity
> > > Dim xref As AcadBlock
> > > Dim NewEntity As AcadEntity
> > >
> > > Set objSS = ThisDrawing.SelectionSets.Add("all")
> > > objSS.Select acSelectionSetAll
> > >
> > > For Each entity In objSS
> > > If entity.ObjectName = "AcDbBlockReference" Then
> > > Set xref = ThisDrawing.Blocks(entity.Name)
> > > End If
> > > Next entity
> > >
> > > For Each entity In xref
> > > Set NewEntity = entity.Copy
> > > NewEntity.Layer = "0"
> > > Next entity
> > >
> > > If Not objSS Is Nothing Then
> > > objSS.Delete
> > > End If
> > >
> > > ThisDrawing.Regen acAllViewports
> > > End Sub
> > >
> > > It works... But not as I would like... Every entity is copied, but
> INSIDE
> > > the XRef !
> > > When I remove it, nothing stays on the screen. So it doesn't help
me...
> > > I've thought it was maybe because I send the entities on the "0"
layer.
> > But
> > > it doesn't work. If I try to send an entity on a new layer from the
> > > modelspace, it makes an error;
> > >
> > > What can I do? Thanks for your help...
> > >
> > > Alexis Perdaen
> > > AM4D
> > > Brussels, Belgium
> > >
> > >
> >
> >
>
>
0 Likes
Message 7 of 8

Anonymous
Not applicable
Try inserting (as block) the XREF file into a new drawing (if successful
then save)
Try exploding the block (if successful then save)
Try zoom extents (if successful then save)

If the above trials are unsuccessful then you can try using the partial open
command to read in a layer at a time. You will probably read in one or two
layers that cause the problem again. Just avoid those layers when doing the
partial open (the next time) and SaveAs the drawing to another name after
you have as much as you can salvage.

HTH, Andy
0 Likes
Message 8 of 8

Anonymous
Not applicable
You must provide the modelspace object as the owner argument.
--
Bobby C. Jones
http://www.acadx.com

"AM4D" wrote in message
news:[email protected]...
> Hello, Bobby,
>
> I have already tried it... with the same problem. The copied object stays
> inside of the XRef...
>
>
> "Bobby C. Jones" a écrit dans le message de news:
> [email protected]...
> > Look at the CopyObjects method instead of Copy.
> > --
> > Bobby C. Jones
> > http://www.acadx.com
> >
> >
> >
>
>
0 Likes