VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "Commands" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit ' Case lt_DocSheetStandart, lt_DocSheetUser, lt_DocFragment ' Set iObject2DNotify = iDoc2D.GetObject2DNotify(0) ' Set iSelMng2D = iDoc2D.GetSelectionMngNotify ' Case lt_DocPart3D, lt_DocAssemble3D ' Set iSelMng3D = iDoc3D.GetSelectionMng Public WithEvents iKompasObject As Kompas6API5.Application Attribute iKompasObject.VB_VarHelpID = -1 Public WithEvents iDoc2D As Kompas6API5.Document2D Attribute iDoc2D.VB_VarHelpID = -1 Public WithEvents iDoc3D As Kompas6API5.Document3D Attribute iDoc3D.VB_VarHelpID = -1 Public WithEvents iDocSpc As Kompas6API5.SpcDocument Attribute iDocSpc.VB_VarHelpID = -1 Public WithEvents iDocTxt As Kompas6API5.DocumentTxt Attribute iDocTxt.VB_VarHelpID = -1 Public WithEvents iObject2DNotify As Kompas6API5.Object2DNotify Attribute iObject2DNotify.VB_VarHelpID = -1 Public WithEvents iStamp As Kompas6API5.Stamp Attribute iStamp.VB_VarHelpID = -1 Public WithEvents iSelMng2D As Kompas6API5.SelectionMngNotify Attribute iSelMng2D.VB_VarHelpID = -1 Public WithEvents iSelMng3D As Kompas6API5.SelectionMng Attribute iSelMng3D.VB_VarHelpID = -1 Public WithEvents iSpcObjects As KompasAPI7.SpecificationBaseObjects Attribute iSpcObjects.VB_VarHelpID = -1 Public WithEvents iSpcObject As KompasAPI7.SpecificationObject Attribute iSpcObject.VB_VarHelpID = -1 Public WithEvents iSpcObjects1 As KompasAPI7.SpecificationBaseObjects Attribute iSpcObjects1.VB_VarHelpID = -1 Public WithEvents iSpcObject1 As KompasAPI7.SpecificationObject Attribute iSpcObject1.VB_VarHelpID = -1 Public libraryName As String ' Комманда 1 ' Команда без наворотов. Позволяет подписаться только на один документ ' определенного типа (2Д, 3Д, СП или текстовый). Если придет второй документ ' одного и тогоже типа команда его проигнорирует. Sub Command1() Dim flag As Boolean ' признак удачного завершения Dim newDoc As Object ' текущий документ Set newDoc = iKompasObject.ActiveDocument2D ' попробуем взять 2Д документ ' текущим является 2Д документ и мы еще на него не подписаны If Not newDoc Is Nothing And iDoc2D Is Nothing Then Set iDoc2D = newDoc ' подпишемся на его события Else ' текущий документ не 2Д Set newDoc = iKompasObject.ActiveDocument3D ' попробуем взять 3Д документ ' текущим является 3Д документ и мы еще на него не подписаны If Not newDoc Is Nothing And iDoc3D Is Nothing Then Set iDoc3D = newDoc ' подпишемся на его события Else ' текущий документ не 3Д Set newDoc = iKompasObject.SpcActiveDocument ' попробуем взять СП документ ' текущим является СП документ и мы еще на него не подписаны If Not newDoc Is Nothing And iDocSpc Is Nothing Then Set iDocSpc = newDoc ' подпишемся на его события Else ' текущий документ не СП Set newDoc = iKompasObject.ActiveDocumentTxt ' попробуем взять текстовый документ ' текущим является текстовый документ и мы еще на него не подписаны If Not newDoc Is Nothing And iDocTxt Is Nothing Then Set iDocTxt = newDoc ' подпишемся на его события End If End If End If End If Set newDoc = Nothing ' освободим текущий документ End Sub ' Комманда 2 ' Команда без наворотов. Позволяет отписаться только на документ определенного ' типа соответствующий текущему. Сами документы на соответствие не проверяются. Sub Command2() Dim newDoc As Object ' текущий документ Set newDoc = iKompasObject.ActiveDocument2D ' попробуем взять 2Д документ ' текущим является 2Д документ и мы на него подписаны If Not newDoc Is Nothing And Not iDoc2D Is Nothing Then Set iDoc2D = Nothing ' отпишемся от событий 2Д документа Else ' текущий документ не 2Д Set newDoc = iKompasObject.ActiveDocument3D ' попробуем взять 3Д документ ' текущим является 3Д документ и мы на него подписаны If Not newDoc Is Nothing And Not iDoc3D Is Nothing Then Set iDoc3D = newDoc ' отпишемся от событий 3Д документа Else ' текущий документ не 3Д Set newDoc = iKompasObject.SpcActiveDocument ' попробуем взять СП документ ' текущим является СП документ и мы на него подписаны If Not newDoc Is Nothing And Not iDocSpc Is Nothing Then Set iDocSpc = newDoc ' отпишемся от событий СП документа Else ' текущий документ не СП Set newDoc = iKompasObject.ActiveDocumentTxt ' попробуем взять текстовый документ ' текущим является текстовый документ и мы на него подписаны If Not newDoc Is Nothing And Not iDocTxt Is Nothing Then Set iDocTxt = newDoc ' отпишемся от событий текстового документа End If End If End If End If Set newDoc = Nothing ' освободим текущий документ End Sub ' Комманда 3 ' Позволяет подписаться на штамп текущего документа, если уже подписывались ' на штамп другого или этого же документа, то при подписки на новый штамп ' на старый произойдет отписка Sub Command3() Dim newDoc As Object ' текущий документ Set newDoc = iKompasObject.ActiveDocument2D ' попробуем взять 2Д документ If Not newDoc Is Nothing Then ' текущим является 2Д документ Dim doc2D As Kompas6API5.Document2D ' интерфейс 2Д документа Set doc2D = newDoc ' преобразование к 2Д документу Set iStamp = doc2D.GetStamp ' подписаться на события штампа Set doc2D = Nothing ' освободить документ Else ' текущий документ не 2Д Set newDoc = iKompasObject.SpcActiveDocument ' попробуем взять СП документ If Not newDoc Is Nothing Then ' текущим является СП документ Dim docSp As Kompas6API5.SpcDocument ' интерфейс СП документа Set docSp = newDoc ' преобразование к СП документу Set iStamp = docSp.GetStamp ' подписаться на события штампа Set docSp = Nothing ' освободить документ Else ' текущий документ не СП Set newDoc = iKompasObject.ActiveDocumentTxt ' попробуем взять текстовый документ If Not newDoc Is Nothing Then ' текущим является текстовый документ Dim Doc As Kompas6API5.DocumentTxt ' интерфейс текстового документа Set Doc = newDoc ' преобразование к текстовому документу Set iStamp = Doc.GetStamp ' подписаться на события штампа Set Doc = Nothing ' освободить документ End If End If End If Set newDoc = Nothing ' освободим текущий документ End Sub ' Комманда 4 ' Позволяет отписаться от событий штампа Sub Command4() If Not iStamp Is Nothing Then ' если была подписка на события штампа Set iStamp = Nothing ' отпишемся End If End Sub ' Комманда 5 Sub Command5() If iSpcObjects Is Nothing Then ' если была подписка на события базовых объектов Dim api7 As KompasAPI7.IApplication Set api7 = iKompasObject.ksGetApplication7 If Not api7 Is Nothing Then Dim Doc As KompasAPI7.KompasDocument Set Doc = api7.ActiveDocument If Not Doc Is Nothing Then Set iSpcObjects = Doc.SpecificationDescriptions.Active.BaseObjects End If End If End If End Sub ' Комманда 6 Sub Command6() If Not iSpcObjects Is Nothing Then ' если была подписка на события базовых объектов Set iSpcObjects = Nothing ' отпишемся End If End Sub ' Комманда 7 Sub Command7() If Not iSpcObjects Is Nothing And iSpcObjects.Count > 0 Then ' если была подписка на события базовых объектов Dim iSpcBaseObject As KompasAPI7.SpecificationBaseObject Set iSpcBaseObject = iSpcObjects(0) 'Dim docs As Variant 'Set docs = iSpcBaseObject.Documents Dim docs() As String docs = iSpcBaseObject.Documents Set iSpcObject = iSpcBaseObject End If End Sub ' Комманда 8 Sub Command8() If Not iSpcObject Is Nothing Then ' если была подписка на события базовых объектов Set iSpcObject = Nothing ' отпишемся End If End Sub ' Комманда 9 Sub Command9() If iSpcObjects1 Is Nothing Then ' если была подписка на события базовых объектов Dim api7 As KompasAPI7.IApplication Set api7 = iKompasObject.ksGetApplication7 If Not api7 Is Nothing Then Dim Doc As KompasAPI7.KompasDocument Set Doc = api7.ActiveDocument If Not Doc Is Nothing Then Set iSpcObjects1 = Doc.SpecificationDescriptions.Active.BaseObjects End If End If End If End Sub ' Комманда 10 Sub Command10() If Not iSpcObjects1 Is Nothing Then ' если была подписка на события базовых объектов Set iSpcObjects1 = Nothing ' отпишемся End If End Sub ' Комманда 11 Sub Command11() If Not iSpcObjects1 Is Nothing And iSpcObjects1.Count > 0 Then ' если была подписка на события базовых объектов Dim iSpcBaseObject As KompasAPI7.SpecificationBaseObject Set iSpcBaseObject = iSpcObjects1(0) 'Dim docs As Variant 'Set docs = iSpcBaseObject.Documents Dim docs() As String docs = iSpcBaseObject.Documents Set iSpcObject1 = iSpcBaseObject End If End Sub ' Комманда 12 Sub Command12() If Not iSpcObject1 Is Nothing Then ' если была подписка на события базовых объектов Set iSpcObject1 = Nothing ' отпишемся End If End Sub ' Комманда 13 Sub Command13() End Sub ' Комманда 14 Sub Command14() End Sub ' Комманда 15 Sub Command15() End Sub ' Комманда 16 Sub Command16() End Sub ' Комманда 17 Sub Command17() End Sub ' Комманда 18 Sub Command18() End Sub ' Комманда 19 Sub Command19() End Sub ' Комманда 20 Sub Command20() End Sub Private Sub Class_Initialize() libraryName = LoadResString(204) '"Использованиe математических функций" End Sub Private Sub Class_Terminate() Set iDoc2D = Nothing Set iObject2DNotify = Nothing Set iStamp = Nothing Set iSelMng2D = Nothing Set iSelMng3D = Nothing Set iDoc3D = Nothing Set iDocSpc = Nothing Set iDocTxt = Nothing Set iKompasObject = Nothing Set iSpcObjects = Nothing Set iSpcObject = Nothing End Sub Private Function iDoc2D_Activate() As Boolean iKompasObject.ksMessage libraryName & " Doc2D->Activate" iDoc2D_Activate = True End Function Private Function iDoc2D_BeginCloseDocument() As Boolean iKompasObject.ksMessage libraryName & " Doc2D->BeginCloseDocument" iDoc2D_BeginCloseDocument = True End Function Private Function iDoc2D_BeginSaveDocument(ByVal fileName As String) As Boolean iKompasObject.ksMessage libraryName & " Doc2D->BeginSaveDocument : " + fileName iDoc2D_BeginSaveDocument = True End Function Private Function iDoc2D_CloseDocument() As Boolean iKompasObject.ksMessage libraryName & " Doc2D->CloseDocument" Set iDoc2D = Nothing iDoc2D_CloseDocument = True End Function Private Function iDoc2D_Deactivate() As Boolean iKompasObject.ksMessage libraryName & " Doc2D->Deactivate" iDoc2D_Deactivate = True End Function Private Function iDoc2D_SaveDocument() As Boolean iKompasObject.ksMessage libraryName & " Doc2D->SaveDocument" iDoc2D_SaveDocument = True End Function Private Function iDoc3D_Activate() As Boolean iKompasObject.ksMessage libraryName & " Doc3D->Activate" iDoc3D_Activate = True End Function Private Function iDoc3D_BeginCloseDocument() As Boolean iKompasObject.ksMessage libraryName & " Doc3D->BeginCloseDocument" iDoc3D_BeginCloseDocument = True End Function Private Function iDoc3D_BeginSaveDocument(ByVal fileName As String) As Boolean iKompasObject.ksMessage libraryName & " Doc3D->BeginSaveDocument : " + fileName iDoc3D_BeginSaveDocument = True End Function Private Function iDoc3D_CloseDocument() As Boolean iKompasObject.ksMessage libraryName & " Doc3D->CloseDocument" Set iDoc3D = Nothing iDoc3D_CloseDocument = True End Function Private Function iDoc3D_Deactivate() As Boolean iKompasObject.ksMessage libraryName & " Doc3D->Deactivate" iDoc3D_Deactivate = True End Function Private Function iDoc3D_SaveDocument() As Boolean iKompasObject.ksMessage libraryName & " Doc3D->SaveDocument" iDoc3D_SaveDocument = True End Function Private Function iDocSpc_Activate() As Boolean iKompasObject.ksMessage libraryName & " DocSpc->Activate" iDocSpc_Activate = True End Function Private Function iDocSpc_BeginCloseDocument() As Boolean iKompasObject.ksMessage libraryName & " DocSpc->BeginCloseDocument" iDocSpc_BeginCloseDocument = True End Function Private Function iDocSpc_BeginSaveDocument(ByVal fileName As String) As Boolean iKompasObject.ksMessage libraryName & " DocSpc->BeginSaveDocument : " + fileName iDocSpc_BeginSaveDocument = True End Function Private Function iDocSpc_CloseDocument() As Boolean iKompasObject.ksMessage libraryName & " DocSpc->CloseDocument" Set iDocSpc = Nothing iSpcObjects = Nothing iSpcObject = Nothing iDocSpc_CloseDocument = True End Function Private Function iDocSpc_Deactivate() As Boolean iKompasObject.ksMessage libraryName & " DocSpc->Deactivate" iDocSpc_Deactivate = True End Function Private Function iDocSpc_SaveDocument() As Boolean iKompasObject.ksMessage libraryName & " DocSpc->SaveDocument" iDocSpc_SaveDocument = True End Function Private Function iDocTxt_Activate() As Boolean iKompasObject.ksMessage libraryName & " DocTxt->Activate" iDocTxt_Activate = True End Function Private Function iDocTxt_BeginCloseDocument() As Boolean iKompasObject.ksMessage libraryName & " DocTxt->BeginCloseDocument" iDocTxt_BeginCloseDocument = True End Function Private Function iDocTxt_BeginSaveDocument(ByVal fileName As String) As Boolean iKompasObject.ksMessage libraryName & " DocTxt->BeginSaveDocument : " + fileName iDocTxt_BeginSaveDocument = True End Function Private Function iDocTxt_CloseDocument() As Boolean iKompasObject.ksMessage libraryName & " DocTxt->CloseDocument" Set iDocTxt = Nothing iDocTxt_CloseDocument = True End Function Private Function iDocTxt_Deactivate() As Boolean iKompasObject.ksMessage libraryName & " DocTxt->Deactivate" iDocTxt_Deactivate = True End Function Private Function iDocTxt_SaveDocument() As Boolean iKompasObject.ksMessage libraryName & " DocTxt->SaveDocument" iDocTxt_SaveDocument = True End Function Private Function iKompasObject_ApplicationDestroy() As Boolean iKompasObject.ksMessage libraryName & " Application->ApplicationDestroy" Set iKompasObject = Nothing iKompasObject_ApplicationDestroy = True End Function Private Function iKompasObject_BeginOpenDocument(ByVal fileName As String) As Boolean 'iKompasObject.ksMessage libraryName & " Application->BeginOpenDocumen : " + fileName Dim res As Long res = iKompasObject.ksYesNo(libraryName & " Application->BeginOpenDocumen : " & fileName & "?") iKompasObject_BeginOpenDocument = Not (res = 0) 'True End Function Private Function iKompasObject_ChangeActiveDocument(ByVal newDoc As Object, ByVal docType As Long) As Boolean iKompasObject.ksMessage libraryName & " Application->ChangeActiveDocument" iKompasObject_ChangeActiveDocument = True End Function Private Function iKompasObject_CreateDocument(ByVal newDoc As Object, ByVal docType As Long) As Boolean ' Select Case docType ' ' Case lt_DocSheetStandart, lt_DocSheetUser, lt_DocFragment ' Set iDoc2D = newDoc ' Set iObject2DNotify = iDoc2D.GetObject2DNotify(0) ' Set iStamp = iDoc2D.GetStamp ' Set iSelMng2D = iDoc2D.GetSelectionMngNotify ' ' Case lt_DocPart3D, lt_DocAssemble3D ' Set iDoc3D = newDoc ' Set iSelMng3D = iDoc3D.GetSelectionMng ' ' Case lt_DocSpc, lt_DocSpcUser ' Set iDocSpc = newDoc ' ' Case lt_DocTxtStandart, lt_DocTxtUser ' Set iDocTxt = newDoc ' End Select iKompasObject.ksMessage libraryName & " Application->CreateDocument" iKompasObject_CreateDocument = True End Function Private Function iKompasObject_OpenDocument(ByVal newDoc As Object, ByVal docType As Long) As Boolean iKompasObject.ksMessage libraryName & " Application->OpenDocumen" ' Select Case docType ' ' Case lt_DocSheetStandart, lt_DocSheetUser, lt_DocFragment ' Set iDoc2D = newDoc ' Set iStamp = iDoc2D.GetStamp ' Set iSelMng2D = iDoc2D.GetSelectionMngNotify ' ' Case lt_DocPart3D, lt_DocAssemble3D ' Set iDoc3D = newDoc ' Set iSelMng3D = iDoc3D.GetSelectionMng ' ' Case lt_DocSpc, lt_DocSpcUser ' Set iDocSpc = newDoc ' ' Case lt_DocTxtStandart, lt_DocTxtUser ' Set iDocTxt = newDoc ' End Select iKompasObject_OpenDocument = True End Function Private Function iSelMng2D_Select(ByVal obj As Variant) As Boolean iKompasObject.ksMessage libraryName & " SelMng2D->Select" iSelMng2D_Select = True End Function Private Function iSelMng2D_Unselect(ByVal obj As Variant) As Boolean iKompasObject.ksMessage libraryName & " SelMng2D->Unselect" iSelMng2D_Unselect = True End Function Private Function iSelMng2D_UnselectAll() As Boolean iKompasObject.ksMessage libraryName & " SelMng2D->UnselectAll" iSelMng2D_UnselectAll = True End Function Private Function iSelMng3D_Select(ByVal obj As Variant) As Boolean iKompasObject.ksMessage libraryName & " SelMng3D->Select" Set obj = Nothing iSelMng3D_Select = True End Function Private Function iSelMng3D_Unselect(ByVal obj As Variant) As Boolean iKompasObject.ksMessage libraryName & " SelMng3D->Unselect" Set obj = Nothing iSelMng3D_Unselect = True End Function Private Function iSelMng3D_UnselectAll() As Boolean iKompasObject.ksMessage libraryName & " SelMng3D->UnselectAll" iSelMng3D_UnselectAll = True End Function Private Function iStamp_BeginEditStamp() As Boolean Dim res As Long res = iKompasObject.ksYesNo(libraryName & "Редактировать штамп?") iStamp_BeginEditStamp = Not (res = 0) End Function Private Function iStamp_EndEditStamp(ByVal editResult As Boolean) As Boolean Dim str As String If editResult Then str = " -> штамп отредактирован" Else str = " -> отказались от редактирования" End If iKompasObject.ksMessage libraryName & " Stamp->EndEditStamp" & str End Function Private Function iStamp_StampCellBeginEdit(ByVal number As Long) As Boolean Dim res As Long res = iKompasObject.ksYesNo(libraryName & "Редактировать ячейку с номером " & CStr(number) & "?") iStamp_StampCellBeginEdit = Not (res = 0) End Function Private Function iStamp_StampCellDblClick(ByVal number As Long) As Boolean Dim res As Long res = iKompasObject.ksYesNo(libraryName & "Редактировать по DBLCLICK'у ячейку с номером " & CStr(number) & "?") iStamp_StampCellDblClick = Not (res = 0) If number = 1 Then iStamp.ksOpenStamp Dim iDynamicArray As Kompas6API5.ksDynamicArray Dim iItemArray As Kompas6API5.ksDynamicArray Dim iTextLine As Kompas6API5.ksTextLineParam Dim iTextItem As Kompas6API5.ksTextItemParam Set iDynamicArray = iKompasObject.GetDynamicArray(TEXT_LINE_ARR) Set iTextLine = iKompasObject.GetParamStruct(ko_TextLineParam) iTextLine.Init Set iItemArray = iTextLine.GetTextItemArr Set iTextItem = iKompasObject.GetParamStruct(ko_TextItemParam) iTextItem.Init iTextItem.s = libraryName iItemArray.ksAddArrayItem -1, iTextItem iDynamicArray.ksAddArrayItem -1, iTextLine iStamp.ksSetStampColumnText number, iDynamicArray iItemArray.ksDeleteArray iDynamicArray.ksDeleteArray Set iDynamicArray = Nothing Set iItemArray = Nothing Set iTextLine = Nothing Set iTextItem = Nothing iStamp.ksCloseStamp End If End Function Private Function iSpcObjects_BeginDelete(ByVal obj As KompasAPI7.ISpecificationObject) As Boolean iKompasObject.ksMessage "iSpcObjects_BeginDelete" Dim res As Long res = iKompasObject.ksYesNo(libraryName & "Удалить объект?") iSpcObjects_BeginDelete = Not (res = 0) End Function Private Function iSpcObjects_CreateObject(ByVal obj As KompasAPI7.ISpecificationObject) As Boolean iKompasObject.ksMessage "iSpcObjects_CreateObject" End Function Private Function iSpcObject_BeginDelete(ByVal obj As KompasAPI7.ISpecificationObject) As Boolean iKompasObject.ksMessage "iSpcObject_BeginDelete" Dim res As Long res = iKompasObject.ksYesNo(libraryName & "Удалить объект?") iSpcObject_BeginDelete = Not (res = 0) If res = 1 Then Set iSpcObject = Nothing End If End Function Private Function iSpcObject_Delete(ByVal obj As KompasAPI7.ISpecificationObject) As Boolean iKompasObject.ksMessage "iSpcObject_Delete" Set iSpcObject = Nothing End Function Private Function iSpcObject_CreateObject(ByVal obj As KompasAPI7.ISpecificationObject) As Boolean iKompasObject.ksMessage "iSpcObject_CreateObject" End Function