几何尺寸与公差论坛

 找回密码
 注册
查看: 834|回复: 0

【转帖】strange insertpart2

[复制链接]
发表于 2009-4-13 14:40:39 | 显示全部楼层 |阅读模式
strange "insertpart2"
dear all,
i got a strange problem when developing an add-in for solidworks 2008. the add-in process is:
1. create empty part document
2. insert a part using "insertpart2" api function (c# - vs2005)
we want to insert a large part into the document. our problem is that "insertpart2" returns null when we run the add-in for the first time (and the part is not inserted) while it returns the handle of the inserted part (and the part is inserted) when we run the add-in again. we tested the add-in by using a small part. "insertpart2" can insert the small part for the first time. does anyone have any idea about this?
many thanks
newform
sounds like a timing problem. your code is continuing on before swx has responded w/ the handle given the size of the part and the time it's taking to process.
my code in c# is as follows:
swfeat = swpart.insertpart2(path, (int)swinsertpartoptions_e.swinsertpartimportsolids);
where swfeat is a "feature" object, swpart is "partdoc" object, and path is string containing the full path of the file.
how can i know when swx responses? i can only check the returned value - "swfeat" and see if it is null. does anyone have any solution for it? thanks
newform
the following is my test code in c# (vs2005). it works fine for file (with size of severall k) but get error message "obtained feature is null" if the file is large, say 18m.
-----------------------
bool test(isldworks iswapp)
{
string strfun = "test";
/// check input argument
if (iswapp == null)
{
messagebox.show("application is null", strfun, messageboxbuttons.ok, messageboxicon.information);
return false;
}
/// create a new document
string parttemplate = iswapp.getuserpreferencestringvalue((int)swuserpreferencestringvalue_e.swdefaulttemplatepart);
modeldoc2 swmod = (modeldoc2)iswapp.newdocument(parttemplate, (int)swdwgpapersizes_e.swdwgpapera2size, 0.0, 0.0);
if (swmod == null)
{
messagebox.show("solidworks application cannot create a new document.", strfun, messageboxbuttons.ok, messageboxicon.error);
return false;
}
partdoc swpart = null;
/// get part handle
if (swmod is partdoc)
{
swpart = swmod as partdoc;
}
else
{
messagebox.show("solidworks application cannot create the partdoc handle.", strfun, messageboxbuttons.ok, messageboxicon.error);
return false;
}
/// insert moulds
string path = @"c:\documents and settings\fguan\desktop\t3\old.sldprt";
feature swfeat = swpart.insertpart2(path, (int)swinsertpartoptions_e.swinsertpartimportsolids);
if (swfeat == null)
{
messagebox.show("obtained feature is null.", strfun, messageboxbuttons.ok, messageboxicon.error);
return false;
}
return true;
}
hi,
we just found out what the problem is. if the file has certain kinds of references, such as circular reference, "insertpart2" doesn't allow opening the file.
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-22 23:22 , Processed in 0.035609 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表