[ACAPI_LibPart_UpdateSection] doesnt work like I expect?
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2009-05-14
01:07 PM
- last edited on
2023-05-23
04:40 PM
by
Rubia Torres
2009-05-14
01:07 PM
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 (§ion, sizeof (API_LibPartSection)); section.sectType = API_SectComText; ACAPI_LibPart_NewSection (§ion); CHCopyC(hpgl.GetDescription().c_str(), buffer); ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer); ACAPI_LibPart_EndSection (); // Master script section BNZeroMemory (§ion, sizeof (API_LibPartSection)); section.sectType = API_Sect1DScript; ACAPI_LibPart_NewSection (§ion); buffer[0] = '\0'; ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer); ACAPI_LibPart_EndSection (); // 3D script section BNZeroMemory (§ion, sizeof (API_LibPartSection)); section.sectType = API_Sect3DScript; ACAPI_LibPart_NewSection (§ion); buffer[0] = '\0'; ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer); ACAPI_LibPart_EndSection (); // 2D script section BNZeroMemory (§ion, sizeof (API_LibPartSection)); section.sectType = API_Sect2DScript; ACAPI_LibPart_NewSection (§ion); 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 (§ion, 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, §ionHdl); API_LibPartDetails details; BNZeroMemory (&details, sizeof (API_LibPartDetails)); err = ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details); err = ACAPI_LibPart_UpdateSection(libPart.index, §ion, sectionHdl, NULL); if(err == NoError) { err = ACAPI_LibPart_Save(&libPart); if(err == NoError) { } else { // I HAVE ERROR HERE } } else { // NO ERROR } BMKillHandle(§ionHdl); } 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, §ionHdl); API_LibPartDetails details; BNZeroMemory (&details, sizeof (API_LibPartDetails)); ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details); ACAPI_LibPart_AddSection (§ion, sectionHdl, NULL); BMKillHandle (§ionHdl); // 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
Labels:
- Labels:
-
Library (GDL)
5 REPLIES 5
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2009-05-15 01:35 PM
2009-05-15
01:35 PM
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:
Regards,
Maciek
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 (§ion, sizeof (API_LibPartSection)); section.sectType = API_Sect2DScript; GSHandle sectionHdl = NULL; GS::UniString us; err = ACAPI_LibPart_GetSection(libPart.index, §ion, §ionHdl, &us); //BNZeroMemory (§ion, sizeof (API_LibPartSection)); //section.sectType = API_Sect2DScript; //ACAPI_LibPart_NewSection (§ion); //err = ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer); //ACAPI_LibPart_EndSection (); err = ACAPI_LibPart_UpdateSection(libPart.index, §ion, &buffer /*sectionHdl*/, &us); BNZeroMemory (§ion, sizeof (API_LibPartSection)); section.sectType = API_Sect2DScript; BMKillHandle(§ionHdl); sectionHdl = NULL; err = ACAPI_LibPart_GetSection(libPart.index, §ion, §ionHdl, 0); CHCopyC(os.str().c_str(), buffer); BMKillHandle(§ionHdl); if(err == NoError) { err = ACAPI_LibPart_Save(&libPart); if(err == NoError) { } else { // I HAVE ERROR HERE } } else { // NO ERROR }
Regards,
Maciek

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2009-05-15 07:14 PM
2009-05-15
07:14 PM
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
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

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2009-05-15 07:29 PM
2009-05-15
07:29 PM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2009-05-16 01:56 PM
2009-05-16
01:56 PM
bamboos wrote:Sorry, I'm struggling to understand what you are trying to do. Take a look at
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.
Ralph Wessel BArch
Central Innovation
Central Innovation
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2009-05-18 09:33 AM
2009-05-18
09:33 AM
Hello,
APIEnv_OverwriteLibPartID is exactly what i needed thanks very much.
Regards,
Maciek
APIEnv_OverwriteLibPartID is exactly what i needed thanks very much.
Regards,
Maciek