[MSV8i C++]在线创建与放置共享单元

符老师   C#创建与放置共享单元太耗内存   想试试C++创建    但函数mdlSharedCell_create  中参数scOverride 、relativeMode 、assocOrigin 不是太明白,还有一个求问符老师怎么放置共享单元呢 ?

Parents
  • 符老师 

     //创建共享单元
    		 KIBODY *Spherebody;
    		 MSElementDescrP SphereEdp ,shareCellEdp,fangZhiCellEdp;
    		 MSElement  ShareCellSCElm,qiuEle;
    		 Transform Ts;
    		 RotMatrix rot;
    		 //画个球
    		 DPoint3d moveSpherept={100*g_1mu,-50*g_1mu,0};//单元设置的基点
    		 mdlKISolid_makeSphere(&Spherebody,5);
    		 mdlKISolid_bodyToElement (&SphereEdp, Spherebody, -1,-1, NULL, ACTIVEMODEL);
    		 mdlTMatrix_getIdentity (&Ts);
    		 mdlTMatrix_setTranslation (&Ts,&moveSpherept);
    		 mdlElmdscr_transform(SphereEdp,&Ts);//平移实体
    		 mdlRMatrix_getIdentity(&rot); 
    		 DPoint3d scalPt ={1,1,1};//单元放大的倍数
    		 char cellName[MAX_TableNameLength] = "zhuxu";//单元名字
    		 MSWChar wCellname[MAX_TableNameLength];
    		 mdlCnv_convertMultibyteToUnicode(cellName,-1,wCellname,sizeof(wCellname));
    		 qiuEle = SphereEdp->el;
    		 mdlKISolid_beginCurrTrans(ACTIVEMODEL);
    		 int state = mdlSharedCell_create(&ShareCellSCElm,&(qiuEle),&moveSpherept,&rot,&scalPt,wCellname,NULL,0,0,NULL);
    		 mdlKISolid_endCurrTrans();
    		 mdlElmdscr_new(&shareCellEdp,NULL,&ShareCellSCElm);
    		 mdlElmdscr_add(shareCellEdp);
    		 mdlElmdscr_freeAll(&shareCellEdp);
    图形就是没创建出来  但是这里显示有  求符老师解答

  • 您调用的这个mdlSharedCell_create是需要您首先连接了单元库,然后直接从单元库中根据单元名取得一个共享单元的。

    如果你连接了系统的Sample2.cel,如下代码可以工作:

        MSElement cell;
        mdlSharedCell_create (&cell, NULL, NULL, NULL, &scale, L"ARRO", NULL, FALSE, 0, NULL);
        if (SUCCESS != mdlSharedCell_makeSureDefExists (&cell))
        {
            mdlDialog_openAlert ("可能没有连接单元库Sample2.cell");
            return;
        }
        mdlSharedCell_setRange (&cell, ACTIVEMODEL);
        mdlElement_add (&cell);

    请注意,共享单元是一个简单元素,用MSElement即可表达。mdlCell_attachLibrary函数可以用来连接单元库。

    mdlSharedCell_makeSureDefExists能确认共享单元定义(SharedCellDefinition)是否已经添加到当前DGN中,SharedCellDefinition元素是复杂元素,要用MSElementDescr表达。



  • 符老师  没有像C#(CreateSharedCellElement1 数量多太耗内存)那样的在dgn创建一个sharedcell    不用连接库

  • 也有,那就是mdlSharedCell_addToFile,调用该函数前需要你创建一个SharedCell Definition元素。



  • 今天抽空为您写了如下例子,请参考:

    void createSharedCellOnTheFly ()
    {
    	MSElement           sharedCell;
    	DPoint3d            scale = {1.0, 1.0, 1.0}, org = {10000, 10000, 0};
    	MSWCharP            wCellName = L"My-SharedCell";
    	mdlSharedCell_create (&sharedCell, NULL, &org, NULL, &scale, wCellName, NULL, FALSE, 0, NULL);
        if (SUCCESS != mdlSharedCell_makeSureDefExists (&sharedCell))
        {
    		MSElement           el;
            MSElementDescrP     edP = NULL;
    		mdlSharedCell_createDefinitionElement (&el, wCellName, FALSE);
            mdlElmdscr_new (&edP, NULL, &el);
    		mdlEllipse_create (&el, NULL, NULL, 1000, 1000, NULL, -1);
    		mdlElmdscr_appendElement (edP, &el);
    		mdlSharedCell_setOriginAndRange (edP, NULL);
    		mdlSharedCell_addDefinitionElements (edP, NULL,NULL);
            mdlElmdscr_freeAll (&edP);
        }
    	mdlSharedCell_setRange (&sharedCell, ACTIVEMODEL);
        mdlElement_add (&sharedCell);
    }



    MISSING RESOURCE: VerifiedBy Andy 

Reply
  • 今天抽空为您写了如下例子,请参考:

    void createSharedCellOnTheFly ()
    {
    	MSElement           sharedCell;
    	DPoint3d            scale = {1.0, 1.0, 1.0}, org = {10000, 10000, 0};
    	MSWCharP            wCellName = L"My-SharedCell";
    	mdlSharedCell_create (&sharedCell, NULL, &org, NULL, &scale, wCellName, NULL, FALSE, 0, NULL);
        if (SUCCESS != mdlSharedCell_makeSureDefExists (&sharedCell))
        {
    		MSElement           el;
            MSElementDescrP     edP = NULL;
    		mdlSharedCell_createDefinitionElement (&el, wCellName, FALSE);
            mdlElmdscr_new (&edP, NULL, &el);
    		mdlEllipse_create (&el, NULL, NULL, 1000, 1000, NULL, -1);
    		mdlElmdscr_appendElement (edP, &el);
    		mdlSharedCell_setOriginAndRange (edP, NULL);
    		mdlSharedCell_addDefinitionElements (edP, NULL,NULL);
            mdlElmdscr_freeAll (&edP);
        }
    	mdlSharedCell_setRange (&sharedCell, ACTIVEMODEL);
        mdlElement_add (&sharedCell);
    }



    MISSING RESOURCE: VerifiedBy Andy 

Children