I have a macro that has been working fine for the last couple years, but now is throwing a run-time error and I am hoping someone may be able to point me the right direction to fix it.
While the actual macro does a number of things, I have been able to pinpoint the line causing the error (the Set line below) and have made a verify simplified macro that produces the error:
Sub Test() Dim NewRefAttachment As Attachment Set NewRefAttachment = ActiveModelReference.Attachments.Add("FILENAME", "Default", "Logical Name", "Description", Point3dFromXY(0, 0), Point3dFromXY(0, 0), True, True) NewRefAttachment.Rewrite End Sub
In the code above, if FILENAME is a DGN file, the attachment is added to the file just as you would expect. If FILENAME is a DWG file, I get a run-time error [Run-time error '-2147218317 (80040c73)': Cache not found]. While usually I have been attaching DGN files as references, I know I have successfully attached DWG files.
Any suggestions would be appreciated.
An attachment's logical name must be unique. Be sure that there are no existing attachments with the same logical name when you run your macro.
Regards, Jon Summers LA Solutions
Thank you for the suggestion, but there are no duplicate logical names in my test case and I still get the run-time error.
It might be helpful to see in your original macro to see how you are defining "Logical Name", etc. It's possible that somehow that assignment is creating some bad data for these lines to pass.
MaryB
Power GeoPak 08.11.09.918Power InRoads 08.11.09.918OpenRoads Designer 2021 R2
I may be able to post the whole macro, but I need to check if I'm allowed first. I am not sure it matters, though. The above 3 line macro causes the same run-time error. I purposely removed the variables from the ActiveModelReference.Attachments.Add command to rule out any variable issues. The only difference between the above posted macro and my test macro is in my test macro I have a real file (full path and filename between double quotes, again to rule out a variable issue) instead of FILENAME. When I substitute a DGN file for FILENAME, the macro runs fine. When I substitute a DWG for FILENAME, I get the run-time error. Any DGN I choose works, and any DWG errors.
As for the logical name in my original macro, it is just text between double quotes, no variable, as it is the same every time. Prior to adding the attachment, the macro cycles through the existing attachments looking for an identical logical name. If found, the macro reports an error to the user and then quits the macro.
I am curious. Using the above Test macro, and substituting in a real file for FILENAME, are you able to attach a DWG to a DGN file?
Brian Loughry said:Thank you for the suggestion
It's a process of elimination.
Using the same parameters as your test macro, are you able to attach the same DWG file manually as a reference using MicroStation tools?
Jon Summers said:Using the same parameters as your test macro, are you able to attach the same DWG file manually as a reference using MicroStation tools?
Yes, I can manually attach any DWG file I choose as a reference using Microstation tools.
Prior to posting my question, I thought possibly there was an issue with the DWG file I was initially trying to attach, so I opened it in AutoCAD. It opened fine. Even so, I attempted other DWG files in the above macro and get the same run-time error.
I think we need help from Bentley Systems. Artur Goldsweer , can you replicate this problem?
Hi Brian,
Brian Loughry said:Yes, I can manually attach any DWG file I choose as a reference using Microstation tools.
When you attach DWG manually with success, what parameters/settings, when accessed by VBA code, the attachment has?
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,
Jan Ĺ legr said:what parameters/settings, when accessed by VBA code, the attachment has?
I am not sure what you are asking here. Could you expound a little on what information you are wanting to know?
Jon,
So I tried something this morning that I think takes this outside of a VBA issue. Up until now, when manually trying to attach a DWG reference, I have been using the dialog boxes. This morning I tried using the "reference attach" key-in.
Key-in used: reference attach "FILENAME","Default","Logical Name","Description",,,,
(FILENAME is the full path and filename of the desired reference. There were no other attachments to my test drawing, so no duplication of logical name would be possible.)
This key-in produced interesting results:
DGN file for FILENAME: Reference attached just fine.
DWG file for FILENAME: The reference is not attached and there is no message in the Message Center explaining why not.
A nonexistent DGN or DWG file for FILENAME: Obviously the reference does not attach since it does not exist, but there is a message in the Message Center explaining the file does not exist.
I tested this key-in using multiple DGN and DWG files. The results are constant. If a DGN is being attached, it attaches. If a DWG is being attached, it does not attach and there is no message in the Message Center.
I am not sure where this leaves us. What would allow a reference to attach when using the dialog boxes but not using the key-in? And why no message in the Message Center? It seems to be locating the file, since it doesn't report that the file does not exist in the Message Center, but then why doesn't it attach?
Brian Loughry said:This key-in produced interesting results: DGN file for FILENAME: Reference attached just fine. DWG file for FILENAME: The reference is not attached and there is no message in the Message Center explaining why not.
If that's reproducible then it's a MicroStation bug. That key-in failure and the VBA failure should be investigated by Bentley Systems.
What is the process to have Bentley Systems look into a possible bug?
Brian Loughry said:What is the process to have Bentley Systems look into a possible bug?
First, post a question to the MicroStation Forum. It's possible that a MicroStation user has come across this and can provide an answer.
If the MicroStation Forum yields no result, then the format way to notify Bentley Systems of a bug is via a Service Request (SR).
It's disappointing that the support team ( Robert Hook , Artur Goldsweer ) have not answered.
I did a quick test and could reproduce this error message if the model name does not exist.Did you verify if the DWG file has a model with name "Default".If you are not sure you should use vbNullString - this will take the default model of the reference file.
The test code below worked fine. Also the logical name is not problem. If trying to attach the same combination of filename and logical, the logical name is set to "Refx" automatically.
Code tested with success:
Dim sPath As String sPath = "D:\DGN\empty.dwg" Dim oAtt As Attachment Set oAtt = ActiveModelReference.Attachments.Add(sPath, vbNullString, "logical", "description", Point3dZero, Point3dZero, True, True) oAtt.Rewrite
I hope this helps?
If you still experience an issue please provide a test case here or via a new ServiceCase.
Best regards,Artur
Answer Verified By: Brian Loughry
Hi Artur,
Yes, that was exactly the problem. There was no "Default" model in the DWG file. I am so used to working with Microstation drawings, that it never occurred to me that the model name was the problem. The run-time error and the lack of an error message in the message center made it hard to diagnose. Thank you for the assistance.