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

Problem Inserting DWG file as Block

4 REPLIES 4
Reply
Message 1 of 5
GTVic
569 Views, 4 Replies

Problem Inserting DWG file as Block

I have been using the following code to insert blocks from our library:

{code}
blkDWG = New DatabaseServices.Database
blkDWG.ReadDwgFile(myBlockPath, FileShare.Read, True, vbNullString)
AcadDoc.Database.Insert(BlockName, blkDWG, False)
blkDWG.Dispose()
{code}

For a small percentage of our standard blocks, this will fail at the Insert with the following errors: eOutOfRange, eDwgObjectImproperlyRead, or eFilerError

The remedy so far has been to copy/paste the entities from the bad file into our blank template and overwrite the bad file. I also tried inserting as an exploded block into a blank template and wblocking out and neither of those two methods worked.

However, I cannot copy/paste the entities from a dynamic block DWG into a blank drawing and maintain the dynamic block properties. I also have a couple of drawings that are blank and just contain layer definitions, etc. So I need another solution.

Any ideas would be appreciated... Thanks
4 REPLIES 4
Message 2 of 5
GTVic
in reply to: GTVic

I should add that if it were not for this one .NET function there would be no issue with these files. They don't appear to be corrupt in any way, they are just not compatible with the managed code for some reason.
Message 3 of 5
patrick1256
in reply to: GTVic

I have not had any issues inserting blocks, but the difference is do you check to make sure the block does not already exist in your drawing?

which then you can place a new block reference

Patrick K. Johnson
http://www.cadenhancement.com
Message 4 of 5
GTVic
in reply to: GTVic

Yes, that check has been done but I did not show all the code. I found that a solution is to export the dynamic block DWG to 2007 DXF and then open that file and resave as 2007 DWG. Neither solution tells me what was wrong with the DWG in the first place so I guess that will be a mystery.

BTW, the code I demonstrated is able to insert a dynamic block DWG but all the dynamic properties are lost. So some other method is required for dynamic blocks.
Message 5 of 5
GTVic
in reply to: GTVic

Solved the last problem of losing the dynamic block properties:

Previous code:
{code}
blkDWG = New DatabaseServices.Database
Try
blkDWG.ReadDwgFile(myBlockPath, FileShare.Read, True, vbNullString)
AcadDoc.Database.Insert(BlockName, blkDWG, False)
Catch ex As Exception
MsgBox("Insert failed: " + ex.Message, 0, "Block")
Finally
blkDWG.Dispose()
End Try
{code}
New code:
{code}
blkDWG = New DatabaseServices.Database(False, False)
...
{code}

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