UG爱好者
标题:
prt打不开这是我用nxopen导入stp形成的prt
[打印本页]
作者:
429570094
时间:
2017-10-25 09:43
标题:
prt打不开这是我用nxopen导入stp形成的prt
file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\429570094\QQ\WinTemp\RichOle\E6SGE6ICVUU7M~8HXXQQY(0.png这是为啥,prt打不开这是我用nxopen导入stp形成的prt
/***
** VayoDFM2UG_prt.cpp
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <uf_part.h>
#include <io.h>
#include <string.h>
#include <string>
#include <locale.h>
#include <stdlib.h>
#include <fstream>
#include <stdafx.h>
#include <uf_modl.h>
#include "uf_weight.h"
#include <uf_attr.h>
#include<uf_obj.h>
#include<UF_ASSEM.h>
#include "Step214Importer.hxx"
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/BasePart.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/DexManager.hxx>
#include <NXOpen/FileNew.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/ObjectTypeSelector.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/PartCloseResponses.hxx>
#include <NXOpen/PDM_PartFromTemplateBuilder.hxx>
#include <NXOpen/PDM_PartManager.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Step214Importer.hxx>
using namespace NXOpen;
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
using namespace std;
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
CStringArray* SplitLine(CString source, CString division)
{
CString csflag;
CStringArray* dest = new CStringArray() ;
OutputDebugString(source);
OutputDebugString(L"\n");
dest->RemoveAll();
int pos = 0;
int pre_pos = 0;
int iCount_1=0;
CString Temp;
while( -1 != pos ){
int temp1=0;
int temp2=0;
iCount_1++;
pre_pos = pos;
pos = source.Find(division,(pos+1));
if(pos == -1){
if(iCount_1 == 1){
// temp1=source.GetLength()-pre_pos;
//temp2=pre_pos;
// csflag.Format(L"%d",temp1);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
//csflag.Format(L"%d",temp2);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
Temp=source.Mid(pre_pos,source.GetLength()-pre_pos);
}
else{
// temp1=source.GetLength()-(pre_pos+1);
// temp2=pre_pos+1;
// csflag.Format(L"%d",temp1);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
//csflag.Format(L"%d",temp2);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
Temp=source.Mid(pre_pos+1,source.GetLength()-(pre_pos+1));
}
}else{
if(iCount_1 == 1){
// temp1=pos-(pre_pos);
// temp2=pre_pos;
// csflag.Format(L"%d",temp1);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
//csflag.Format(L"%d",temp2);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
Temp=source.Mid(pre_pos,(pos-(pre_pos)));
}
else{
// temp1=pos-(pre_pos+1);
// temp2=pre_pos+1;
// csflag.Format(L"%d",temp1);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
//csflag.Format(L"%d",temp2);
// OutputDebugString(csflag);
//OutputDebugString(L"\n");
Temp=source.Mid(pre_pos+1,(pos-(pre_pos+1)));
}
}
int compareid=wcscmp(Temp.GetBuffer(), L"");
if(compareid != 0){
dest->Add(Temp);
}
Temp.ReleaseBuffer();
//AfxMessageBox(Temp);
}
return dest;
}
/////////////////////////////////////////////////////////////////////////////////////////
// 将Char型字符转换为Unicode字符
int CharToUnicode(char *pchIn, CString *pstrOut)
{
int nLen;
WCHAR *ptch;
if(pchIn == NULL)
{
return 0;
}
nLen = MultiByteToWideChar(CP_ACP, 0, pchIn, -1, NULL, 0);
ptch = new WCHAR[nLen];
MultiByteToWideChar(CP_ACP, 0, pchIn, -1, ptch, nLen);
pstrOut->Format(_T("%s"), ptch);
delete [] ptch;
return nLen;
}
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* Unigraphics Startup
** This entry point activates the application at Unigraphics startup */
extern DllExport void ufsta( char *param, int *returnCode, int rlen )
{
/* Initialize the API environment */
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
CString strText;
CString szLine; //存储行字符串
CStdioFile file;
CString file_path;//list文件路径
CStringArray *destArray;//全局数组,参数名
CStringArray *OutputArrayFile;//文件读入数组
//ProError Error;
TCHAR strPath_temp[MAX_PATH];
OutputDebugString(strPath_temp);
////////////////////test use
//////////////EXE路径
//CString path=AfxGetApp()->m_pszHelpFilePath;
//CString str=AfxGetApp()->m_pszExeName;
//path=path.Left(path.GetLength()-str.GetLength()-4);
CString inipath;
CString PropList;
CString PropLIB;
//inipath=path+ L"\config.ini";
inipath="D:\\UG\\UGII\\config.ini";
//AfxMessageBox(inipath);
OutputDebugString(inipath);
OutputDebugString(L"\n");
GetPrivateProfileString(L"ProE_Parameter",L"PropList",L"Default",PropList.GetBuffer(MAX_PATH),MAX_PATH,inipath);
GetPrivateProfileString(L"ProE_Parameter",L"LIB",L"Default",PropLIB.GetBuffer(MAX_PATH),MAX_PATH,inipath);
bool flag = CreateDirectory(PropLIB, NULL);
OutputDebugString(PropLIB);
OutputDebugString(L"\n");
char temps1[99999];
sprintf(temps1,"%S",PropLIB);
if(_access(temps1, 00)==0)
{
OutputDebugString(L"LIB has created\n");
}else{
flag = CreateDirectory(PropLIB, NULL);
if(flag)
{
}
else{
PropLIB="C:\\LIB";
OutputDebugString(L"LIB has created C:\\LIB\n");
}
flag = CreateDirectory(PropLIB, NULL);
}
//AfxMessageBox(PropList);
destArray=SplitLine(PropList.GetBuffer(PropList.GetLength()),L",");//ini文件解析
PropList.ReleaseBuffer();
destArray->InsertAt(0,L"STEP_NAME");
destArray->InsertAt(0,L"PART_RENAME");
destArray->InsertAt(0,L"PART_NAME");
CString t;
t.Format(L"%d",destArray->GetCount());
OutputDebugString(L"destArray: Count->");
OutputDebugString(t);
OutputDebugString(L"\n");
for (int n = 0; n < destArray->GetCount(); n ++)
{
CString t;
t.Format(L"%s",(*destArray)[n]);
OutputDebugString(t);
OutputDebugString(L"\n");
}
///////////////////////////////////////////////////
GetTempPath(MAX_PATH, strPath_temp);
file_path.Format(L"%s\\proe\\list.txt",strPath_temp);
//MessageBox(file_path);
//Error=ProDirectoryCurrentGet(pro_path);
//Error=ProDirectoryChange(PropLIB.GetBuffer());
//PropLIB.ReleaseBuffer();
// if( Error != PRO_TK_NO_ERROR )
// {
// AfxMessageBox(L"ProDirectoryChange error: 可能PROE未启动 ");
// return;
// }
///////////////////
try
{
CFile file(file_path, CFile::modeRead);
char* buf = NULL;
DWORD dwLen = (DWORD)file.GetLength();
buf = new char[dwLen + 1];
memset(buf, 0, dwLen + 1);
file.Read(buf, dwLen);
file.Close();
CString str(buf);
delete[] buf;
buf = NULL;
//AfxMessageBox(str);
OutputArrayFile=SplitLine(str,L"\r");
CString t;
t.Format(L"FileLineCount: %d",OutputArrayFile->GetCount());
OutputDebugString(t);
OutputDebugString(L"|end\n");
}
catch (CException* e)
{
e->ReportError();
e->Delete();
}
/////////////////////
//file.Open(file_path,CFile::modeRead);//打开文件
//逐行读取字符串
QQ图片20171025094023.png
(260.71 KB, 下载次数: 58)
下载附件
2017-10-25 09:40 上传
作者:
429570094
时间:
2017-10-25 09:45
for (int i1 = 0; i1 < OutputArrayFile->GetCount(); i1 ++)
{
szLine=(*OutputArrayFile)[i1].GetBuffer();
CStringArray *OutputArrayLine;
CString file_path_step;
//最后一个带回车
szLine.Replace(L"\n",L"");
CString t;
OutputDebugString(L"start|");
OutputDebugString(szLine);
OutputDebugString(L"|end\n");
////////////////////////行分隔
OutputArrayLine=SplitLine(szLine,L"\t");
szLine.ReleaseBuffer();
int n = OutputArrayLine->GetCount();
if(n ==0){
//行结束退出
OutputDebugString(L"Skip blank line.\n");
//return;
}else{
//////////////////////
char prt_name[256];
char file_path_stepW[260];
double m_mass;
char mass_temps[256];
//ProName w_name;
//ProPath input_file;
//ProMdl model;
//int w_id;
//ProMassProperty mass_prop;
double mass_value;
double mass_density;
//////////////////////
t.Format(L"modelname: %s",(*OutputArrayLine)[0].GetBuffer());
OutputDebugString(t);
OutputDebugString(L"|end\n");
file_path_step.Format(L"%s\\ProE\\%s",strPath_temp,(*OutputArrayLine)[2].GetBuffer());
sprintf(file_path_stepW,"%S",file_path_step);
CString prt_name_temp;
prt_name_temp.Format(L"%s\\ProE\\%s",strPath_temp,(*OutputArrayLine)[1].GetBuffer());
//prt_name_temp=(*OutputArrayLine)[1].GetBuffer();
sprintf(prt_name,"%S",prt_name_temp);
sprintf(mass_temps, "%S", (*OutputArrayLine)[3].GetBuffer());
m_mass=atof(mass_temps);
if(m_mass == 0){//赋默认质量1mg
m_mass=1;
}
Session *theSession = Session::GetSession();
// ----------------------------------------------
// Menu: File->New...
// ----------------------------------------------
//Session::UndoMarkId markId1;
// markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
FileNew *fileNew1;
fileNew1 = theSession->Parts()->FileNew();
//theSession->SetUndoMarkName(markId1, NXString("##84New \345\257\271\350\257\235\346\241\206", NXString::UTF8));
//Session::UndoMarkId markId2;
//markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "##84New");
theSession->SetUndoMark(Session::MarkVisibilityInvisible, "##84New");
fileNew1->SetTemplateFileName("model-plain-1-mm-template.prt");
fileNew1->SetApplication(FileNewApplicationModeling);
fileNew1->SetUnits(Part::UnitsMillimeters);
fileNew1->SetTemplateType(FileNewTemplateTypeItem);
fileNew1->SetNewFileName(prt_name);
fileNew1->SetMasterFileName("");
fileNew1->SetUseBlankTemplate(false);
fileNew1->SetMakeDisplayedPart(true);
NXObject *nXObject1;
nXObject1 = fileNew1->Commit();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
// theSession->DeleteUndoMark(markId2, NULL);
fileNew1->Destroy();
//Session::UndoMarkId markId3;
//markId3 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Enter Modeling");
theSession->SetUndoMark(Session::MarkVisibilityVisible, "Enter Modeling");
// ----------------------------------------------
// Menu: File->Import->STEP214...
// ----------------------------------------------
// Session::UndoMarkId markId4;
// markId4 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
Step214Importer *step214Importer1;
step214Importer1 = theSession->DexManager()->CreateStep214Importer();
step214Importer1->SetSimplifyGeometry(true);
step214Importer1->SetLayerDefault(1);
step214Importer1->SetInputFile(file_path_stepW);
step214Importer1->SetSettingsFile("D:\\UG\\step214ug\\step214ug.def");
step214Importer1->ObjectTypes()->SetSolids(true);
step214Importer1->SetFlattenAssembly(true);
step214Importer1->SetOutputFile("D:\\UG\\UGII\\ug-open2-test\\ug--data\\2.prt");
step214Importer1->SetInputFile("");
step214Importer1->SetOutputFile("");
//theSession->SetUndoMarkName(markId4, NXString("Import from STEP214 Options \345\257\271\350\257\235\346\241\206", NXString::UTF8));
step214Importer1->SetInputFile(file_path_stepW);
step214Importer1->SetOutputFile(prt_name);
//Session::UndoMarkId markId5;
//markId5 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Import from STEP214 Options");
theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Import from STEP214 Options");
step214Importer1->SetFileOpenFlag(false);
NXObject *nXObject2;
nXObject2 = step214Importer1->Commit();
//theSession->DeleteUndoMark(markId5, NULL);
//theSession->SetUndoMarkName(markId4, "Import from STEP214 Options");
step214Importer1->Destroy();
if(_access(file_path_stepW, 00)==0)//判断文件是否存在
{
for (int i = 0; i < n; i ++)
{
/////debug
t.Format(L"%d",i);
OutputDebugString(t);
OutputDebugString(L"-->");
/////debug end
int temp_i=i;
CString ProParaName;
//ProModelitem modelitem;
//ProParamvalue proval;
//ProParameter param;
//ProName Pro_PARA_NAME;
//wchar_t TempProName[PRO_VALUE_SIZE];
int compareid;
char ssa[255]; //属性标题
char sva[255];
//char ProParaName_char[PRO_FEATREF_KEY_SIZE];
//char ProParaValue_char[PRO_VALUE_SIZE];
if(destArray->GetCount() < i+1){
CString t;
t.Format(L"INPUT_%d",i);
sprintf(ssa,"%S",t);
//AfxMessageBox(t);
//////////////////////////debug
OutputDebugString(t);
OutputDebugString(L"->");
t.Format(L"%s",(*OutputArrayLine)[temp_i].GetBuffer());
OutputDebugString(t);
OutputDebugString(L"|end\n");
//////////////////////////debug end
}
else{
sprintf(ssa,"%S",(*destArray)[i].GetBuffer());
//////////////////////////debug
//char ssa[255]; //属性标题
//char sva[255];
CString t;
t.Format(L"%s",(*destArray)[i].GetBuffer());
//sprintf(ssa,"%S",t);
OutputDebugString(t);
OutputDebugString(L"->");
t.Format(L"%s",(*OutputArrayLine)[temp_i].GetBuffer());
OutputDebugString(t);
OutputDebugString(L"|end\n");
//sprintf(sva,"%S",t);
//写入属性
//////////////////////////debug end
//AfxMessageBox(destArray[i]);
}
sprintf(sva,"%S",(*OutputArrayLine)[temp_i].GetBuffer());
// AfxMessageBox(temp);
//*
/////////////////////////写入参数质量
compareid=wcscmp((*OutputArrayLine)[temp_i].GetBuffer(), L"-1");
if(compareid != 0){
compareid=wcscmp((*OutputArrayLine)[temp_i].GetBuffer(), L"");
}
if(compareid != 0){
tag_t workpart;
workpart=UF_ASSEM_ask_work_part();
// char ssa[255]="质量"; //属性标题
//char sva[255]="55"; //属性值
UF_ATTR_value_t attr_va;
attr_va.type=UF_ATTR_string; //属性类型 字符串
attr_va.value.string=sva;
UF_ATTR_assign(workpart,ssa,attr_va);
// ----------------------------------------------
// Menu: File->Save
// ----------------------------------------------
//Session::UndoMarkId markId9;
//markId9 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
}
(*OutputArrayLine)[temp_i].ReleaseBuffer();
}
theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
// theSession->SetUndoMarkName(markId9, NXString("Name Parts \345\257\271\350\257\235\346\241\206", NXString::UTF8));
//Session::UndoMarkId markId10;
//markId10 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Name Parts");
theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Name Parts");
workPart->AssignPermanentName(prt_name);
// theSession->DeleteUndoMark(markId10, NULL);
// theSession->SetUndoMarkName(markId9, "Name Parts");
PartSaveStatus *partSaveStatus1;
partSaveStatus1 = workPart->Save(BasePart::SaveComponentsTrue, BasePart::CloseAfterSaveFalse);
delete partSaveStatus1;
PartCloseResponses *partCloseResponses1;
partCloseResponses1 = theSession->Parts()->NewPartCloseResponses();
workPart->Close(BasePart::CloseWholeTreeFalse, BasePart::CloseModifiedUseResponses, partCloseResponses1);
workPart = NULL;
displayPart = NULL;
delete partCloseResponses1;
}//if存在file_path_stepW
else{
CString Mes_file_path_step;
Mes_file_path_step.Format(L"Missing file: %s",file_path_step);
AfxMessageBox(file_path_step);
//return;
}
}//skip blank
delete OutputArrayLine;
}//for i
delete destArray;
delete OutputArrayFile;
UF_CALL(UF_terminate());
}
extern int ufusr_ask_unload (void)
{
/* 设置UF程序运行以后立刻从内存中卸除,即当重新修改、编译成新的DLL文件时,UG无须关闭重启动,就可调用此新的*.DLL文件 */
return (UF_UNLOAD_IMMEDIATELY);
}
作者:
lizhaoyong*
时间:
2017-10-26 08:12
表示看不懂
作者:
难人*
时间:
2018-9-2 15:20
具体问的什么问题?表示没看懂
作者:
123.321123
时间:
2018-12-15 10:50
看着很厉害的样子
作者:
123.321123
时间:
2018-12-15 10:51
看着很厉害的样子
作者:
123.321123
时间:
2018-12-15 11:22
具体问的什么问题?表示没看懂
作者:
小小小小星星
时间:
2018-12-19 12:46
修复下 看看
欢迎光临 UG爱好者 (https://www.ugsnx.com/)
Powered by Discuz! X3.2