查看单个帖子
旧 2009-05-07, 03:24 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】save Gradient Hatches

save gradient hatches
save gradient hatches
hi to all,
i have made a gradient hatch with odamfcapp with the code below:
code:
//test for gradient hatch
oddbobjectid idhatchtemp;
oddbdatabaseptr pdb = this->m_pdb;
{
oddbblocktablerecordptr precord = pdb->getactivelayoutbtrid().safeopenobject(); pdb->getactivelayoutbtrid().safeopenobject(oddb::kforwrite);;
//create new hatch
oddbhatchptr phatch = oddbhatch::createobject();
phatch->setdatabasedefaults(precord->database());
oddbobjectid hatchid = precord->appendoddbentity(phatch);
idhatchtemp = hatchid;
}
{

oddbhatchptr phatch = idhatchtemp.safeopenobject(oddb::kforwrite);
odgevector3d normal(0.0, 0.0, 1.0);
phatch->setnormal(normal);
phatch->setelevation(0.0);
// set non associative hatch
//
phatch->setassociative(false);
// set hatch pattern to solidfill type
//
phatch->setpattern(oddbhatch::kpredefined, "solid");
// set hatch style to knormal
//
phatch->sethatchstyle(oddbhatch::knormal);
// construct hatch external boundary
//
odgepoint2darray vertexpts;
odgedoublearray vertexbulges;
vertexpts.setphysicallength(0).setlogicallength(5);
vertexpts[0].set(2.0, 2.0);
vertexpts[1].set(8.0, 2.0);
vertexpts[2].set(8.0, 8.0);
vertexpts[3].set(2.0, 8.0);
vertexpts[4].set(2.0, 2.0);
vertexbulges.setphysicallength(0).setlogicallength(5);
for (int i = 0; i < 5; i++)
vertexbulges[i] = 0.0;
// append an external loop (rectangle) to hatch boundary
phatch->appendloop(oddbhatch::kpolyline, vertexpts, vertexbulges);
//gradient params
phatch->sethatchobjecttype(oddbhatch::kgradientobject);
phatch->setgradient(oddbhatch::kpredefinedgradient,"spherical");
odcmcolorarray cols;
odgedoublearray vals;
vals.push_back(0.0);vals.push_back(1.0);

odcmcolor color1(odcmentitycolor::kbyaci);
color1.setcolorindex(3);//green
cols.push_back(color1);
odcmcolor color2(odcmentitycolor::kbyaci);
color2.setcolorindex(6);//magenta
cols.push_back(color2);
//rgb colors
////odcmcolor color1(odcmentitycolor::kbycolor);
////color1.setrgb(255,0,0);
////cols.push_back(color1);
////odcmcolor color2(odcmentitycolor::kbycolor);
////color2.setrgb(0,0,255);
////cols.push_back(color2);
assert(cols.size() == vals.size());
phatch->setgradientcolors(2, &cols[0], &vals[0]);
phatch->setgradientonecolormode(false);
phatch->setshadetintvalue(1.0);
phatch->setgradientangle(0.0);
phatch->setgradientshift(0.0);
phatch->evaluatehatch(true);
}
after that i saved the drawing and opened it in acad 2006.
it seems the gradient colors are set to black - rgb 0,0,0. they are set from the code respectively to green and magenta as indexed colors, but they are somehow overwritten.
when i use rgb colors(see the commented code) there are no problems.
so, does it mean that the colors should be always rgb (odcmentitycolor::kbycolor) to be saved correctly?
thanks in advance
nino
file format allows to store gradient colors as index. but for some reason autocad always store them in file as rgb. maybe it will be fixed in ac2007..
sergey slezkin
thanks for the attention!
regards,
nino
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)