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


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


 
 
主题工具 搜索本主题 显示模式
旧 2009-05-06, 06:34 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】no lineweights on bmp-expor

no lineweights on bmp-export?
no lineweights on bmp-export?
i realized that the bmp-export does not draw curves with their respective lineweights. the pdf-export from odamfcapp gives the right results. where is the difference? what do i have to do to get the same result on a bitmap? are there other export-options or do i have to alter the code?
your help is appreciated.
this is the code i use. i've copied it from some example you provided, slightly modified:
code:
int mergefunctions::writebmp( oddbdatabaseptr pdb, long resolution, odstring targetfile )
{
int rcode = rc::r_rstdev;
try{
//code from cmd_bmpout
//odgsmoduleptr pgs = odrxdynamiclinker()->loadmodule(dd_t("winopengl_2.06_9.gs"), false);
//odgsmoduleptr pgs = odrxdynamiclinker()->loadmodule(dd_t("windirectx_2.06_9.gs"), false);
odgsmoduleptr pgs = odrxdynamiclinker()->loadmodule(dd_t("wingdi_2.06_9.gs"), false);
//odgsmoduleptr pgs = odrxdynamiclinker()->loadmodule(dd_t("winbitmap_2.06_9.gs"), false);

odgsdeviceptr pdevice = pgs->createbitmapdevice();
odgicontextfordbdatabaseptr pctx = odgicontextfordbdatabase::createobject();
pctx->setdatabase(pdb);
// extents of active layout
pdevice = oddbgsmanager::setupactivelayoutviews(pdevice, pctx);
odabstractviewpeptr pdeviceview;
odgsviewptr pdv;
odrxobjectptr playoutview;
if (!pdb->gettilemode())
{ // paper space
pdv = odgspaperlayouthelperptr(pdevice)->overallview();
pdeviceview = pdv;
oddblayoutptr playout = pdb->currentlayoutid().safeopenobject();
oddbobjectid overallvpid = playout->overallvportid();
oddbviewportptr pactivevp = overallvpid.safeopenobject();
playoutview = pactivevp;
}
else
{ // model space
pdv = odgsmodellayouthelperptr(pdevice)->activeview();
pdeviceview = pdv;
oddbviewporttableptr pvpt = pdb->getviewporttableid().safeopenobject();
oddbviewporttablerecordptr pactivevp = pvpt->getactiveviewportid().safeopenobject();
playoutview = pactivevp;
}
// get extents from current layout
odgeboundblock3d bbox;
odabstractviewpeptr playoutviewpe(playoutview);
playoutviewpe->viewextents(playoutview, bbox);
pdeviceview->zoomextents(pdv, &bbox);
int ncolorbits = 1;
pdevice->properties()->putat("bitperpixel", odrxvariantvalue(oduint32(ncolorbits)));
odcolorref bg = odrgb(255,255,255); // palette background
pctx->setpalettebackground(bg);
const odcolorref* palette = odcmacadpalette(bg);
odgspalette ppalcpy;
ppalcpy.insert(ppalcpy.begin(), palette, palette+256);
ppalcpy[0] = bg;
pdevice->setlogicalpalette(ppalcpy.asarrayptr(), 256);
double width = bbox.maxpoint().x - bbox.minpoint().x;
double height = bbox.maxpoint().y - bbox.minpoint().y;
double x = ( width/25.4 ) * resolution;
double y = ( height/25.4 ) * resolution;
//round
long xsize = (long)floor(x+0.5);
long ysize = (long)floor(y+0.5);
odgsdcrect gsrect(0, xsize, ysize, 0 );
pdevice->onsize(gsrect);
pctx->setplotgeneration(1);
pdevice->setbackgroundcolor(bg);
pdevice->update();
rcode = rc::r_wrtbmp;
savebitmap( odgirasterimageptr(pdevice->properties()->getat("rasterimage")), targetfile );
rcode = rc::r_ok;
} catch( oderror e ){
odstring s = e.description();
odresult r = e.code();
oderrorcontext * ec = e.context();
std::cout << std::endl << "oderror: ";
odprintconsolestring( s );
std::cout << std::endl << "oderrorcode: " << e.code() << std::endl;
}
return rcode;

lineweights
hi martin,
see our bmpout example in excustobjs. it process lineweights correctly.
i've looked into the code you've mentioned. it is exactly the sample-code i started with... as you can see in my code, i altered it so it would fit my needs. can you please point out to me where i can tell the device (or some other object..) to also process the lineweights? i cannot see the relevant difference between the my altered code and the sample you provided.
just a short hint would be enough so i could look into it using the api. thank you.
ps: are you absolutely sure the bmp-export prints the right lineweights? in my results i get the same weight for all the lines...

lineweights
quote:
can you please point out to me where i can tell the device (or some other object..) to also process the lineweights? i cannot see the relevant difference between the my altered code and the sample you provided.
are lineweights visible in bmpout example output or odamfcapp for your drawing?
lineweight displaying controlled by lwdisplay variable into drawing. are you sure is lwdisplay is on?
output image may be too small to display lineweight, in this case lines will be drawed using 1px width.
quote:
ps: are you absolutely sure the bmp-export prints the right lineweights? in my results i get the same weight for all the lines...
you can test it on lineweights.dwg autocad sample. see attached result image of bmpout.
attached images (37.7 kb, 4 views)

ok
hi amark
you're right, the lineweights were not visible, that's why the resulting bmp didn't show the right lineweights. i make them visible now, before exporting and reset the lwdisplay flag to false after bmp was written.
i didn't expect the bmp-export to be linked to the display. a simple lack of dwgdirect knowledge...
thanks for the hint!
cheers
martin
...not quite!
hi amark
i can see different lineweights in the lines of the exported bmp. but the lineweights do not correspond to the value in the dxf-file. the appearance is similiar to that in odamfcapp-view. the lines are too wide. i might be missing some important steps. can you give me a short step-to-step tutorial on how to get a bitmap of a dxf with exact lineweights and a defined resolution?
i found the lineweights.dwg you've mentioned earlier. the resulting bmp is much too small (resolution should be 600 ppi). i've attached two examples, both files are tifs (i convert the resulting bmp in tif, nothing wrong with the conversion though, i double checked that). "merged_example.tif" is how the exported drawing should look like, however the lines are too fat ( tool: 0.5mm ). "lineweights.tif" is what i get when i export the "lineweights.dwg" drawing.
what do i have to do? define views? create a new paperspace? i am not too familiar with autocad and totally lost...
martin
ps: the code i use is in the first post...
attached files (1.1 kb, 2 views)
(5.2 kb, 2 views)


lineweights
hi martin,
why do you think lineweights is not exact? drawing has own units, lineweights defined in millimeters. so if you scale drawing - you will get lineweights exactly recalculated using drawing units. you can compare output image with autocad bmp export, results will be same.
btw, this behaviour available only in paperspace (ps), modelspace (ms) lineweights has constant visible lineweights not dependent on zooming.
you can scale lineweights into ps using plot settings, or in ms using lwdispscale variable.
i think i'm getting closer to the problem now...
picture following situation:
1. i've openened a dxf-file in my application. the different layers of the drawing have a certain color and lineweight assigned.
2. now i call the writebmp-function i posted earlier with a resolution 200. i then convert the newly created bmp-file into a tif (no resizing).
when i examine the tif-file, i measure a lineweight of approximately 0.76 mm instead of the defined 0.5mm.
if i repeat step 1&2 with...
resolution of 600: lineweight of ~0.25 mm instead of 0.5mm
resolution of 400: lineweight of ~0.38 mm instead of 0.5mm
all files are attached. feel free to take a look
could this be, because i export from model-space? where can i decide what space to export from? how do i export from paperspace? do i have the possibility of setting a resolution to the exported bmp from paperspace? it would be very helpful i you could provide me with an example or just roughly describe the steps i'd have to take to get there.
the goal is to produce a bmp (tif in the end..) of a drawing in a certain resolution ( 200-600) with respective lineweights.
thanks a lot for your help amark!
attached files (26.4 kb, 2 views)


lineweights
hi martin,
yes, this is modelspace behaviour (you can see difference of lineweight behaviour for paperspace and modelspace into odamfcapp or autocad by switching between layouts and zoom in/out).
in your drawing active layout is modelspace, so your code export modelspace.
code:
// extents of active layout
pdevice = oddbgsmanager::setupactivelayoutviews(pdevice, pctx); // active layout
// . . .
if (!pdb->gettilemode()) // tilemode true if modelspace view enabled
{ // paper space
// . . .
}
else
{ // model space
// . . .
}you can use following variants to switch layouts manually before setupactivelayoutviews() call:
1) you can set tilemode variable to true
2) you can call pdb->setcurrentlayout(name) if you know name of layout you need.
3) you can get oddblayoutmanager object from database (pdb->appservices()->layoutmanager()) and call setcurrentlayout(pdb, layoutid) to set layout you need. layout manager also can be used for enumerate layouts in drawing, create new layouts and etc.
hi amark
thanks for your response. here's what i tried:
1) setting tilemode to true leaves my with an exception on this line (cannot cast...):
code:
pdv = odgspaperlayouthelperptr(pdevice)->overallview();2) unfortunately i don't know the name of the layout, so this will not help me.
3) this is an interesting approach. my idea is to add a new layout (in paperspace) and then make the bmp-export. the code works, but the result is just a very small sized bmp with no content (just white). i added this to my code:
code:
//test paperspace...
oddblayoutmanagerptr layoutmanager = pdb->appservices()->layoutmanager();
int noflayouts = layoutmanager->countlayouts( pdb );
odstring printlayout = l"dxfmergeprintlayout";
oddbobjectid printlayoutid = layoutmanager->createlayout( pdb, printlayout );
layoutmanager->setcurrentlayout( pdb, printlayoutid );obviously this isn't enough. as you said yourself, the drawing has a certain size. i'd like to get a view of the whole drawing (right to the extents, just as i did in modelspace), get those extents and multiply them with a given resolution. how can i achieve that? what classes are involved?
i will be working this weekend, so if you could reply to my post today it would be very helpful. thank you.
martin

lineweights
hi martin,
quote:
3) this is an interesting approach. my idea is to add a new layout (in paperspace) and then make the bmp-export. the code works, but the result is just a very small sized bmp with no content (just white).
this is not all work what you must to do in this case. after layout creation you must add oddbviewport entity to new layout and set it view to modelspace extents in it (zoomextents() for example).
quote:
obviously this isn't enough. as you said yourself, the drawing has a certain size. i'd like to get a view of the whole drawing (right to the extents, just as i did in modelspace), get those extents and multiply them with a given resolution. how can i achieve that? what classes are involved?
you can get eye coordinate system extents using odabstractviewpe::viewextents() method (see documentation and examples).
additionaly oddblayout has getextmin() and getextmax() methods.
hi amark
quote:
this is not all work what you must to do in this case. after layout creation you must add oddbviewport entity to new layout and set it view to modelspace extents in it (zoomextents() for example).
following code is my attempt to implement what you describe above. how do i add the viewport entity to the layer? how can i set it to view modelspace extents? can't find any example of this...
code:
oddblayoutmanagerptr layoutmanager = pdb->appservices()->layoutmanager();
odstring printlayout = l"dxfmergeprintlayout";
oddbobjectid printlayoutid = layoutmanager->createlayout( pdb, printlayout );
layoutmanager->setcurrentlayout( pdb, printlayoutid );
oddbviewportptr viewportentity = oddbviewport::createobject();
viewportentity->setdatabasedefaults( pdb );
viewportentity->zoomextents();
oddblayoutptr printlayoutptr = printlayoutid.safeopenobject( oddb::kforwrite );
printlayoutptr->setactiveviewportid( viewportentity->id() ); //exception null-id...i've tried to use the "void dbfiller::addlayout(oddbdatabase* pdb)" code (instead of code above) without the "creating viewports for all entities"-part. the result shows the whole drawing, but much too small.
quote:
you can get eye coordinate system extents using odabstractviewpe::viewextents() method (see documentation and examples).
additionaly oddblayout has getextmin() and getextmax() methods.
this is already done in the code ( from _bmpout_cmd::execute ). i assume that if i do the first part right, the results will be as expected.
code:
// get extents from current layout
odgeboundblock3d bbox;
odabstractviewpeptr playoutviewpe(playoutview);
playoutviewpe->viewextents(playoutview, bbox);
pdeviceview->zoomextents(pdv, &bbox);can you give me some more detailed information on this? thanks for your patience.
martin
attached files (1.1 kb, 1 views)


