11-07-2020
12:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
11-07-2020
12:17 PM
I want to set the IncludeStatus of Workplanes with the API for some parts or assemblies.
In the first level of the referenced assembly this works fine.
Then i use TraverseAssembly to do the same in second or deeper levels of the assembly.
In this case i get an error in the TraverseAssembly in line:
Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, True)
Here is the code i wrote in VBA:
Public Sub SetIncludeStatusFromAsm()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
Dim intWorkplane As Integer
intWorkplane = 1 'YZ-Plane
'Get referenced Assembly document
Dim strFileName As String
'File in which the workplane is to be included
strFileName = "testfile.ipt" 'testfile.iam"
Dim oAsm As AssemblyDocument
Set oAsm = oDrawDoc.ReferencedDocuments(1)
Dim oCompDef As ComponentDefinition
Dim oDoc As Document
Dim oOcc As ComponentOccurrence
Dim oOccs As ComponentOccurrences
Set oOccs = oAsm.ComponentDefinition.Occurrences
'Search for the strFileName occurence
For Each oOcc In oOccs
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, True)
Else
If oOcc.Definition.Type = kAssemblyComponentDefinitionObject Then
Call TraverseAssembly(oOcc.Definition.Occurrences, strFileName, intWorkplane, oSheet)
End If
End If
Next
End Sub
Sub TraverseAssembly(Occurrences As ComponentOccurrences, strFileName As String, intWorkplane As Integer, oSheet As Sheet)
' Iterate through all of the occurrence in this collection. This
' represents the occurrences at the top level of an assembly.
Dim oOcc As ComponentOccurrence
For Each oOcc In Occurrences
Debug.Print (oOcc.Name) & " - " & FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName)
If FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName) = strFileName Then
Dim oCompDef As ComponentDefinition
Set oCompDef = oOcc.Definition
Dim oWP As WorkPlane
'Get WorkPlane 1 (YZ), 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)
Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, True)
End If
If oOcc.Definition.Type = kAssemblyComponentDefinitionObject Then
Call TraverseAssembly(oOcc.SubOccurrences, strFileName, intWorkplane, oSheet)
End If
Next
End Sub
Public Function FileNameFromPathExt(strFullPath As String) As String
FileNameFromPathExt = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "\"))
FileNameFromPathExt = Left(FileNameFromPathExt, InStrRev(FileNameFromPathExt, ".") - 1)
End Function
Did anyone have an idea?
Solved! Go to Solution.
