11-09-2020
02:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-09-2020
02:27 AM
Hi Jhoel, thank you for the good advice. I have now done that with AllReferencedOccurrences
and that seems to work for ipt and iam now.
Here is the complete code to use it from other context:
Sub SetIncludeStatusWorkplane()
Call SetIncludeStatusFromAsm("test.ipt", 1, True)
'Call SetIncludeStatusFromAsm("test.iam", 1, True)
End Sub
Public Sub SetIncludeStatusFromAsm(strFileName As String, intWorkplane As Integer, boolSetWorkplane As Boolean)
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
Dim oAsm As AssemblyDocument
Set oAsm = oDrawDoc.ReferencedDocuments(1)
Dim oCompDefAsm As ComponentDefinition
Set oCompDefAsm = oAsm.ComponentDefinition
Dim oDoc As Document
Dim oOcc As ComponentOccurrence
Dim oOccs As ComponentOccurrences
Set oOccs = oAsm.ComponentDefinition.Occurrences
Dim oOccRefs As ComponentOccurrencesEnumerator
Set oOccRefs = oOccs.AllReferencedOccurrences(oCompDefAsm)
For Each oOcc In oOccRefs
'Debug.Print (oOcc.Name)
If FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName) = strFileName Then
Set oCompDef = oOcc.Definition
Dim oWP As WorkPlane
'Get YZ WorkPlane, suppose it's perpendicular to the view
Set oWP = oCompDef.WorkPlanes.item(intWorkplane)
'Create proxy object
Dim oWPpx As WorkPlaneProxy
Call oOcc.CreateGeometryProxy(oWP, oWPpx)
'SetIncludeStatus
Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, boolSetWorkplane)
End If
Next
End Sub
Public Function FileNameFromPath(strFullPath As String) As String
Dim i As Integer
For i = Len(strFullPath) To 1 Step -1
If Mid(strFullPath, i, 1) = "\" Then
FileNameFromPath = Right(strFullPath, Len(strFullPath) - i)
Exit For
End If
Next
End Function
