几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 02:45 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】sw com addin and depth buffer

sw com addin and depth buffer
hi all,
i m writing an addin using sw com addin in vc++.
i am using visual studio 2005.
i am required to read the depth information of the model and store it in an array. but i am receiving an error code that maps to "invalid pixel format" when the finction wglmakecurrent(hdc,hrc) is encountered.
i have been programming with vb n c# throughout ... this is the first time i m working on vc++ an finding it a bit hard to comprehend ...!!
i was wondering if anybody could point me to a link of a code that reads zbuffer data of a model.
thank you all ...!!
abraham
if you dont mind me asking why switch to c++ from c# and vb in the first place? as far as sw is concerned you will gain nothing of benefit.
actually i am working on a code left half way .... by another programmer...who did it in vc++!!
he has included "gl.h" and is using the glreadpixel in conjunction with gl_depth_component to read depth buffer!!
i don't mind rewriting it all over in c# as i feel that will make my life a lot easier... but i didn't find a way of using opengl commands in c#.... .....
personally i would re-write it all yourself instead of rehacking someone elses code. that way not only will it be cleaner but you will have a full understanding of every part of the code, and can also enjoy the fact that the end result is entirely yours.
as for opengl, not sure what you are doing with solidworks if you are using opengl unless you are rendering something yourself, but here are a few good links to get you started using opengl libraries build purely for c#:
thank you very much.. that was very informative...!!!
i have a requirement to read out the depth information of all the pixels and preform some computation on it....
i had a few more queries ....
=========================
1. the existing code has been written by creating a vc++ mfc extention dll. i wanted to know if there in any advantage (performance or otherwise) of choosing that over sw com addin.
2. i have installed sw 2007 sdk and tried to create a c# sw com addin project ... but it fails with the error dialog "error hresult e_fail has been returned from a call to com component" as soon as i press the ok. the same was observed for vb.net too.
but in vc++ the addin project was created successfully. what could have gone wrong?
3. here's a part of the code that i tried in vc++ addin...
m_modeldoc2->graphicsredraw2();
long h;
m_modelview->getviewhwnd(&h);
hwnd hwnd = (h);
hdc hdc = getdc(hwnd);
hglrc hrc = wglcreatecontext(hdc);
if(wglmakecurrent(hdc, hrc) == null)
"failed to make rendering context current"
else
"sucessful"
the code fails at this point... and the error code maps to "invalid pixel format" .... am i going wrong
thank you very much again for all the help you are extending
1. no there won't be any advantage. the only difference is that the dll gets registered in the rot (running object table) and loaded by sw as an add-in, which takes a split second. from that point on the performance is the same, possibly even minutely faster as a sw add-in as it may store a prefetch object for the dll.
2. this is usually the code if the com fails to get a handle to sw, so you are best supplying me with some code so i can look at it. also, debug the project and step through it line by line to see where the error is occuring.
3. that may be failing if again it is an in-process call to getviewhwnd. the best way to check that is to create a macro so it runs in-process and do exactly the same (if you know how to do it in vba), if not create an add-in to run the code. if you still get the error i will look into it further.
2. this is usually the code if the com fails to get a handle to sw, so you are best supplying me with some code so i can look at it. also, debug the project and step through it line by line to see where the error is occuring.
i m getting this error in the create new project dialog itself.
i supply the name of the project and select sw com addin from the template ... and hit ok ... and i get this error immediately "error hresult e_fail has been returned from a call to com component"
the status bas says "error creating project" {note that this happens only in vb n c# and not in vc++}
that may be failing if again it is an in-process call to getviewhwnd. the best way to check that is to create a macro so it runs in-process and do exactly the same (if you know how to do it in vba), if not create an add-in to run the code. if you still get the error i will look into it further.
thank you for the suggestion .. i 'll sure try that out!!
thanks a llot again!!
hi luke,
sorry for the delay on my part.... it was a long week end...!!
1. i have tried everything.. but am not getting anywhere.
2. my objective is to use the sw com addin and be able to obtain the opengl rendering context so that i can read the depth buffer!! cud you please help me out. (without using mfc, if possible and a completely managed coding)
3. i m using vc++ sw com addin anyway.. as the other two are not happening for me as stated in my previous post...
thank you very much .. again!!
abraham
hey!!
i got the solution...
m_modeldoc2->graphicsredraw2();
long h;
m_modelview->getviewhwnd(&h);
hwnd hwnd = (h);
cwindow wh(hwnd);
hdc hdc = getdc(wh.m_hwnd);
hglrc hrc = wglcreatecontext(hdc);
if(wglmakecurrent(hdc, hrc) == null)
"failed to make rendering context current"
else
"sucessful"
adding the "bold faced" statements did the trick.... i think i was not crerating the atl window which was causing undefined behaviour...!!
thanks a lot luke for all the suggestions...!!
abraham!!!
ah yes of course, i didn't spot that ! well done. glad it is all sorted.
ab,
i am just messing around with the hwnd of solidworks and basically capturing its pixels using bitblt. all works fine but when i get the pixels from the following:
swapp.activedoc.activeview.getviewhwnd()
and bitblt it i get an image starting at the position that the model is (if maximised it is top left of the screen below the menus) and if you make the window float it is the top position of its window. however, i actually get the pixels from the background solidworks application, not the model view. so basically i am always getting the grey solidworks logo background image, not the model. have you come across this so far? and how do you get your hwnd compared to my method?
ps i have also looped every hwnd from the swapp.frame.modelwindows and the same result. i think it is probably something to do with the 3d model being rendered on a separate buffer like playing movies are (direct to screen) so bitblt is not getting the pixels.
update. the above ps is not the case as using getdesktopwindow with the sw visible gets the model pixels, so its definately a problem with sw handles or i am doing something wrong.
furthermore, if i draw directly on the hwnd's hdc it draws on the solidworks application background too (after checking it again) so it is definately returning the handle to the sw app not the model.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 04:47 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多