create hatch

create hatch

jignesh.rana
Advocate Advocate
1,739 Views
13 Replies
Message 1 of 14

create hatch

jignesh.rana
Advocate
Advocate

hi 

 

i want to create hatch of any object but exclude inner object 

 

for e.g if one rectangle has text inside then hatch will be exclude that text 

0 Likes
1,740 Views
13 Replies
Replies (13)
Message 2 of 14

tbrammer
Advisor
Advisor

You can use 

Acad::ErrorStatus AcDbHatch::appendLoop(
    Adesk::Int32 loopType, // AcDbHatch::kDefault for a hole in the hatch, AcDbHatch::kExternal for external
    const AcDbObjectIdArray& dbObjIds // ids of the text entities 
);

 

to create a hole around one or more DB resident (text-) entities. Or

 

Acad::ErrorStatus AcDbHatch::appendLoop(
    Adesk::Int32 loopType, 
    const AcGePoint2dArray& vertices, 
    const AcGeDoubleArray& bulges
);

 

To create an arbitrary polyline shaped hole. When you are done call AcDbHatch::evaluateHatch() to update the hatch.


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

0 Likes
Message 3 of 14

jignesh.rana
Advocate
Advocate

sir could you please share code of objectarx ?

0 Likes
Message 4 of 14

jignesh.rana
Advocate
Advocate

here i attached drawing for refrence please look into this hatch is out of object

0 Likes
Message 5 of 14

tbrammer
Advisor
Advisor

Sample code:

void cmdHatch()
{
	ads_name           sset = { 0,0 };
	AcDbObjectIdArray outsideIds; // IDs of outer curve(s)/region
	AcDbObjectIdArray holeIds;    // IDs of inner text(s)/pline(s)/region that shall create ONE hole.

	acutPrintf(_T("\nSelect entities that form the outer conture: "));
	if (acedSSGet(NULL, NULL, NULL, NULL, sset) == RTNORM)
	{
		outsideIds.setLogicalLength(0);
		Selset2ObjIdArray(sset, outsideIds);
		acedSSFree(sset);
	}
	else
		return;

	Acad::ErrorStatus es;
	AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
	AcDbHatch* hatch = new AcDbHatch();
	hatch->setDatabaseDefaults(db);
	es = hatch->appendLoop(AcDbHatch::kExternal, outsideIds);

	int stat = RTNORM;
	while (stat==RTNORM)
	{
		acutPrintf(_T("\nSelect entities that form one inner hole: "));
		stat = acedSSGet(NULL, NULL, NULL, NULL, sset);
		if (stat == RTNORM)
		{
			holeIds.setLogicalLength(0);
			Selset2ObjIdArray(sset, holeIds);
			acedSSFree(sset);
			es = hatch->appendLoop(AcDbHatch::kDefault, holeIds);
		}
	}

	hatch->evaluateHatch();
	postToDb(db, hatch);
}

long Selset2ObjIdArray(ads_name sset, AcDbObjectIdArray& objIdArr) {
	Adesk::Int32 selSetLen = 0, i;
	if (acedSSLength(sset, &selSetLen) != RTNORM)
		return -1;
	ads_name ename;
	AcDbObjectId objId;

	for (i = 0; i < selSetLen; i++)	{
		if (acedSSName(sset, i, ename) == RTNORM) {
			if (acdbGetObjectId(objId, ename) == Acad::eOk)
				objIdArr.append(objId);
		}
	}
	return selSetLen;
}


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

0 Likes
Message 6 of 14

jignesh.rana
Advocate
Advocate

sir please try in this drawing which i attached

 

hatch is out of object

0 Likes
Message 7 of 14

tbrammer
Advisor
Advisor

Works perfectly. Did I pick the right entities?

 


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

0 Likes
Message 8 of 14

jignesh.rana
Advocate
Advocate

please look into this 

 

jigneshrana_0-1716544078817.png

 

0 Likes
Message 9 of 14

tbrammer
Advisor
Advisor

I don't know what you mean. Did you watch the video? Did I select the right entities? 

Please post a DWG that only contains the entity that defines the outer bounds of the hatch and the text that shall be left out.

Which AutoCAD version do you use?


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

0 Likes
Message 10 of 14

tbrammer
Advisor
Advisor

It looks as if you created a external hatch loop using the bounding points of the MTEXT entity.

This is what SNOOPENTS from the ArxDbg.arx (<ARX>\samples\database\ARXDBG) shows for the MTEXT:

tbrammer_0-1716546979852.png

And this for the hatch:

tbrammer_1-1716547162412.png

 

If you use my code the inner loop will look like this:

tbrammer_2-1716547249828.png

 


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

0 Likes
Message 11 of 14

jignesh.rana
Advocate
Advocate

one more help required 

 

want to set specific color for hatch for e.g red color i tried to set it 

hatch->SetColorIndex(1);

 

but its not working

0 Likes
Message 12 of 14

tbrammer
Advisor
Advisor
Acad::ErrorStatus es = hatch->setColorIndex(1);

should work. Please check whether it returns es==Acad::eOk.

Did you open hatch for write and close it after changing the color?

Maybe the graphics need a refresh. Try _REGEN or save and reopen the drawing.

If the hatch isn't "solid" or "gradient" the color is applied to the pattern of the hatch. If no part of the pattern is visible, you will only see the background color of the hatch - or the background itself if the background color is "none". Try

AcCmColor color; 
color.setColorIndex(1);
hatch->setBackgroundColor(color);

 


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

0 Likes
Message 13 of 14

jignesh.rana
Advocate
Advocate

in this logic if more than one closed polylines/regions in outer polyline then its not work

0 Likes
Message 14 of 14

jignesh.rana
Advocate
Advocate

please share objectarx code to exclude inner objects more than one including text.

 

please see attachment/image

 

jigneshrana_0-1726123957188.png

 

0 Likes