HiI'm trying to change logical names for certain attachments.Here is my code
Sub ChangeLogicalNames2Ontwerp() Dim mdl As ModelReference Dim oAttachment As Attachment For Each mdl In ActiveDesignFile.Models If mdl.name <> "Default" Then For Each oAttachment In mdl.Attachments If (oAttachment.DesignFile.name = Left(ActiveDesignFile.name, 7) & ".dgn" Or oAttachment.DesignFile.name = ActiveDesignFile.name) And oAttachment.name = "Default" Then oAttachment.LogicalName = "ontwerp" oAttachment.Rewrite oAttachment.Redraw End If Next End If Next End SubProblem is with "oAttachment.Name="Default"
I'm getting error "This operation cannot be completed. Possible cause: The associated design file is unavailable."I'm not sure what's the cause of this.
I've also noticed that sometimes when I do something with logical names, attachments "become invisible". If I check their Display mode in reference manager everything is ok. I have to turn off display and then turn on. after that attachment is visible.
Any help would be appreciated
Hi,
one reason this message occurs is if you try to retrieve properties from an attachment, which design file is not loaded.By default, if display for an attachment is off, the underlying design file is not loaded into the cache, so you can´t read details like model name, level names etc. from that attachment.
In the main menu Workspace > Preferences, Category "Reference" is the setting "Cache when display is off" will make those properties available with display off.Enabling this setting may reduce performance while opening design files with a large number of attachments with display off.But this does not help in case the reference file is not found. For such a case you may first want to check the existence of the model with oAttachment.IsMissingFile.
I hope this helps?Best regards,Artur
I would suggest to add a check, if the file and model of the attachment exist before trying to read .Designfile.name or oAttachment.name.
What I mean is something similar to this:
'..... If Not (oAttachment.IsMissingFile Or oAttachment.IsMissingModel) Then If (oAttachment.DesignFile.name = Left(ActiveDesignFile.name, 7) & ".dgn" Or oAttachment.DesignFile.name = ActiveDesignFile.name) And oAttachment.name = "Default" Then oAttachment.LogicalName = "ontwerp" oAttachment.Rewrite oAttachment.Redraw End If End If '.....
At least this should avoid a runtime error with trying to read properties from missing objects.This also could help finding the reason behind the issues like renamed models/files , possibly network issues etc.
Best regards
Artur
I've added line "If Not (oAttachment.IsMissingFile Or oAttachment.IsMissingModel) Then" but I still got the runtime error.
As I said it has to be some bug I guess.
BTW - here is how the invisible error looks like
as You can see reference is visible and invisible at the same time.I think it has also some impact on my macro. I've tried to add code to turn display off and then on, but that changed nothing :(Very much thank you for your effortBest regardsSlawek
here some further suggestions to try:
- try not to use .Rewrite for each oAttachment. This rewrite should not be required. Without .Rewrite you will need to reopen the reference dialog to see recent changes.
- Iterating the models may require to activate the model before reading attachments.Please try to use mod.Activate before modifying the attachments.
- If the steps do not help, could you please upload a testcase to allow us reproducing the issue - thanks
Best regards,