GDL
About building parametric objects with GDL.

[ACAPI_LibPart_UpdateSection] doesnt work like I expect?

Anonymous
Not applicable
Hello,

I've created LibPart from code based on elements generated from outside source (HPGL file). The problem is that i need to modify that element on the fly and it doesn't work:

some code:

The body of LibPart:
API_LibPartSection CreateSection(const HPGLPattern<double, GS::Guid> & hpgl)  
{  
	char buffer[1000];  
  
	API_LibPartSection section;  
  
	BoundingBox<double> box;  
	box.AddSegments(hpgl.GetSegments().begin(), hpgl.GetSegments().end());  
	box.AddArcs(hpgl.GetArcs().begin(), hpgl.GetArcs().end());  
  
	double aa = box.maxx() - box.minx();  
	double bb = box.maxy() - box.miny();  
	  
	// Comment script section  
	BNZeroMemory (&section, sizeof (API_LibPartSection));  
	section.sectType = API_SectComText;  
	ACAPI_LibPart_NewSection (&section);  
	CHCopyC(hpgl.GetDescription().c_str(), buffer);  
	ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);  
	ACAPI_LibPart_EndSection ();  
  
	// Master script section  
	BNZeroMemory (&section, sizeof (API_LibPartSection));  
	section.sectType = API_Sect1DScript;  
	ACAPI_LibPart_NewSection (&section);  
	buffer[0] = '\0';  
	ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);  
	ACAPI_LibPart_EndSection ();  
  
	// 3D script section  
	BNZeroMemory (&section, sizeof (API_LibPartSection));  
	section.sectType = API_Sect3DScript;  
	ACAPI_LibPart_NewSection (&section);  
	buffer[0] = '\0';  
	ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);  
	ACAPI_LibPart_EndSection ();  
  
	// 2D script section  
	BNZeroMemory (&section, sizeof (API_LibPartSection));  
	section.sectType = API_Sect2DScript;  
	ACAPI_LibPart_NewSection (&section);  
  
	for(size_t i = 0; i < hpgl.GetSegments().size(); ++i)  
	{  
		std::ostringstream os;  
		const Segment2<double, GS::Guid> & segment = hpgl.GetSegments();  
		os << "LINE2 " << segment.p0()[0] - box.minx() << ", " << segment.p0()[1] - box.miny() << ", " << segment.p1()[0] - box.minx() << ", " << segment.p1()[1] - box.miny() << std::endl;  
		CHCopyC(os.str().c_str(), buffer);  
		ACAPI_LibPart_WriteSection(Strlen32 (buffer), buffer);  
	}  
  
	for(size_t i = 0; i < hpgl.GetArcs().size(); ++i)  
	{  
		std::ostringstream os;  
		const Arc2<double, GS::Guid> & arc = hpgl.GetArcs();  
		os << "ARC2 " << arc.p0()[0] - box.minx() << ", " << arc.p0()[1] - box.miny() << ", " << arc.radius() << ", " << (arc.startAngle() * 180) / M_PI << ", " << (arc.endAngle() * 180) / M_PI << std::endl;  
		CHCopyC(os.str().c_str(), buffer);  
		ACAPI_LibPart_WriteSection(Strlen32 (buffer), buffer);  
	}  
  
	ACAPI_LibPart_EndSection ();  
  
	// Parameters section  
	BNZeroMemory (&section, sizeof (API_LibPartSection));  
	section.sectType = API_SectParamDef;  
  
	return section;  
}


The Create/Update procedure:

API_LibPart CreateGDLFromHPGL(const HPGLPattern<double, GS::Guid> & hpgl)  
{  
	API_LibPart libPart;  
  
	GSErrCode err = NoError;  
  
	BoundingBox<double> box;  
	box.AddSegments(hpgl.GetSegments().begin(), hpgl.GetSegments().end());  
	box.AddArcs(hpgl.GetArcs().begin(), hpgl.GetArcs().end());  
  
	double aa = box.maxx() - box.minx();  
	double bb = box.maxy() - box.miny();  
  
	BNZeroMemory (&libPart, sizeof (API_LibPart));  
	libPart.typeID = APILib_ObjectID;  
	libPart.isTemplate = false;  
	libPart.isPlaceable = true;  
  
	CHCopyC("{4ABD0A6E-634B-4931-B3AA-9BEE01F39666}-{00000000-0000-0000-0000-000000000000}", libPart.parentUnID);  
	CHANSI2Unicode(hpgl.GetName().c_str(), hpgl.GetName().length(), libPart.docu_UName, API_UniLongNameLen);  
	CHANSI2Unicode(hpgl.GetName().c_str(), hpgl.GetName().length(), libPart.file_UName, API_UniLongNameLen);  
  
	err = ACAPI_LibPart_Search(&libPart, false);  
	if(err == NoError) // update needed   
	{  
		API_LibPartSection section = CreateSection(hpgl);  
  
		GSHandle sectionHdl = NULL;  
		err = ACAPI_LibPart_GetSect_ParamDef (&libPart, NULL, &aa, &bb, NULL, &sectionHdl);  
  
		API_LibPartDetails details;  
		BNZeroMemory (&details, sizeof (API_LibPartDetails));  
		err = ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details);			  
		err = ACAPI_LibPart_UpdateSection(libPart.index, &section, sectionHdl, NULL);  
		  
		if(err == NoError)  
		{  
			err = ACAPI_LibPart_Save(&libPart);  
			if(err == NoError)  
			{  
			}  
			else  
			{  
				// I HAVE ERROR HERE  
			}  
		}  
		else  
		{  
			// NO ERROR  
		}  
		BMKillHandle(&sectionHdl);  
  
	}  
	else // New LibPart needed  
	{  
		IO::Location folderLoc(hpgl.GetDir().c_str());  
		folderLoc.AppendToLocal ("GDL");  
		IO::Folder destFolder (folderLoc, IO::Folder::Create);  
		  
		if (destFolder.GetStatus () != NoError || !destFolder.IsWriteable ())  
			err = APIERR_GENERAL;  
  
		libPart.location = &folderLoc;  
		err = ACAPI_LibPart_Create (&libPart);  
		  
		if (err == NoError) {  
			  
			API_LibPartSection section = CreateSection(hpgl);  
  
			GSHandle sectionHdl = NULL;  
			ACAPI_LibPart_GetSect_ParamDef (&libPart, NULL, &aa, &bb, NULL, &sectionHdl);  
  
			API_LibPartDetails details;  
			BNZeroMemory (&details, sizeof (API_LibPartDetails));  
			ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details);  
  
			ACAPI_LibPart_AddSection (&section, sectionHdl, NULL);  
			BMKillHandle (&sectionHdl);  
  
			// Save the constructed library part  
			if (err == NoError)  
				err = ACAPI_LibPart_Save (&libPart);  
  
			if (libPart.location != NULL) {  
				delete libPart.location;  
				libPart.location = NULL;  
			}  
		}  
	}  
  
	return libPart;   
}


