点击查看详细介绍

录制的代码和UI界面结合的时候报错

qiangli93 5月前 405 4

UG NX 二次开发(C、C#、WPF)技术交流群:641226372      UG二次开发(C、C#、WPF)


用操作记录录制的代码,在复制到新建项目的可以正常运行,和UI界面结合的时候有一行代码报错,麻烦指点一下

    Session *theSession = Session::GetSession();
    Part *workPart(theSession->Parts()->Work());
    Part *displayPart(theSession->Parts()->Display());

    std::vector<CAM::CAMObject *> objectsToBeBuffered1(1);
    UI *theUI = UI::GetUI();

    objectsToBeBuffered1[0] = dynamic_cast<CAM::NCGroup *>(theUI->SelectionManager()->GetSelectedObject(0));
    workPart->CAMSetup()->BufferObjects(CAM::CAMSetup::ViewProgramOrder,objectsToBeBuffered1);	//这一条代码报错 "an invalid tag was passed to the tag module"谷歌翻译是“无效的标签已传递到标签模块”
	

    std::vector<CAM::CAMObject *> objectsToBeMoved1(1);
    objectsToBeMoved1[0] = dynamic_cast<CAM::NCGroup *>(theUI->SelectionManager()->GetSelectedObject(0));
    std::vector<CAM::CAMObject *> newObjects1;
    newObjects1 = workPart->CAMSetup()->CopyObjects(CAM::CAMSetup::ViewProgramOrder, objectsToBeMoved1, dynamic_cast<CAM::NCGroup *>(theUI->SelectionManager()->GetSelectedObject(0)), CAM::CAMSetup::PasteAfter);
    

    std::vector<CAM::CAMObject *> objectsToBeMoved2(1);
    objectsToBeMoved2[0] = dynamic_cast<CAM::NCGroup *>(theUI->SelectionManager()->GetSelectedObject(0));
    CAM::NCGroup *nCGroup1(dynamic_cast<CAM::NCGroup *>(newObjects1[0]));
    std::vector<CAM::CAMObject *> newObjects2;
    newObjects2 = workPart->CAMSetup()->CopyObjects(CAM::CAMSetup::ViewProgramOrder, objectsToBeMoved2, nCGroup1, CAM::CAMSetup::PasteAfter);			



用下面的新建项目的代码可以达到预期的效果,但是复制到UI界面编辑器生成的代码中就报错

image.png

0

最新回复 (4)
  • Hu2008 5月前
    1

    你报错这行与UI界面有什么关系?

  • qiangli93 5月前
    2

    回复1楼(Hu2008):我就是不清楚为什么会有这种差异

  • Hu2008 5月前
    3

    录制的时候选择对象这些代码肯定不能用,结合你自己界面选择去获得选择的对象

  • qiangli93 5月前
    4

    回复3楼(Hu2008):可能是我太过新手了,生搬硬套的,感谢了

请登录后发表新帖