quote:
following code is my attempt to implement what you describe above. how do i add the viewport entity to the layer? how can i set it to view modelspace extents? can't find any example of this...
example of viewport creation also can be found in odwriteex example [dbfiller.cpp] dbfiller::addpsviewport(). i think you are already use correct code if got paperspace layout with entire modelspace view.
quote:
the result shows the whole drawing, but much too small.
you use following code for compute output bitmap dimensions:
code:
double width = bbox.maxpoint().x - bbox.minpoint().x;
double height = bbox.maxpoint().y - bbox.minpoint().y;
double x = ( width/25.4 ) * resolution;
double y = ( height/25.4 ) * resolution;, but paperspace and modelspace units are different.
code:
playoutviewpe->viewextents(playoutview, bbox);for paperspace layout returns layout viewport size into paperspace coordinate space (not size of entire drawing in modelspace).
so you need to improve your calculations at this point.
ok, so i get the right size of the drawing and then add a new layout with a viewport. i do the following, before adding layout and viewport:
code:
double totalwidth, totalheight;
oddbobjectptr pmsblock = pdb->getmodelspaceid().safeopenobject();
odgeextents3d extents;
odresult err = pmsblock->getgeomextents(extents);
totalwidth = extents.maxpoint().x - extents.minpoint().x;
totalheight = extents.maxpoint().y - extents.minpoint().y;the drawback of this is, that some drawings have blockreferences in it with coordinates way out of the visible part of the drawing. i will then get a huge bmp or an exception because of the size. what other possibilities do i have to determine the extents of the visible part of a drawing ( extents in the unit of modelspace) ?

quote:
what other possibilities do i have to determine the extents of the visible part of a drawing ( extents in the unit of modelspace) ?
you can get modelspace geometry extents via viewextents() function, but in your case call it for oddbviewport containing whole modelspace. if you call zoomextents() for viewport, you can use viewextents() one time (for get geometry extents and for next zoomextents() call).
after that you can use layout extents separately for setup viewer onto viewport in paperspace.
paperspace primarily used for plotting of drawings, so it has some properties, which can be used for setup correct resolution of drawings. i think plotting and bitmap exporting is the same application field, but i can't say more clear how this properties can be used in your case because poorly familiar with this matter.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】maximal resolution on bmp-expor yang686526 DirectDWG 0 2009-05-06 05:28 PM
【转帖】error in export to bmp yang686526 DirectDWG 0 2009-05-05 09:37 AM
【转帖】bmp of 32bit color yang686526 DirectDWG 0 2009-05-04 04:54 PM
【转帖】bmp export and whitespace yang686526 DirectDWG 0 2009-05-04 04:54 PM
【转帖】any dwg to bmp export command line programsample code yang686526 DirectDWG 0 2009-05-04 04:03 PM


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


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