cad2008~2014 createFromCurves bug

cad2008~2014 createFromCurves bug

xinxirong
Enthusiast Enthusiast
769 Views
3 Replies
Message 1 of 4

cad2008~2014 createFromCurves bug

xinxirong
Enthusiast
Enthusiast

The test example in attachment,with this code,cad will turn to no responded and memory increased quickly to 32G

AcDbRegion::createFromCurves(curves, regions);

0 Likes
Accepted solutions (1)
770 Views
3 Replies
Replies (3)
Message 2 of 4

tbrammer
Advisor
Advisor
Accepted solution

I can't test with Acad 2014 or older. The code below runs well on Acad 2022 with your sample DWG. Can you try it with your version?

Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbDatabase* pDB)  {
	AcDbObjectId IdModelSpace = acdbSymUtil()->blockModelSpaceId(pDB);
	AcDbBlockTableRecord* model;
	Acad::ErrorStatus es;
	if ((es = acdbOpenObject(model, IdModelSpace, AcDb::kForWrite)) == Acad::eOk)	{
		es = model->appendAcDbEntity(ent);
		model->close();
	}
	return es;
}

void cmdMyRegion()
{
	ads_name ss, ename;
	int stat = acedSSGet(NULL, NULL, NULL, NULL, ss);
	if (RTNORM != stat)
		return;

	Adesk::Int32 nSSLength = 0;
	acedSSLength(ss, &nSSLength);
	Acad::ErrorStatus es;
	AcDbVoidPtrArray curves, regions;
	AcDbObjectId objId;
	AcDbEntity* ent;

	for (Adesk::Int32 i = 0; i < nSSLength; i++)
	{
		acedSSName(ss, i, ename);
		es = acdbGetObjectId(objId, ename);
		if (!es)	{
			if ((es = acdbOpenObject(ent, objId, AcDb::kForRead)) == Acad::eOk)	{
				curves.append(ent);
				ent->close();
			}
		}
	}
	acedSSFree(ss);

	// close the curves
	for (int i = 0; i < curves.length(); ++i)	{
		ent = static_cast<AcDbEntity*>(curves[i]);
		ent->close();
	}

	es = AcDbRegion::createFromCurves(curves, regions); // create region(s)
	if (!es)	{ 		// append region(s) to the modelspace
		for (int i = 0; i < regions.length(); ++i)		{
			ent = static_cast<AcDbEntity*>(regions[i]);
			postToDb(ent, acdbHostApplicationServices()->workingDatabase());
			ent->close();
		}
	}
}

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 4

xinxirong
Enthusiast
Enthusiast

Yes ,it work well at cad2020,but doesn't at 2008~2014

0 Likes
Message 4 of 4

tbrammer
Advisor
Advisor

I'm afraid that these AutoCAD versions are discontinued. So you probably won't get a fixed version.

Does AutoCAD also crash if you try to create a region with the REGION command? Could you use acedCommand() as a workaround then?

Maybe you can convert the spline entities to polylines using AcDbSpline::toPolyline(AcDbCurve*&, ..) and use the polylines instead of the splines.

 

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes