Thijs Posted February 10 Share Posted February 10 Hi there, I'm trying to solve a issue and I can;'t figure out how to do this. I wrote a script to find a specific Block called "BASEELE3" OR "BASEKA0", each of these Blocks have nested blocks inside them called "BASELOGO" and "LOC_NAME". I wan't to change the BASELOGO and the LOC_NAME blocks for new ones, only they will keep the same name. I have come to the point where I can find the existing BlockReferences "BASEELE3" and "BASEKA0". But removing (delete) them and insert a new block with the same name, containing revised blocks of "BASELOGO" and "LOC_NAME", doesn't do anything. If I explode the main Block "BASEELE3", and use the same code to search for the "BASELOGO" directly and delete this, and insert the new "BASELOGO", it does work fine. If I delete the "BASEELE3" and do a purgeall (twice), and insert the new BASEELE3 with the nested Blocks BASELOGO and LOC_NAME, it does work. However if I op de drawing afterwords, Autocad recommends to do a recovery on the file because it found 3 errors on the drawing. It seems like I have to delete all three blocks before I insert the new block. But I don't know how. Everywhere people write ThisDrawing.Blocks("BASELOGO").delete does the trick, but it doesn't. Does anyone know how I purge these two blocks (that no longer exist in the drawing after I deleted the main block "BASEELE3" withour getting errors on reopening the drawing? I have added the 2 modules I wrote so far, in the attachment. I would appreciate you help. A_Start_Module.bas GetDWGFiles.bas Quote Link to comment Share on other sites More sharing options...
Thijs Posted February 11 Author Share Posted February 11 16 hours ago, Thijs said: Hi there, I'm trying to solve a issue and I can;'t figure out how to do this. I wrote a script to find a specific Block called "BASEELE3" OR "BASEKA0", each of these Blocks have nested blocks inside them called "BASELOGO" and "LOC_NAME". I wan't to change the BASELOGO and the LOC_NAME blocks for new ones, only they will keep the same name. I have come to the point where I can find the existing BlockReferences "BASEELE3" and "BASEKA0". But removing (delete) them and insert a new block with the same name, containing revised blocks of "BASELOGO" and "LOC_NAME", doesn't do anything. If I explode the main Block "BASEELE3", and use the same code to search for the "BASELOGO" directly and delete this, and insert the new "BASELOGO", it does work fine. If I delete the "BASEELE3" and do a purgeall (twice), and insert the new BASEELE3 with the nested Blocks BASELOGO and LOC_NAME, it does work. However if I op de drawing afterwords, Autocad recommends to do a recovery on the file because it found 3 errors on the drawing. It seems like I have to delete all three blocks before I insert the new block. But I don't know how. Everywhere people write ThisDrawing.Blocks("BASELOGO").delete does the trick, but it doesn't. Does anyone know how I purge these two blocks (that no longer exist in the drawing after I deleted the main block "BASEELE3" withour getting errors on reopening the drawing? I have added the 2 modules I wrote so far, in the attachment. I would appreciate you help. A_Start_Module.bas 4.95 kB · 0 downloads GetDWGFiles.bas 817 B · 0 downloads I already found the solution! It's actually as easy as: - just insert the new block - regen drawing - Delete the inserted block again. - save and close the file Public Sub InsertBlock() Dim INSPOINT(0 To 2) As Double INSPOINT(0) = 100 INSPOINT(1) = 100 INSPOINT(2) = 0 Dim BlockReplacementPath As String BlockReplacementPath = "C:\Users\Thijs\Desktop\VBA code directory LOGO vervangen - kopie - werkt\Ketjen Blocks\" Dim MyPath_Drawings As String MyPath_Drawings = "C:\Users\Thijs\Desktop\VBA code directory LOGO vervangen - kopie - werkt\Tekeningen\" Dim ReplacementBlock As String ReplacementBlock = "BASELOGO" Dim newBlockRefPath As String newBlockRefPath = BlockReplacementPath & ReplacementBlock & ".dwg" 'start Autocad On Error Resume Next Set acadApp = GetObject(, "AutoCAD.Application") On Error GoTo 0 If acadApp Is Nothing Then Set acadApp = CreateObject("AutoCAD.Application") acadApp.Visible = True End If 'Open drawing Dim currentFile As Variant currentFile = "BASEELE3 Heel" acadApp.Documents.Open (MyPath_Drawings & currentFile & ".dwg") 'Insert updated (nested)block Dim ReplacingBlockRefObj As AcadBlockReference Set ReplacingBlockRefObj = ThisDrawing.ModelSpace.InsertBlock _ (INSPOINT, newBlockRefPath, 1#, 1#, 1#, CurrentRotation) ZoomAll 'regen complete drawing ThisDrawing.Regen acAllViewports 'Delete the inserted block again ReplacingBlockRefObj.Delete 'Save the drawing ThisDrawing.SaveAs (MyPath_Drawings & currentFile & "_NEW.dwg") 'close the drawing again ThisDrawing.Close End Sub Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.