The problem is, that i need to edit LibPart during the document is open. I need to update file with LibPart definition and AC memory, so updated libpart would be shown.

I try to figure out how to do it, and i can't.

I try to delete file and create new libpart instead of updating old one, but then all placed libparts changes to single dot and loading report library shows missing library.

help.

Regards,
Maciek
5 REPLIES 5
Anonymous
Not applicable
Hello.

I've try to update section in multiple ways... and nothing works. Sometimes the ACAPI_LibPart_UpdateSection returns noerror but ACAPI_LibPart_Save returns "General error" (no idea what is wrong). In other way ACAPI_LibPart_UpdateSection gives the "General error" :/:/ and sometimes the "Insufficient memory." error... What is wrong. Could somebody give me w little example how to change the LibPart code during the document is open... Exactly like GDL editor does.

Please help or i will lose all my hairs 😆

The newest code i created:
char buf[1000]; 
char * buffer = buf; 
 
std::ostringstream os; 
os << "LINE2 0, 0, 10, 10" << std::endl; 
CHCopyC(os.str().c_str(), buffer); 
API_LibPartSection section; 
 
BNZeroMemory (&section, sizeof (API_LibPartSection)); 
section.sectType = API_Sect2DScript; 
 
GSHandle sectionHdl = NULL; 
GS::UniString us; 
err = ACAPI_LibPart_GetSection(libPart.index, &section, &sectionHdl, &us); 
//BNZeroMemory (&section, sizeof (API_LibPartSection)); 
//section.sectType = API_Sect2DScript; 
//ACAPI_LibPart_NewSection (&section); 
//err = ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer); 
//ACAPI_LibPart_EndSection (); 
 
err = ACAPI_LibPart_UpdateSection(libPart.index, &section, &buffer /*sectionHdl*/, &us); 
 
BNZeroMemory (&section, sizeof (API_LibPartSection)); 
section.sectType = API_Sect2DScript; 
 
BMKillHandle(&sectionHdl); 
sectionHdl = NULL; 
err = ACAPI_LibPart_GetSection(libPart.index, &section, &sectionHdl, 0); 
CHCopyC(os.str().c_str(), buffer); 
 
BMKillHandle(&sectionHdl); 
if(err == NoError) 
{ 
	err = ACAPI_LibPart_Save(&libPart); 
	if(err == NoError) 
	{ 
	} 
	else 
	{ 
		// I HAVE ERROR HERE 
	} 
} 
else 
{ 
	// NO ERROR 
}


Regards,
Maciek
Oleg
Expert
Hi,

AFAIR,
You need ACAPI_LibPart_Save only for a new lib part (ACAPI_LibPart_Create).
For updating just ACAPI_LibPart_UpdateSection.

PS: But I dont understand what mean exactly "during the document is open". So I am not sure I understood your issue.

Oleg
Oleg
Expert
Addition,

After I saw your code more closely, I think it is wrong.

ACAPI_LibPart_Create
ACAPI_LibPart_AddSection
ACAPI_LibPart_NewSection
ACAPI_LibPart_WriteSection
ACAPI_LibPart_EndSection
ACAPI_LibPart_Save
All are ONLY for creating a new lib part.

ACAPI_LibPart_UpdateSection for an existing lib part.
So your function CreateSection can not be used fot updating.
You need make a Hande which will contains section data and use ACAPI_LibPart_UpdateSection for every section (2d,3d etc) you need to update.

Oleg
Ralph Wessel
Mentor
bamboos wrote:
I've try to update section in multiple ways... and nothing works. Sometimes the ACAPI_LibPart_UpdateSection returns noerror but ACAPI_LibPart_Save returns "General error" (no idea what is wrong). In other way ACAPI_LibPart_UpdateSection gives the "General error" :/:/ and sometimes the "Insufficient memory." error... What is wrong.
Sorry, I'm struggling to understand what you are trying to do. Take a look at APIEnv_OverwriteLibPartID - could this be what you're looking for?
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Hello,

APIEnv_OverwriteLibPartID is exactly what i needed thanks very much.

Regards,
Maciek

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!