# -*- coding: utf-8 -*-
#|L_Request2D

import pythoncom
from win32com.client import Dispatch, gencache

import LDefin2D
import MiscellaneousHelpers as MH

#  Подключим константы API Компас
const_2d = gencache.EnsureModule("{75C9F5D0-B5B8-4526-8681-9903C567D2ED}", 0, 1, 0).constants
const_3d = gencache.EnsureModule("{2CAF168C-7961-4B90-9DA2-701419BEEFE3}", 0, 1, 0).constants

#  Подключим описание интерфейсов API5
kapi_5 = gencache.EnsureModule("{0422828C-F174-495E-AC5D-D31014DBBE87}", 0, 1, 0)
iKompas_5 = kapi_5.KompasObject(Dispatch("Kompas.Application.5")._oleobj_.QueryInterface(kapi_5.KompasObject.CLSID, pythoncom.IID_IDispatch))
MH.iKompasObject = iKompas_5

#  Подключим описание интерфейсов API7
kapi_7 = gencache.EnsureModule("{69AC2981-37C0-4379-84FD-5DD2F3C0A520}", 0, 1, 0)
iApplication_7 = kapi_7.IApplication(Dispatch("Kompas.Application.7")._oleobj_.QueryInterface(kapi_7.IApplication.CLSID, pythoncom.IID_IDispatch))
MH.iApplication = iApplication_7


iDocuments_7 = iApplication_7.Documents
#  Получим активный документ
iDocument_7 = iApplication_7.ActiveDocument
iDocument2D_7 = kapi_7.IKompasDocument2D(iDocument_7)
iDocument2D_5 = iKompas_5.ActiveDocument2D()

# Запрос позиции размещения и угла поворота объекта с фантомным изображением
iVr1 = 0
iVr2 = 0
iVr3 = 0

iRequestInfo_5 = kapi_5.ksRequestInfo(iKompas_5.GetParamStruct(const_2d.ko_RequestInfo))
iRequestInfo_5.Init()
iRequestInfo_5.prompt = "Укажите точку"

iPhantom_5 = kapi_5.ksPhantom(iKompas_5.GetParamStruct(const_2d.ko_Phantom))
iPhantom_5.Init()
iPhantom_5.phantom = 1

iPhantomParam_5 = iPhantom_5.GetPhantomParam()
iPhantomParam_5.Init()
iPhantomParam_5.xBase = 0
iPhantomParam_5.yBase = 0

iPhantomParam_5.gr = iDocument2D_5.ksNewGroup(1)

iRectangleParam_5 = kapi_5.ksRectangleParam(iKompas_5.GetParamStruct(const_2d.ko_RectangleParam))
iRectangleParam_5.Init()
iRectangleParam_5.x = 0
iRectangleParam_5.y = 0
iRectangleParam_5.ang = 0
iRectangleParam_5.height = 50
iRectangleParam_5.width = 100
iRectangleParam_5.style = 1
obj_5 = iDocument2D_5.ksRectangle(iRectangleParam_5)

iDocument2D_5.ksEndGroup()

iRet = iDocument2D_5.ksPlacement(iRequestInfo_5, iVr1, iVr2, iVr3, iPhantom_5)

if iRet[0] == -1:
    iDocument2D_5.ksMoveObj(iPhantomParam_5.gr, iRet[1], iRet[2])
    iDocument2D_5.ksRotateObj(iPhantomParam_5.gr, iRet[1], iRet[2], iRet[3])
    iDocument2D_5.ksStoreTmpGroup(iPhantomParam_5.gr)

iDocument2D_5.ksClearGroup(iPhantomParam_5.gr, True)
iDocument2D_5.ksDeleteObj(iPhantomParam_5.gr)








