调整命令处理程序以进行同步涉及对命令的 AutoCAD 注册及其执行代码的更改。 更新特性选项板同步的命令处理程序
acedRegCmds->addCommand("SQUARE_COMMANDS", "ASDKADDSQUARE", "ADDSQ", ACRX_CMD_MODAL | ACRX_CMD_INTERRUPTIBLE, addSquare); 在已注册的 AutoCAD 命令的处理程序代码中,调用全局函数。此调用应在命令提示用户输入之前发生。acedSetIUnknownForCurrentCommand() 在出现提示的位置,轮询所有输入函数以获取返回值。RTMODELESS 返回 ifis,放弃当前输入请求并继续执行下一个命令步骤。此调用在同步的命令处理程序中进行。RTMODELESS 在调用该函数之前,必须创建 COM 对象包装器和 COM 命令包装器的实例,然后通过连接点将两者关联。如果要将对象添加到 ,则通过调用 COM 对象包装器的函数实现来创建底层对象。使用返回的指针,可以调用 COM 包装器的函数实现。acedSetIUnknownForCurrentCommand()AcDbDatabaseAcDbEntityIAcadBaseObject2Impl::CreateObject()IAcadBaseObject2::AddToDb() 以下是来自com\AsdkSquareWrapper_dg\Square\squareui.cpp的命令处理程序函数:addSquare() void addSquare() { CComPtr<IAsdkSquareWrapper> pSquare; CComQIPtr<IAcadBaseObject2> pSquareBase; CComQIPtr<IConnectionPointContainer> pConnectionPts; CComPtr<IConnectionPoint> pConnection; CComObject<CAsdkSquareCmd> *pSquareCmdObj; CComPtr<IUnknown> pSquareCmd; DWORD connectionId = 0; HRESULT hr = S_OK; try { // Create the wrapper object which we will place into OPM // to display the square's properties if (FAILED(hr = pSquare.CoCreateInstance(CLSID_AsdkSquareWrapper))) throw hr; pSquareBase = pSquare; // Create the underlying square object if (FAILED(hr = pSquareBase->CreateObject())) throw hr; // Create the square modification listener which we use to // synchronize changes in OPM and the command line if (FAILED(hr = CComObject<CAsdkSquareCmd>::CreateInstance( &pSquareCmdObj))) throw hr; pSquareCmdObj->QueryInterface(IID_IUnknown, (void **)&pSquareCmd); // Attach the square modification listener to the wrapper pConnectionPts = pSquare; if (!pConnectionPts) throw E_POINTER; if (FAILED(hr = pConnectionPts->FindConnectionPoint (IID_IPropertyNotifySink, &pConnection))) throw hr; if (FAILED(hr = pConnection->Advise(pSquareCmd, &connectionId))) throw hr; } catch (HRESULT) { acutPrintf("\n Error initializing command."); return; } // Set the square object up for OPM acedSetIUnknownForCurrentCommand(pSquare); // Now process the command line input by // looping for all required parameters ads_point pt0, pt1; ads_real size = 0.0; struct resbuf UCS, WCS; int retval; WCS.restype = RTSHORT; WCS.resval.rint = 0; UCS.restype = RTSHORT; UCS.resval.rint = 1; while (true) { if (!pSquareCmdObj->GotCenterPoint()) { retval = acedGetPoint(NULL, "\nPick a point for the center: ", pt0); if (retval == RTCAN) break; else if (retval != RTNORM) continue; acedTrans(pt0, &UCS, &WCS, 0, pt1); AcAxPoint3d pnt3d(pt1[X], pt1[Y], pt1[Z]); pSquare->put_CenterPoint(*(pnt3d.asVariantPtr())); } if (!pSquareCmdObj->GotSquareSize()) { retval = acedGetDist(pt0, "\nPick the square size : ", &size); if (retval == RTCAN) break; else if (retval != RTNORM) continue; pSquare->put_SquareSize(size); } AcDbObjectId squareId; if (FAILED(hr = pSquareBase->AddToDb(squareId, curDoc()->database()->currentSpaceId()))) { acutPrintf("\n Error appending object to database."); break; } break; } // Unadvise the square modified listener pConnection->Unadvise(connectionId); return; } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:41
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.