I found a .mvba that detaches all references that are turned off or missing. What I need is to keep the missing ones that are turned on, or in otherwords, I only want to detach the references that are turned off.
Here is the .mvba that detaches all the off and missing references:Sub detachDisplayOff()For Each Attachment In ActiveModelReference.Attachments Set currentRef = Attachment If currentRef.ElementsVisible = False Then Dim attParent As ModelReference Set attParent = currentRef.ParentModelReference attParent.Attachments.Remove currentRef End IfNextRedrawAllViewsEnd Sub
According to the webiste:
"Note: because of the way MicroStation's attachment objects are structured, this will detachall references that have Display switched off and any reference that cannot be found(ie show in the Reference dialogue box in red). If you want to get clever and ignore themissing references you'll have to add a check on the value of .isMissingModel. "
I'm just wondering if anyone can edit this .mvba to use this .isMissingModel, as I haveno idea what the code is.
I think you want to do something like this …
Sub DetachRefsWithDisplayOff() Dim currentRef As Attachment For Each currentRef In ActiveModelReference.Attachments If Not currentRef.ElementsVisible _ Or _ currentRef.IsMissingFile Then ' You're iterating the active model, ' so the next three lines are redundant 'Dim attParent As ModelReference 'Set attParent = currentRef.ParentModelReference 'attParent.Attachments.Remove currentRef ActiveModelReference.Attachments.Remove currentRef End If Next RedrawAllViews End Sub
Regards, Jon Summers LA Solutions
Regards, Jon Summers LA Solutions
Thanks for the reply, but this still detaches all references that are off or missing but on. I'd like for it to keep the ones missing but Display On.
It sounds like you need "AND" instead of "OR".
I will give that a try.
With "And" instead "Or", it gets rid of only the "Missing" ones. So I decided to try and put Not in front of "currentRef.IsMissingFile Then". This actually got me a lot closer. Now it detaches all the "Found" references that have display turned off. If a "Missing" reference is turned off it will still not delete. I'm closer, and appreciate the help. Keep it coming.
Here is the latest I have:
Dim currentRef As Attachment
For Each currentRef In ActiveModelReference.Attachments
If Not currentRef.ElementsVisible _
Not currentRef.IsMissingFile Then
What happens if you get rid of the IsMissingFile clause?
If Not currentRef.ElementsVisible Then ActiveModelReference.Attachments.Remove currentRef
It might help to both document and explain what's going on if you were to put those conditional clauses into a function. Like this …
' Trivial, but illustrates my point Private Function AreReferenceElementsVisible (ByRef oAttachment As Attachment) _ As Boolean AreReferenceElementsVisible = oAttachment.ElementsVisible End Function Private Function IsMissingReference (ByRef oAttachment As Attachment) _ As Boolean IsMissingReference = oAttachment.IsMissingFile End Function
Here's something more complex — a predicate function …
Private Function RefIsNotVisibleOrNotFound (ByRef oAttachment As Attachment) _ As Boolean RefIsNotVisibleOrNotFound = (Not oAttachment.ElementsVisible) _ Or _ (oAttachment.IsMissingFile And oAttachment.ElementsVisible) End Function
Call your predicate like this …
If RefIsNotVisibleOrNotFound (currentRef) Then … End If
It does as when I first got the file, it detaches all "missing" with Display ON and OFF, and all "found" with Display OFF.