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
Tuan,
I was finally able to get back to this project today. Your suggestion worked well for me.
Using part of my original code, I retrieved the attachment name. I then retrieved the last graphical element's file position. I merged the attachment using the "reference merge" key-in. Scanned the file using the IncludeOnlyFilePositionRange search criteria. I took those elements and cloned them into an element array. I then deleted those elements. Lastly I created a cell using the element array and attachment name. I looped this for the other attachments.
Thanks.
Another way to achieve what you want:
choose all; lock element
for each ref:
merge ref with optimized clip
choose all; group; ungroup
get selected elements
process elements
create cell
end for
choose all; unlock element
Tuan is correct. I do not want the clipped elements.
Tuan, this approach sounds like it may work. I'll have to look into it further.
Tuan Le said:But 1 of the issue with merging references is you lose reference specific level override settings.
In my case, this will not affect anything as we do not use level override settings. And in this specific scenario, the customer requires every element moved to level 1, color 0.
Tuan Le said:That was the brief
OP's main caption: Macro to copy attachments, excluding clipped elements. Perhaps the OP could clarify?
Regards, Jon Summers LA Solutions
Brian Loughry said:a way to mimic "merge into master" but keep the attachment elements grouped.
That was the brief.
I don't think OP wanted to specifically find clipped elements. Sounds to me he wanted to "merge" visible elements from a clipped reference.
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?
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: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.