www.mxdraw.com
内容索引主面
前一个向上下一个
_DMxDrawX::SendStringToExecuteFun 方法

把命令当着函数执行,可以传参数.

IDL
[id(188), helpstring("method SendStringToExecuteFun")]
VARIANT_BOOL SendStringToExecuteFun(BSTR sCmdName, IDispatch* pParam);
参数 
说明 
IDispatch* pParam 
命令参数,IMxDrawResbuf对象 
pszExecute 
命令名 

例如: VC 命令接受代码

            void CDrawCommand::Mirror()
            {
                struct resbuf* pRb = Mx::mcedGetArgs();
                McGePoint3d pt1;
                McGePoint3d pt2;
                bool isGetPoint = false;
                if(pRb != NULL && pRb->restype == McDb::kDxfXdXCoord)
                {
                    pt1 = asPnt3d(pRb->resval.rpoint);
                    pRb = pRb->rbnext;
                    if(pRb != NULL && pRb->restype == McDb::kDxfXdXCoord)
                    {
                        isGetPoint = true;
                        pt2 = asPnt3d(pRb->resval.rpoint);
                    }
                }

 

例如: 调用代码

                    IMxDawResbufPtr param;
                    param.CreateInstance(__uuidof( MxDrawResbuf ));

                    IMxDrawPointPtr pt;
                    pt.CreateInstance(__uuidof( MxDrawXLib::MxDrawPoint ));
                    pt->x = 10.0;
                    pt->y = 10.0;
                    param->AddPointEx(pt,1010);

                    pt->x = 10.0;
                    pt->y = 100.0;
                    param->AddPointEx(pt,1010);

                    m_ocx.SendStringToExecuteFun(_T("_Mirror"),param);

 

例如: 调用绘制样条线的代码

                void CTestVc2005Dlg::DrawSpline()
                {
                    IMxDrawResbufPtr param;
                    param.CreateInstance(__uuidof( MxDrawResbuf ));

                    m_ocx.SendStringToExecuteFun(_T("_DrawSpline"),param);

                    IDispatchPtr spDisp(m_ocx.GetEntitysLastCmd(),false);;

                    if(spDisp== NULL)
                        return;

                    IMxDrawResbufPtr spRet;
                    spDisp->QueryInterface(&spRet);


                    if(spRet->Count == 0)
                        return;

                    for(int i = 0; i < spRet->Count;i++)
                    {
                        IMxDrawMcDbObjectPtr spObj = spRet->AtObject(i);

                        IMxDrawSplinePtr spSpline;
                        spObj->QueryInterface(&spSpline);



                        if(spSpline != NULL)
                        {
                            IMxDrawPointsPtr spPoints;
                            long  degree = 3;
                            double fitTolerance = 0.01;
                            VARIANT_BOOL tangentsExist = VARIANT_FALSE;
                            IMxDrawVector3dPtr startTangent;
                            IMxDrawVector3dPtr endTangent; 

                            spSpline->GetFitData(&spPoints,&degree,&fitTolerance,&tangentsExist,&startTangent,&endTangent);

                            if(spPoints->Count > 0)
                            {
                                IMxDrawPointPtr frstPoint = spPoints->Item(0);
                                spPoints->Add2(frstPoint);

                                spSpline->SetFitData(spPoints,degree,fitTolerance,startTangent,endTangent);
                            }
                        }
                    }
                }

 

例如: C# 调用导角命令,并返回导角的圆弧对象.

            MxDrawEntity ent1 = (MxDrawEntity)axMxDrawX1.GetEntity("曲线1");
            if (ent1 == null)
                return;

            MxDrawEntity ent2 = (MxDrawEntity)axMxDrawX1.GetEntity("曲线2");
            if (ent2 == null)
                return;

            MxDrawResbuf param = new MxDrawResbuf();

            // 曲线1 id.
            param.AddObjectId(ent1.ObjectID);

            // 曲线2 id.
            param.AddObjectId(ent2.ObjectID);

            // 导角半径.
            param.AddDoubleEx(10, 5001);

            // 调用导角命令,
            axMxDrawX1.SendStringToExecuteFun("Mx_Fillet", param);

            MxDrawResbuf ret = (MxDrawResbuf)axMxDrawX1.Cal("Mx_GetRetArgs");
            if (ret.Count > 1)
            {
                // 导角成功.
                axMxDrawX1.TwinkeEnt(ret.AtObjectId(1));
        
            }

相应的C++代码.

        void CMxFillet::Do()
        {
            struct resbuf* pRb = Mx::mcedGetArgs();
            if(pRb != NULL
                && pRb->restype == RTId
                && pRb->rbnext != NULL
                && pRb->rbnext->restype == RTId
                && pRb->rbnext->rbnext != NULL
                && pRb->rbnext->rbnext->restype == RTREAL
                )
            {
                McDbObjectId id1;
                id1.setFromOldId(pRb->resval.objId );

                McDbObjectId id2;
                id2.setFromOldId(pRb->rbnext->resval.objId );

                if(id1 == id2)
                    return;

                double dR = pRb->rbnext->rbnext->resval.rreal;

                McDbObjectPointer<McDbCurve> spCurve1(id1,McDb::kForRead);
                if(spCurve1.openStatus() != Mcad::eOk)
                    return;

                double dParam = 0.0;
                spCurve1->getEndParam(dParam);

                McGePoint3d pt1;
                spCurve1->getPointAtParam(dParam / 2.0,pt1);

                McDbObjectPointer<McDbCurve> spCurve2(id2,McDb::kForRead);
                if(spCurve2.openStatus() != Mcad::eOk)
                    return;

                dParam = 0.0;
                spCurve2->getEndParam(dParam);

                McGePoint3d pt2;
                spCurve2->getPointAtParam(dParam / 2.0,pt2);

                s_dRadius = dR;
                spCurve1->close();
                spCurve2->close();

                McDbObjectId retId;
                DoFillet(id1,id2,pt1,pt2,retId);

                //
                if(!retId.isNull())
                {
                    struct resbuf* pRet = Mx::mcutNewRb(RTId);
                    pRet->resval.objId = retId.asOldId();

                    Mx::mcedSetRetArgs(pRet );
                }
                return;
            }

例如: C# 调用移命令.

                MxDrawResbuf param = new MxDrawResbuf();
                param.AddObjectId(axMxDrawX1.DrawBlockReference(point.x, point.y, "MyBlkName", 0.2, 0));
                param.AddObjectId( axMxDrawX1.DrawBlockReference(point2.x, point2.y, "MyBlkName", 0.2, 0));
                param.AddPoint(point);
                param.AddPoint(point2)
                axMxDrawX1.SendStringToExecuteFun("Move", param);

例如: C# 调用旋转命令.

       MxDrawResbuf param = new MxDrawResbuf();
     axMxDrawX1.SendStringToExecuteFun("_Rotation", param);

     MxDrawResbuf ret = (MxDrawResbuf)axMxDrawX1.Cal("Mx_GetRetArgs");
     if (ret.Count > 1)
     {
         // 旋转成功.
         MxDrawPoint pt = ret.AtPoint(1);
         double dAng = ret.AtDouble(2);
         String sTip = String.Format("pt:{0:f},{1:f},{2:f},Ang:{3:f}", pt.x, pt.y, pt.z, dAng);
         MessageBox.Show(sTip);

     }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!