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

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   DirectDWG (http://www.dimcax.com/hust/forumdisplay.php?f=89)
-   -   【转帖】appendloop90 exception question (http://www.dimcax.com/hust/showthread.php?t=15114)

yang686526 2009-05-04 04:05 PM

【转帖】appendloop90 exception question
 
appendloop() exception question
appendloop() exception question
hi,
we're using dd 1.14.02. am appending a single database object as a loop to hatch. the object is a oddb2dpolyline.
consider the following vertices:
v1 = (1, 2)
v2 = (2, 2)
v3 = (1, 3)
v4 = (2, 3)
v5 = (2, 1)
when the polyline is made as {v1, v2, v1, v3, v4, v5, v1}, appendloop() throws invalid input exception.
initially i thought it was the problem with inner loop {v1, v2, v1} preceding the outer loop {v1, v3, v4, v5, v1} in the order. so i tried reversing. but polyline made as {v1, v5, v4, v3, v1, v2, v1} produces the same result.
when the polylne is made as {v2, v1, v3, v4, v5, v1, v2} it creates the hatch just fine.
can someone please advice.
incidently, it was working perfectly fine using old odt.
thanks,
varun

has anyone else encountered such problems. if so, i'd be very much interested in the workaround you developed to overcome this.
thanks,
varun
from objectarx help:
a loop must be simple, closed, and continuous, intersecting itself only at its endpoints. furthermore, its start point and end point must coincide. when defining the hatch boundary, the application must ensure that the loops and edges are well defined and structured. if the boundary contains two or more loops, they must be organized into a nested structure in which the external loop is constructed first, then followed by all its internal loops in nested order. if there is more than one external loop, repeat the process. autocad provides limited validation of the hatch boundary in order to maintain api efficiency and performance.
actually non-closed, self-intersecting etc. loops cause problems only with solid hatches.
solid hatch does not like (v1,v2,v1) part of your path.
sergey slezkin

hi,
can anyone suggest some pointers to good algorithms to ensure polylines are simple and non self intersecting. my app does not provide a rich toolkit for ensuring the strigent conditions laid down for hatch loops.
thanks,
varun
i am getting the same exception from appendloop(). the object array contains a single polyline with the following points:
dwgdirect exception: invalid input
polyline point=(17.01597613642, 3.03995167676, 0.00000000000)
polyline point=(17.01597613642, 14.59640955921, 0.00000000000)
polyline point=(24.72712509877, 3.03995167676, 0.00000000000)
polyline point=(17.01597613642, 3.03995167676, 0.00000000000)
the hatch is a solid hatch. the polyline forms a triangle and the first and last points are the same to at least 11 decimal places. i can't see how this input would be invalid based on the description posted earlier.
i am using dd version 2.0.3 with msvc++ 2003. this same code worked in dd version 1.13.2.
any ideas?
i downloaded and installed dd version 2.1.0, and this problem persists.
bcavebmg, your problem seems to be a different one from mine. does it work if you specifiy a different pattern than solid? there was some issue with tolerance as well regarding this, but i think it was fixed in 1.14.03 (sorry, i can't seem to find the relavent thread at this moment.)
btw, i got around the original problem by checking for duplicated edges, and if present adding the entity as a spline instead of a polyline (worked like a beauty! )
regards,
varun
can you post the code you are using to append loop?
vladimir
this is the gist of it:
code:
oddbobjectidarray aobjs;
// fill aobjs with ids for objects to be hatched. in the case where,
// i get an exception, it contains a single polyline as described above.
oddbhatchptr phatch = oddbhatch::createobject();
phatch->setpattern(oddbhatch::kpredefined, "solid");
phatch->setassociative(true);
phatch->sethatchstyle(oddbhatch::knormal);
phatch->setcolorindex(3);
phatch->appendloop(oddbhatch::kexternal, aobjs);as i mentioned before, this code worked with dd 1.13.2, but does not work with version 2.0.3 or 2.1.0.
i used the following test code, and could not reproduce the problem:
code:
void _hatchtest_func(odedcommandcontext* pcmdctx)
{
oddbcommandcontextptr pdbcmdctx(pcmdctx);
oddbdatabaseptr pdb = pdbcmdctx->database();
oddbobjectidarray aobjs;
oddbblocktablerecordptr ms = pdb->getmodelspaceid().safeopenobject(oddb::kforwrite);
oddbpolylineptr poly = oddbpolyline::createobject();
poly->addvertexat(0,odgepoint2d(17.01597613642, 3.03995167676));
poly->addvertexat(1,odgepoint2d(17.01597613642, 14.59640955921));
poly->addvertexat(2,odgepoint2d(24.72712509877, 3.03995167676));
poly->addvertexat(3,odgepoint2d(17.01597613642, 3.03995167676));
aobjs.append(ms->appendoddbentity(poly));
// fill aobjs with ids for objects to be hatched. in the case where,
// i get an exception, it contains a single polyline as described above.
oddbhatchptr phatch = oddbhatch::createobject();
phatch->setpattern(oddbhatch::kpredefined, "solid");
phatch->setassociative(true);
phatch->sethatchstyle(oddbhatch::knormal);
phatch->setcolorindex(3);
phatch->appendloop(oddbhatch::kexternal, aobjs);
ms->appendoddbentity(phatch);
}what kind of polyline do you use?
vladimir
here is how i construct the polyline:
code:
oddbpolylineptr pacadpolyline = oddbpolyline::createobject();
pacadpolyline->minimizememory();
// "points" is a collection of point objects.
for (size_t i = 0; i < points.getcount(); i++)
{
point pt = points.getat(i);
pacadpolyline->addvertexat(pacadpolyline->numverts(), odgepoint2d(pt.x, pt.y));
}
pacadpolyline->setclosed(true);
pacadpolyline->setlayer(idlayer);
oddbobjectid idnewentity = pdwgblock->appendoddbentity(pacadpolyline);it is pretty straightforward. i tried removing the call to minimizememory(), but i still get the exception.
some more info...
i tried removing the call to pacadpolyline->setclosed(true), and now the exception has gone away. maybe the problem is related to that?
yes, it is a bug in dd appendloop code. it adds empty segment if polyline is closed and its start and end points are the same (redundantly closed polyline). then it checks edge data and complains on empty edge segment.
as a workaround you may check for such condition and open polylines while adding loops, or, if you create the polylines yourself - do not add last duplicated point if the polyline is intended to be closed.
the bug will be fixed in the next update.
vladimir
hello,
is it safe using a hatch entity, when appendloop() throws "invalid input" exception?
for example, at the begining i had treat this exception, then i call appendloop() once again for add an anohter loop.
best regards,
andrey.
yes, it is safe - hatch is modified only when all the checks are passed.
vladimir


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