<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [ACAPI_LibPart_UpdateSection] doesnt work like I expect? in GDL</title>
    <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133819#M5145</link>
    <description>Hello,  &lt;BR /&gt;
  &lt;BR /&gt;
APIEnv_OverwriteLibPartID is exactly what i needed thanks very much.  &lt;BR /&gt;
  &lt;BR /&gt;
Regards,  &lt;BR /&gt;
Maciek</description>
    <pubDate>Mon, 18 May 2009 07:33:15 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-05-18T07:33:15Z</dc:date>
    <item>
      <title>[ACAPI_LibPart_UpdateSection] doesnt work like I expect?</title>
      <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133814#M5140</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;&lt;R&gt;Hello,  &lt;BR /&gt;
  &lt;BR /&gt;
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:  &lt;BR /&gt;
  &lt;BR /&gt;
some code:  &lt;BR /&gt;
  &lt;BR /&gt;
The body of LibPart:  
&lt;PRE&gt;API_LibPartSection CreateSection(const HPGLPattern&amp;lt;double, GS::Guid&amp;gt; &amp;amp; hpgl)  
{  
	char buffer[1000];  
  
	API_LibPartSection section;  
  
	BoundingBox&amp;lt;double&amp;gt; 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 (&amp;amp;section, sizeof (API_LibPartSection));  
	section.sectType = API_SectComText;  
	ACAPI_LibPart_NewSection (&amp;amp;section);  
	CHCopyC(hpgl.GetDescription().c_str(), buffer);  
	ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);  
	ACAPI_LibPart_EndSection ();  
  
	// Master script section  
	BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection));  
	section.sectType = API_Sect1DScript;  
	ACAPI_LibPart_NewSection (&amp;amp;section);  
	buffer[0] = '\0';  
	ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);  
	ACAPI_LibPart_EndSection ();  
  
	// 3D script section  
	BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection));  
	section.sectType = API_Sect3DScript;  
	ACAPI_LibPart_NewSection (&amp;amp;section);  
	buffer[0] = '\0';  
	ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer);  
	ACAPI_LibPart_EndSection ();  
  
	// 2D script section  
	BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection));  
	section.sectType = API_Sect2DScript;  
	ACAPI_LibPart_NewSection (&amp;amp;section);  
  
	for(size_t i = 0; i &amp;lt; hpgl.GetSegments().size(); ++i)  
	{  
		std::ostringstream os;  
		const Segment2&amp;lt;double, GS::Guid&amp;gt; &amp;amp; segment = hpgl.GetSegments()&lt;I&gt;;  
		os &amp;lt;&amp;lt; "LINE2 " &amp;lt;&amp;lt; segment.p0()[0] - box.minx() &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; segment.p0()[1] - box.miny() &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; segment.p1()[0] - box.minx() &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; segment.p1()[1] - box.miny() &amp;lt;&amp;lt; std::endl;  
		CHCopyC(os.str().c_str(), buffer);  
		ACAPI_LibPart_WriteSection(Strlen32 (buffer), buffer);  
	}  
  
	for(size_t i = 0; i &amp;lt; hpgl.GetArcs().size(); ++i)  
	{  
		std::ostringstream os;  
		const Arc2&amp;lt;double, GS::Guid&amp;gt; &amp;amp; arc = hpgl.GetArcs()&lt;I&gt;;  
		os &amp;lt;&amp;lt; "ARC2 " &amp;lt;&amp;lt; arc.p0()[0] - box.minx() &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; arc.p0()[1] - box.miny() &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; arc.radius() &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; (arc.startAngle() * 180) / M_PI &amp;lt;&amp;lt; ", " &amp;lt;&amp;lt; (arc.endAngle() * 180) / M_PI &amp;lt;&amp;lt; std::endl;  
		CHCopyC(os.str().c_str(), buffer);  
		ACAPI_LibPart_WriteSection(Strlen32 (buffer), buffer);  
	}  
  
	ACAPI_LibPart_EndSection ();  
  
	// Parameters section  
	BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection));  
	section.sectType = API_SectParamDef;  
  
	return section;  
}&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;  &lt;BR /&gt;
  &lt;BR /&gt;
The Create/Update procedure:  &lt;BR /&gt;
  &lt;BR /&gt;
  
