How to create a Swept Solid using the objectARX AcDb3dSolid::createSweptSolid api?

How to create a Swept Solid using the objectARX AcDb3dSolid::createSweptSolid api?

it
Participant Participant
2,082 Views
7 Replies
Message 1 of 8

How to create a Swept Solid using the objectARX AcDb3dSolid::createSweptSolid api?

it
Participant
Participant

Hello everyone,
Does anyone know how to create a Swept Solid using the objectARX AcDb3dSolid::createSweptSolid api? I've been looking for a long time and haven't found any usable examples, can anyone help?

2022-05-25_164210.png

0 Likes
Accepted solutions (1)
2,083 Views
7 Replies
Replies (7)
Message 2 of 8

tbrammer
Advisor
Advisor
Accepted solution

For example with the code below.

I have attached a DWG with a small triangle that can be used as "curve to sweep".

 

void cmdSweep()
{
	ads_point    pt;
	ads_name     ent;
	AcDbObjectId objId, pathId;
	Acad::ErrorStatus es;

	if (acedEntSel(_T("\nSelect curve or region to sweep: "), ent, pt) != RTNORM)
		return;

	if (acdbGetObjectId(objId, ent) != Acad::eOk) //ads_name-->AcDbObjectId
		return;

	if (acedEntSel(_T("\nSelect sweep path: "), ent, pt) != RTNORM)
		return;
	if (acdbGetObjectId(pathId, ent) != Acad::eOk) //ads_name-->AcDbObjectId
		return;

	AcDbDatabase* pDB = objId.database();
	AcDb3dSolid* solid = new AcDb3dSolid;
	AcDbEntity* pSweepEnt;
	AcDbCurve* path;
	if ((es = acdbOpenObject(path, pathId, AcDb::kForRead)) == Acad::eOk)
	{
		if ((es = acdbOpenObject(pSweepEnt, objId, AcDb::kForRead)) == Acad::eOk)
		{
			AcDbSweepOptions sweepOpts;
			sweepOpts.setAlignStart(true);
			sweepOpts.setMiterOption(AcDbSweepOptions::kDefaultMiter);
			solid->setDatabaseDefaults(pDB);
			es = solid->createSweptSolid(pSweepEnt, path, sweepOpts);
			if (!es)
			{
				es = postToDb(solid, pSweepEnt->database());
				if (!es)
					solid->close();
				else
					delete solid;
			}

			pSweepEnt->close();
		}
		path->close();
	}	
}

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;
}

 


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

Message 3 of 8

it
Participant
Participant

Hi Thomas,
The sample code you provided solved my problem, thanks a lot.

Also, I need to continue my development, I have been looking in the forums, how to use objectARX to develop a function that does the same as the "FLATSHOT" command, it seems difficult to achieve.

I tried to use SendCommand to trigger the "FLATSHOT" command, but it always pops up the dialog, other than that, I didn't find any relevant information, do you have a better way?

0 Likes
Message 4 of 8

tbrammer
Advisor
Advisor

You might take a look at the "HLR API" (HLR=Hidden Line Removal): <ObjectARX>\utils\HlrApi. See the sample there.

 

For AcDb3dSolid, AcDbSurface, AcDbBody, and AcDbRegion entities you can also use AcDbSection : Create an AcDbSection object with a section plane parallel to the XY plane and above the scene you want to take a flatshot from. Use the method

Acad::ErrorStatus AcDbSection::generateSectionGeometry(
	const AcArray<AcDbEntity*>& entset,       // input entities
	AcArray<AcDbEntity*>& intBoundaryEnts,    // out
	AcArray<AcDbEntity*>& intFillEnts,        // out
	AcArray<AcDbEntity*>& backgroundEnts,     // out
	AcArray<AcDbEntity*>& foregroundEnts,     // out
	AcArray<AcDbEntity*>& curveTangencyEnts   // out
) const;

 


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

0 Likes
Message 5 of 8

infrabimtds
Participant
Participant

Hi Thomas,

I am new at objectarx. I tried using your code rebuild on vs2019 but no success.

Before that I have successfully created text and line . Thank.

VS2019 reports the following errors: Screenshot 2022-08-11 100232.png

0 Likes
Message 6 of 8

tbrammer
Advisor
Advisor

Make sure that your project links to acgeoment.lib.

(Project settings->Linker->Input->Additional dependencies)


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

Message 7 of 8

tbrammer
Advisor
Advisor

Note: I used this tool to create the attached <libname>.h files for the <libname>.lib files in <ARX>\lib-x64.

Each <libname>.h file include the names all functions and symbols that <libname>.lib exports. So I can easily find out which ARX lib must be included to fix an unresolved external.


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

Message 8 of 8

infrabimtds
Participant
Participant
Thank you very much. I have solved the problem.
0 Likes