|
板凳

楼主 |
发表于 2023-12-27 16:34:19
|
只看该作者
经典图书 这个也是有问题
Sub AssociateDrawingWithPart()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swModelView As SldWorks.ModelView
Dim bIsFound As Boolean
Dim strDrawingName As String
Dim strPartName As String
Dim strDrawingPath As String
Dim strPartPath As String
Dim strAssociateName As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDrawing = swApp.GetDrawing2(swModel.FileName)
Set swModelView = swDrawing.GetModelView2(swModel.FileName)
strDrawingName = Left(swDrawing.FileName, Len(swDrawing.FileName) - 5) ' Remove extension '.slddrw'
strPartName = Left(swModel.FileName, Len(swModel.FileName) - 5) ' Remove extension '.sldprt'
strDrawingPath = swDrawing.GetPathName
strPartPath = swModel.GetPathName
strAssociateName = "Assembly" ' This can be any name you want to use to represent the assembly in the drawing view.
' Check if drawing and part have the same name (ignoring extension)
If strDrawingName = strPartName Then
bIsFound = True
swModelView.ClearAllAssociativeRelations
swModelView.AddAssociativeRelation2 swModel, , , , , , , , , strAssociateName, , , , , , , , True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False
End If
End Sub |
|