&lt;PRE&gt;API_LibPart CreateGDLFromHPGL(const HPGLPattern&amp;lt;double, GS::Guid&amp;gt; &amp;amp; hpgl)  
{  
	API_LibPart libPart;  
  
	GSErrCode err = NoError;  
  
	BoundingBox&amp;lt;double&amp;gt; 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 (&amp;amp;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(&amp;amp;libPart, false);  
	if(err == NoError) // update needed   
	{  
		API_LibPartSection section = CreateSection(hpgl);  
  
		GSHandle sectionHdl = NULL;  
		err = ACAPI_LibPart_GetSect_ParamDef (&amp;amp;libPart, NULL, &amp;amp;aa, &amp;amp;bb, NULL, &amp;amp;sectionHdl);  
  
		API_LibPartDetails details;  
		BNZeroMemory (&amp;amp;details, sizeof (API_LibPartDetails));  
		err = ACAPI_LibPart_SetDetails_ParamDef (&amp;amp;libPart, sectionHdl, &amp;amp;details);			  
		err = ACAPI_LibPart_UpdateSection(libPart.index, &amp;amp;section, sectionHdl, NULL);  
		  
		if(err == NoError)  
		{  
			err = ACAPI_LibPart_Save(&amp;amp;libPart);  
			if(err == NoError)  
			{  
			}  
			else  
			{  
				&lt;FONT color="red"&gt;// I HAVE ERROR HERE &lt;/FONT&gt; 
			}  
		}  
		else  
		{  
			// NO ERROR  
		}  
		BMKillHandle(&amp;amp;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 = &amp;amp;folderLoc;  
		err = ACAPI_LibPart_Create (&amp;amp;libPart);  
		  
		if (err == NoError) {  
			  
			API_LibPartSection section = CreateSection(hpgl);  
  
			GSHandle sectionHdl = NULL;  
			ACAPI_LibPart_GetSect_ParamDef (&amp;amp;libPart, NULL, &amp;amp;aa, &amp;amp;bb, NULL, &amp;amp;sectionHdl);  
  
			API_LibPartDetails details;  
			BNZeroMemory (&amp;amp;details, sizeof (API_LibPartDetails));  
			ACAPI_LibPart_SetDetails_ParamDef (&amp;amp;libPart, sectionHdl, &amp;amp;details);  
  
			ACAPI_LibPart_AddSection (&amp;amp;section, sectionHdl, NULL);  
			BMKillHandle (&amp;amp;sectionHdl);  
  
			// Save the constructed library part  
			if (err == NoError)  
				err = ACAPI_LibPart_Save (&amp;amp;libPart);  
  
			if (libPart.location != NULL) {  
				delete libPart.location;  
				libPart.location = NULL;  
			}  
		}  
	}  
  
	return libPart;   
}&lt;/PRE&gt;  &lt;BR /&gt;
  &lt;BR /&gt;
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.  &lt;BR /&gt;
  &lt;BR /&gt;
I try to figure out how to do it, and i can't.  &lt;BR /&gt;
  &lt;BR /&gt;
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.  &lt;BR /&gt;
  &lt;BR /&gt;
help.  &lt;BR /&gt;
  &lt;BR /&gt;
Regards,  &lt;BR /&gt;
Maciek&lt;/R&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 23 May 2023 14:40:03 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133814#M5140</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-23T14:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: [ACAPI_LibPart_UpdateSection] doesnt work like I expect?</title>
      <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133815#M5141</link>
      <description>Hello. &lt;BR /&gt;
 &lt;BR /&gt;
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. &lt;BR /&gt;
 &lt;BR /&gt;
Please help or i will lose all my hairs &lt;span class="lia-unicode-emoji" title=":grinning_squinting_face:"&gt;😆&lt;/span&gt; &lt;BR /&gt;
 &lt;BR /&gt;
The newest code i created: &lt;BR /&gt;
 
&lt;PRE&gt;char buf[1000]; 
char * buffer = buf; 
 
std::ostringstream os; 
os &amp;lt;&amp;lt; "LINE2 0, 0, 10, 10" &amp;lt;&amp;lt; std::endl; 
CHCopyC(os.str().c_str(), buffer); 
API_LibPartSection section; 
 
BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection)); 
section.sectType = API_Sect2DScript; 
 
GSHandle sectionHdl = NULL; 
GS::UniString us; 
err = ACAPI_LibPart_GetSection(libPart.index, &amp;amp;section, &amp;amp;sectionHdl, &amp;amp;us); 
//BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection)); 
//section.sectType = API_Sect2DScript; 
//ACAPI_LibPart_NewSection (&amp;amp;section); 
//err = ACAPI_LibPart_WriteSection (Strlen32 (buffer), buffer); 
//ACAPI_LibPart_EndSection (); 
 
