I have a VBA macro the reads each attachment, copies the graphical elements into an array, and writes the array of elements into the active model as a cell. (See code.) I now need to go a step further and address any elements that are clipped from the attachment. As currently written, the macro copies every graphical element, visible and clipped. Is it possible to exclude the clipped elements? In essence I am looking for a way to mimic "merge into master" but keep the attachment elements grouped.
Option Explicit Option Base 1 Sub MergeReferences() Dim nAttachments As Integer nAttachments = ActiveModelReference.Attachments.Count Dim i As Integer For i = nAttachments To 1 Step -1 If LCase(ActiveModelReference.Attachments.Item(i).AttachName) <> "sig.dgn" Then If ActiveModelReference.Attachments.Item(i).DisplayFlag = True Then Dim NewCellName As String If ActiveModelReference.Attachments.Item(i).LogicalName <> "" Then NewCellName = ActiveModelReference.Attachments.Item(i).LogicalName Else NewCellName = ActiveModelReference.Attachments.Item(i).AttachName End If Dim sc As New ElementScanCriteria sc.ExcludeNonGraphical Dim cc As New CopyContext cc.LevelHandling = msdCopyContextLevelCopyIfNotFound Dim ee As ElementEnumerator Set ee = ActiveModelReference.Attachments.Item(i).Scan(sc) Dim eleArray() As Element Dim m As Integer m = 0 While ee.MoveNext If ee.Current.Type = msdElementTypeText Then If ee.Current.AsTextElement.Text = "$DOCSET_CURRENTSETDOC$" Then ActiveModelReference.CopyElement ee.Current, cc ElseIf ee.Current.AsTextElement.Text = "$DOCSET_NUMSETDOCS$" Then ActiveModelReference.CopyElement ee.Current, cc ElseIf ee.Current.AsTextElement.Text = "INSERT$CO" Then ActiveModelReference.CopyElement ee.Current, cc Else m = m + 1 ReDim Preserve eleArray(m) Set eleArray(m) = ee.Current.Clone End If Else m = m + 1 ReDim Preserve eleArray(m) Set eleArray(m) = ee.Current.Clone End If Wend Dim eleCell As CellElement Set eleCell = CreateCellElement1(NewCellName, eleArray, Point3dFromXY(0, 0)) ActiveModelReference.AddElement eleCell ActiveModelReference.Attachments.Remove i End If End If Next i ActiveDesignFile.Views.Item(1).DisplaysTags = True End Sub
rather than copying elements, you can try this approach:
run keyin from vba to merge a reference with optimized clipping turn on
create a cell from the newly merged element
The tricky bit would be to identify "newly merged elements" but I'm pretty sure there're examples around for that topic.
But 1 of the issue with merging references is you lose reference specific level override settings.
Answer Verified By: Brian Loughry
Tuan Le said:The tricky bit would be to identify "newly merged elements" but I'm pretty sure there're examples around for that topic
Please be more specific: what examples show how to obtain 'newly merged elements' (a.k.a. 'newly created elements')?
Regards, Jon Summers LA Solutions
For one, there's an example called "Find Dropped Cell Using IncludeOnlyFilePositionRange" in the microstation vba help file, which can be accessed via the "example" link from IncludeOnlyFilePositionRange Method entry.
Tuan Le said:there's an example called "Find Dropped Cell Using IncludeOnlyFilePositionRange" in the microstation vba help
Yes, that could be used to help find newly-merged elements. However, it doesn't help distinguish between clipped and unclipped elements.
That distinction should be taken care of by the 1st step "run keyin from vba to merge a reference with optimized clipping turn on" :)
Tuan Le said:That distinction should be taken care of by the 1st step "run keyin from vba to merge a reference with optimized clipping turn on"
I still don't get it. From MicroStation Help: Optimized Fence Clipping setting affects the way that solids and surfaces are clipped.
How does that help the OP find clipped elements?
I don't think OP wanted to specifically find clipped elements. Sounds to me he wanted to "merge" visible elements from a clipped reference.
Brian Loughry said:a way to mimic "merge into master" but keep the attachment elements grouped.
That was the brief.
Tuan Le said:That was the brief
OP's main caption: Macro to copy attachments, excluding clipped elements. Perhaps the OP could clarify?
Tuan is correct. I do not want the clipped elements.