Hi,
Here is another rule to try. An edge in a DrawingView needs to be selected. If a edge (DrawingCurveSegment) is not selected it displays a message and returns.
This example gets the display name of the document the selected edge belongs to. It uses name to find out if that part is in one of the other views.
Sub Main()
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim refDocDesc
Dim oReferencedDoc
Dim oAssembly
Dim oPart
Dim oOcc As ComponentOccurrence
Dim ModelName
Dim NAME
Dim selObj
Dim partNameToTest
'see if there is something selected
If oDoc.SelectSet.Count > 0 Then
'Get the first selected entity
selObj = oDoc.SelectSet(1)
'MessageBox.Show(TypeName(selObj), "Title")
'see if the selected entity is a DrawingCurve
If TypeName(selObj) = "DrawingCurveSegment" Then
'get the name of the file the selected DrawingCurveSegment is in
Dim oCompDef As ComponentDefinition
oCompDef = selObj.Parent.ModelGeometry.Parent.ComponentDefinition
partNameToTest = oCompDef.Document.DisplayName
' MessageBox.Show(partNameToTest, "Title")
Else
MessageBox.Show("Selected object not an edge in a view", "Title")
Return
End If ' Select object type
Else
MessageBox.Show("Select an edge in a view", "Title")
Return
End If ' SelectSet.Count
For Each oDrawView In oDoc.ActiveSheet.DrawingViews
myString = myString & "View " & oDrawView.Name & vbCr
refDocDesc = oDrawView.ReferencedDocumentDescriptor
oReferencedDoc = refDocDesc.ReferencedDocument
If oReferencedDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
'MessageBox.Show("this is an Assembly", "Title")
oAssembly = oReferencedDoc
'modelName = IO.Path.GetFileName(oAssembly.FullFileName)
'MessageBox.Show("FullFileName = " & oAssembly.FullFileName, "Title")
'NAME = Left(modelName, Len (ModelName) -4) & ":1"
NAME = oAssembly.DisplayName ' & ":1"
myString = myString & "Top level Assembly = " & NAME & vbCr
ElseIf oReferencedDoc.DocumentType = kPresentationDocumentObject Then
'MessageBox.Show("this is a presentation document", "Title")
oAssembly = oReferencedDoc.ReferencedDocuments(1)
modelName = IO.Path.GetFileName(oAssembly.FullFileName)
NAME = Left(modelName, Len (modelName) -4) & ":1"
myString = myString & "Top level Presentation doc = " & NAME & vbCr
' Return
ElseIf oReferencedDoc.DocumentType = kPartDocumentObject
oPart = oReferencedDoc
'MessageBox.Show("This is a Part document " & oPart.FullFileName, "Title")
'Do something here with the part
' Go to the next DrawingView in the for next loop
Continue For
End If
For Each oOcc In oAssembly.ComponentDefinition.Occurrences
Dim oDrawCrvsEnum As DrawingCurvesEnumerator
oDrawCrvsEnum = oDrawView.DrawingCurves(oOcc)
' MessageBox.Show(oDrawCrvsEnum.count)
If oDrawCrvsEnum.Count > 0 Then
'wB added
'if it is an assembly call GetOccName and put the occurrence name in myString
If (oOcc.DefinitionDocumentType = kAssemblyDocumentObject) Then
myString = myString & "SubAssembly " & vbCr
myString = myString & oOcc.Definition.Document.DisplayName & vbCr
'MessageBox.Show(myString)
myString = GetOccName(oOcc.SubOccurrences, myString,partNameToTest )
End If
If (oOcc.DefinitionDocumentType = kPartDocumentObject) Then
' MessageBox.Show(oOcc.Definition.Document.DisplayName)
If oOcc.Definition.Document.DisplayName = partNameToTest Then
myString = myString & partNameToTest & " is in this view !!!" & vbCr
Else
myString = myString & oOcc.Definition.Document.DisplayName & vbCr
End If
End If
End If
Next 'occurrence
Next 'DrawingViews
MessageBox.Show(myString, "Title")
End Sub
Private Function GetOccName(oOccs As ComponentOccurrences, str1 as String, partNameToTest As String) As String
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
'MessageBox.Show("In For each loop" & oOcc.Name)
If (oOcc.DefinitionDocumentType = kPartDocumentObject) Then ' part
If oOcc.Definition.Document.DisplayName = partNameToTest Then
str1 = str1 & partNameToTest & " is in this view !!!" & vbCr
'MessageBox.Show(partNameToTest & " is in this view ", "Title")
Else
str1 = str1 & oOcc.Definition.Document.DisplayName & vbCr
End If
ElseIf (oOcc.DefinitionDocumentType = kAssemblyDocumentObject) Then
str1 = str1 & "SubAssembly " & vbCr
str1 = str1 & oOcc.Definition.Document.DisplayName & vbCr
str1 = GetOccName(oOcc.SubOccurrences, str1, partNameToTest)
Dim oDoc2 As DrawingDocument
oDoc2 = ThisDoc.Document
End If
Next
'MessageBox.Show(Str1 & vbCr & " Returning from GetOccName")
Return str1
End Function
Maybe this is close to what you need.
Thanks,
Wayne
Wayne Brill
Developer Technical Services
Autodesk Developer Network