err = ACAPI_LibPart_UpdateSection(libPart.index, &amp;amp;section, &amp;amp;buffer /*sectionHdl*/, &amp;amp;us); 
 
BNZeroMemory (&amp;amp;section, sizeof (API_LibPartSection)); 
section.sectType = API_Sect2DScript; 
 
BMKillHandle(&amp;amp;sectionHdl); 
sectionHdl = NULL; 
err = ACAPI_LibPart_GetSection(libPart.index, &amp;amp;section, &amp;amp;sectionHdl, 0); 
CHCopyC(os.str().c_str(), buffer); 
 
BMKillHandle(&amp;amp;sectionHdl); 
if(err == NoError) 
{ 
	err = ACAPI_LibPart_Save(&amp;amp;libPart); 
	if(err == NoError) 
	{ 
	} 
	else 
	{ 
		// I HAVE ERROR HERE 
	} 
} 
else 
{ 
	// NO ERROR 
}&lt;/PRE&gt; &lt;BR /&gt;
 &lt;BR /&gt;
Regards, &lt;BR /&gt;
Maciek</description>
      <pubDate>Fri, 15 May 2009 11:35:58 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133815#M5141</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-05-15T11:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: [ACAPI_LibPart_UpdateSection] doesnt work like I expect?</title>
      <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133816#M5142</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
AFAIR,&lt;BR /&gt;
You need ACAPI_LibPart_Save only for a new lib part (ACAPI_LibPart_Create).&lt;BR /&gt;
For updating just ACAPI_LibPart_UpdateSection.&lt;BR /&gt;
&lt;BR /&gt;
PS: But I dont understand what mean exactly "during the document is open". So I am not sure I understood your issue.&lt;BR /&gt;
&lt;BR /&gt;
Oleg</description>
      <pubDate>Fri, 15 May 2009 17:14:12 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133816#M5142</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2009-05-15T17:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: [ACAPI_LibPart_UpdateSection] doesnt work like I expect?</title>
      <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133817#M5143</link>
      <description>Addition,&lt;BR /&gt;
&lt;BR /&gt;
After I saw your code more closely, I think it is wrong.&lt;BR /&gt;
&lt;BR /&gt;
ACAPI_LibPart_Create&lt;BR /&gt;
ACAPI_LibPart_AddSection&lt;BR /&gt;
ACAPI_LibPart_NewSection&lt;BR /&gt;
ACAPI_LibPart_WriteSection&lt;BR /&gt;
ACAPI_LibPart_EndSection&lt;BR /&gt;
ACAPI_LibPart_Save&lt;BR /&gt;
All are ONLY for creating a new lib part.&lt;BR /&gt;
&lt;BR /&gt;
ACAPI_LibPart_UpdateSection for an existing lib part.&lt;BR /&gt;
So your function CreateSection can not be used fot updating.&lt;BR /&gt;
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.&lt;BR /&gt;
&lt;BR /&gt;
Oleg</description>
      <pubDate>Fri, 15 May 2009 17:29:38 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133817#M5143</guid>
      <dc:creator>Oleg</dc:creator>
      <dc:date>2009-05-15T17:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: [ACAPI_LibPart_UpdateSection] doesnt work like I expect?</title>
      <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133818#M5144</link>
      <description>&lt;BLOCKQUOTE&gt;bamboos wrote:&lt;BR /&gt;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.&lt;/BLOCKQUOTE&gt;
Sorry, I'm struggling to understand what you are trying to do. Take a look at &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt; APIEnv_OverwriteLibPartID&lt;E&gt;&lt;/E&gt; - could this be what you're looking for?</description>
      <pubDate>Sat, 16 May 2009 11:56:48 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133818#M5144</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2009-05-16T11:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: [ACAPI_LibPart_UpdateSection] doesnt work like I expect?</title>
      <link>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133819#M5145</link>
      <description>Hello,  &lt;BR /&gt;
  &lt;BR /&gt;
APIEnv_OverwriteLibPartID is exactly what i needed thanks very much.  &lt;BR /&gt;
  &lt;BR /&gt;
Regards,  &lt;BR /&gt;
Maciek</description>
      <pubDate>Mon, 18 May 2009 07:33:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/ACAPI-LibPart-UpdateSection-doesnt-work-like-I-expect/m-p/133819#M5145</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-05-18T07:33:15Z</dc:date>
    </item>
  </channel>
</rss>

