Hi,
I'm considering ways to streamline an internal process using Microstation V8i SS4.
During the process, we are required to remove all attached drawing references, except specific border ones we're required to use and raster images. These required border references will always be known and are consistent across the drawings. Currently we do this manually for every single drawing; however, I'm wondering if there's a way to use VBA or another solution (like Axiom tools) to accomplish this within a batch process.
For example, I have the following references/raster in two drawing files:
Drawing 1 has: RefA.dgn, RefB.dgn, RefC.dwg, RefD.dxf, & imgA.cit
Drawing 2 has: RefZ.dgn, RefE.dwg, RefF.dxf, & imgB.cit
Between the two files, I only want to keep the RefA.dgn & RefZ.dgn and the particular raster file each file has, but detach all other references.
I've been digging into IF, THEN, and ELSE statements usage within VBAs and quite frankly, I'm inexperienced with VBA. I'm not even sure if VBA allows OR statements either in the event I wish to specify multiple border reference filenames to keep.
So I guess I have a few questions:
1) Is this even possible to do with VBA?
2) Does VBA allow OR statements within IF statements?
Hi Ronald,
try this code:
Option Explicit Public Sub DetachReferences() Dim att As Attachment For Each att In ActiveModelReference.Attachments DetachWhenNotBorder att Next End Sub Private Sub DetachWhenNotBorder(att As Attachment) If ShouldBeRefDetached(att.AttachName) = True Then ActiveModelReference.Attachments.Remove att End If End Sub Private Function ShouldBeRefDetached(fileName As String) As Boolean ShouldBeRefDetached = False If fileName = "RefA.dgn" Then Exit Function End If If fileName = "RefZ.dgn" Then Exit Function End If ShouldBeRefDetached = True End Function
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Ronald Alt
It is possible in VBA, it will require some learning on your part if you aren't sure about conditional statements or looping.
References are attached to models (not files) so first thing is you'll have to do is loop through all your models in a file, then loop through all the attachments & rasters, check to see if the name doesn't match what you want to keep and send command to detach the reference.
Hey Jan,
Thanks for this! This actually works great! It is extremely case-sensitive though for anyone considering using this.
Ronald Alt said:It is extremely case-sensitive though for anyone considering using this.
It's only a draft code, you have to modify and enhance accordingly to your specific conditions and requirements...
Regards,
Ronald Alt said:It is extremely case-sensitive though
Jan's suggestion is to use VBA statement:
If fileName = "RefA.dgn" Then
That performs a literal (case-sensitive) comparison. If you would prefer a case-insensitive comparison, then use VBA function StrComp:
StrComp
If 0 = StrComp (fileName, "RefA.dgn", vbTextCompare) Then
Another trick is to use VBA's Like operator. I'll leave you to investigate that (search the web for VBA Like).
Like
Regards, Jon Summers LA Solutions