<?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 Insert Library element (MEP) to the model in GDL</title>
    <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290531#M5470</link>
    <description>&lt;DIV class="actalk-migrated-content"&gt;&lt;R&gt;Hi there!&lt;BR /&gt;
&lt;BR /&gt;
I'm very new to Archicad development (and c++ too), please be patient with me.&lt;BR /&gt;
&lt;BR /&gt;
So my main goal is to load a a csv/txt file and based on that i want to place MEP models like pipes, ducts, other gdl object from library.&lt;BR /&gt;
&lt;BR /&gt;
I tried to simply insert an element, but i'm not sure what should i define.&lt;BR /&gt;

&lt;PRE&gt;			//initalize element/memo
			API_Element* element;
			API_ObjectType obj;
			API_ElementMemo* elementMemo;
			//API_AddParType** parType;
			elementMemo=new API_ElementMemo;
			element=new API_Element;
			//element pointer
			element-&amp;gt;header.typeID=API_ObjectID;
			element-&amp;gt;header.floorInd=0;
			element-&amp;gt;header.hasMemo=false;
			//initialize obj
			obj=element-&amp;gt;object;
			//set obj paramter
			obj.angle=0;
			obj.pos.x=0;
			obj.pos.y=0;
			obj.level=1;
			obj.libInd=1;
			obj.ltypeInd=1;
			obj.pen=1;
			
			
			//write back new object params
			element-&amp;gt;object=obj;
			
			//create element
			err=ACAPI_Element_Create(element,elementMemo);
			WriteReport("Element_Create",err);&lt;/PRE&gt;

this gives me &lt;PRE&gt;APIERR_BADINDEX	-2130313114	81060066	The passed index is out of range.&lt;/PRE&gt; error.&lt;BR /&gt;
So my guess is that i didn't specify correctly one of the ID, index, or something. So i tried to find the mep library and inside that find the duct element to place that. I could find he libraryInfo, but after that i'm stuck, is there any function to find library parts, and then place that?&lt;BR /&gt;

&lt;PRE&gt;			GSErrCode err;

			//get loaded libraries
			GS::Array&amp;lt;API_LibraryInfo&amp;gt; activeLibs;
			Int32 embeddedLibraryIndex;
			err=ACAPI_Environment(APIEnv_GetLibrariesID,&amp;amp;activeLibs,&amp;amp;embeddedLibraryIndex);
			if(err!=NoError){
				WriteReport("GetLibrariesID",err);
			}
			//Loop through libraries and find mep library
			API_LibraryInfo libraryInfo;
			GS::UniString libraryName;
			for (UInt32 i = 0; i &amp;lt; activeLibs.GetSize(); i++) {
				libraryName=activeLibs&lt;I&gt;.name;
				if(libraryName.Contains("MEP Modeler.apx")){
					//Found MEP library
					ACAPI_WriteReport(libraryName.ToCStr(),true);
				}
				
			}&lt;/I&gt;&lt;/PRE&gt;

&lt;BR /&gt;
There migth be  lot of mistakes in the function usage and in c++ syntax also. Please guide me where to start what functions do i need to place a MEP element, I'll try my best to found out how to use them.&lt;/R&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 23 May 2023 14:37:19 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-05-23T14:37:19Z</dc:date>
    <item>
      <title>Insert Library element (MEP) to the model</title>
      <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290531#M5470</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;&lt;R&gt;Hi there!&lt;BR /&gt;
&lt;BR /&gt;
I'm very new to Archicad development (and c++ too), please be patient with me.&lt;BR /&gt;
&lt;BR /&gt;
So my main goal is to load a a csv/txt file and based on that i want to place MEP models like pipes, ducts, other gdl object from library.&lt;BR /&gt;
&lt;BR /&gt;
I tried to simply insert an element, but i'm not sure what should i define.&lt;BR /&gt;

&lt;PRE&gt;			//initalize element/memo
			API_Element* element;
			API_ObjectType obj;
			API_ElementMemo* elementMemo;
			//API_AddParType** parType;
			elementMemo=new API_ElementMemo;
			element=new API_Element;
			//element pointer
			element-&amp;gt;header.typeID=API_ObjectID;
			element-&amp;gt;header.floorInd=0;
			element-&amp;gt;header.hasMemo=false;
			//initialize obj
			obj=element-&amp;gt;object;
			//set obj paramter
			obj.angle=0;
			obj.pos.x=0;
			obj.pos.y=0;
			obj.level=1;
			obj.libInd=1;
			obj.ltypeInd=1;
			obj.pen=1;
			
			
			//write back new object params
			element-&amp;gt;object=obj;
			
			//create element
			err=ACAPI_Element_Create(element,elementMemo);
			WriteReport("Element_Create",err);&lt;/PRE&gt;

this gives me &lt;PRE&gt;APIERR_BADINDEX	-2130313114	81060066	The passed index is out of range.&lt;/PRE&gt; error.&lt;BR /&gt;
So my guess is that i didn't specify correctly one of the ID, index, or something. So i tried to find the mep library and inside that find the duct element to place that. I could find he libraryInfo, but after that i'm stuck, is there any function to find library parts, and then place that?&lt;BR /&gt;

&lt;PRE&gt;			GSErrCode err;

			//get loaded libraries
			GS::Array&amp;lt;API_LibraryInfo&amp;gt; activeLibs;
			Int32 embeddedLibraryIndex;
			err=ACAPI_Environment(APIEnv_GetLibrariesID,&amp;amp;activeLibs,&amp;amp;embeddedLibraryIndex);
			if(err!=NoError){
				WriteReport("GetLibrariesID",err);
			}
			//Loop through libraries and find mep library
			API_LibraryInfo libraryInfo;
			GS::UniString libraryName;
			for (UInt32 i = 0; i &amp;lt; activeLibs.GetSize(); i++) {
				libraryName=activeLibs&lt;I&gt;.name;
				if(libraryName.Contains("MEP Modeler.apx")){
					//Found MEP library
					ACAPI_WriteReport(libraryName.ToCStr(),true);
				}
				
			}&lt;/I&gt;&lt;/PRE&gt;

&lt;BR /&gt;
There migth be  lot of mistakes in the function usage and in c++ syntax also. Please guide me where to start what functions do i need to place a MEP element, I'll try my best to found out how to use them.&lt;/R&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 23 May 2023 14:37:19 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290531#M5470</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-23T14:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Library element (MEP) to the model</title>
      <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290532#M5471</link>
      <description>I think you're getting in over your head. The opening sections of the API documentation say right up front: &lt;BLOCKQUOTE&gt;&lt;B&gt;Who can do API development?&lt;/B&gt;&lt;BR /&gt;
API developers have to be experienced in C or C++ programming language&lt;/BLOCKQUOTE&gt;
If you don't have that experience, a lot of time is going to be spent cleaning up basic programming errors. I'd recommend the following actions:&lt;BR /&gt;
&lt;BR /&gt;
1) Study C++. There are many good resources out there.&lt;BR /&gt;
2) Read at least the main sections of the API documentation&lt;BR /&gt;
3) Explore some of the examples that seem relevant to your development.&lt;BR /&gt;
&lt;BR /&gt;
You'll save yourself a lot of time energy if you get a good grasp of the fundamentals first.</description>
      <pubDate>Fri, 11 May 2018 22:43:05 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290532#M5471</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2018-05-11T22:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Library element (MEP) to the model</title>
      <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290533#M5472</link>
      <description>You are right, i didn't find the examples at first. From there i was able to do more, but now i have somthing else. Here is what i did&lt;BR /&gt;
1. Loop through library elements to get the correct ElementTypeID,ElementVariationID,ObjectTypeID (working)&lt;BR /&gt;
2. Initialize the element with the previously found variables (working)
&lt;PRE&gt;element.header.typeID=toolboxItemPipe.typeID; //ElementTypeID
element.header.variationID=toolboxItemPipe.variationID; //VariationTypeID
element.object.libInd=libIndPipe; //library index&lt;/PRE&gt;
3. Get the default memo for the initialized element (NoError)
&lt;PRE&gt;err=ACAPI_Element_GetDefaults(&amp;amp;element,&amp;amp;memo);&lt;/PRE&gt;
4. Verify the memo additional parameters and those looks just fine. DumpParameters implementation from the Docs. (Working)
&lt;PRE&gt;DumpParameters(element.object.libInd,libPart_Pipe.typeID)&lt;/PRE&gt;

5. And here is problem i try to create the element with these initialized parameter, but it gives me an error.
&lt;PRE&gt;err=ACAPI_Element_Create(&amp;amp;element,&amp;amp;memo);
APIERR_REFUSEDCMD	-2130312312	81060388	The passed identifier is not subject to the operation.
&lt;/PRE&gt;

Here is my whole code:
&lt;PRE&gt;			API_LibPart  libPart;
			API_LibPart  libPart_Pipe={};
			API_LibPart  libPart_PipeBend={};
			API_ToolBoxItem toolboxItemPipe={},toolboxItemPipeBend={};
			Int32        i, count,libIndPipe=0,libIndPipeBend=0;
			GSErrCode    err;
			GS::UniString libPartName;


			//Found out which library elements ID for mep elements...
			err = ACAPI_LibPart_GetNum (&amp;amp;count);
			if (!err) {
				for (i = 1; i &amp;lt;= count; i++) {
					BNZeroMemory (&amp;amp;libPart, sizeof (API_LibPart));
					libPart.index = i;
					err = ACAPI_LibPart_Get (&amp;amp;libPart);
					if (!err) {
						libPartName="Pipe Straight 20";
						if(GS::UniString (libPart.docu_UName)==libPartName){
							libPart_Pipe=libPart;
							libIndPipe=i;
							err=ACAPI_Goodies(APIAny_GetLibPartToolVariationID,&amp;amp;libPart,&amp;amp;toolboxItemPipe);
							if(err){
								WriteReport("APIAny_GetLibPartToolVariationID",err);
							}else{
								WriteReport("toolboxItemPipe.typeID",toolboxItemPipe.typeID);
								WriteReport("toolboxItemPipe.variationID",toolboxItemPipe.variationID);
							}
						}
						libPartName="Pipe Bend 20";
						if(GS::UniString (libPart.docu_UName)==libPartName){
							libPart_PipeBend=libPart;
							libIndPipeBend=i;
							err=ACAPI_Goodies(APIAny_GetLibPartToolVariationID,&amp;amp;libPart,&amp;amp;toolboxItemPipeBend);
							if(err){
								WriteReport("APIAny_GetLibPartToolVariationID",err);
							}else{
								WriteReport("toolboxItemPipeBend.typeID",toolboxItemPipeBend.typeID);
								WriteReport("toolboxItemPipeBend.variationID",toolboxItemPipeBend.variationID);
							}
						}
					}
						if (libPart.location != nullptr)
							delete libPart.location;
				}
			}
			
			//Define element
			API_Element element;
			API_ElementMemo memo;

			//TODO for cycle to read data from CSV line by line

			//Clear element, memo
			BNZeroMemory (&amp;amp;element, sizeof (API_Element));
			BNZeroMemory (&amp;amp;memo, sizeof (API_ElementMemo));
			
			//initialize element.header
			element.header.typeID=toolboxItemPipe.typeID; //ElementTypeID
			element.header.variationID=toolboxItemPipe.variationID; //VariationTypeID
			element.header.floorInd=0;
			element.header.hasMemo=true;
			
			//initialize element.object
			element.object.libInd=libIndPipe; //library index
			/*element.object.level=0; //height from the floor
			element.object.pos.x=0;
			element.object.pos.y=0;
			element.object.angle=0; //element angle
			*/
			WriteReport("element.object.libInd",element.object.libInd);

			//Get memo Defaults 
			err=ACAPI_Element_GetDefaults(&amp;amp;element,&amp;amp;memo);
			if(!err){
				//Element_GetDefaults was successfull
				//Get default parameters
				double a,b;
				Int32 parCount;
				API_AddParType **addPars=nullptr;
				err=ACAPI_LibPart_GetParams(libIndPipe,&amp;amp;a,&amp;amp;b,&amp;amp;parCount,&amp;amp;addPars);
				if(!err){
					WriteReport("Parameters count",parCount);
					//write default parameters to memo
					memo.params=addPars;
					//parCount=1;
					//DumpParameters(element.object.libInd,libPart_Pipe.typeID);
					for(i=0;i&amp;lt;parCount;i++){
						
			        if ((*memo.params)&lt;I&gt;.typeMod == API_ParSimple) {
						DumpOneParam ((*memo.params)&lt;I&gt;.typeID, (*memo.params)&lt;I&gt;.name, (*memo.params)&lt;I&gt;.flags,
				(*memo.params)&lt;I&gt;.value.real, (*memo.params)&lt;I&gt;.value.uStr,
                          0,0);
						}
					}
					//try to create the element
					err=ACAPI_Element_Create(&amp;amp;element,&amp;amp;memo);
					if(!err){
						//element successfully created
						ACAPI_WriteReport("Element created",false);
					}else{
						WriteReport("Element_Create",err);
					}
				}else{
						WriteReport("ACAPI_LibPart_GetParams",err);
				}
			}else{
				WriteReport("Element_GetDefaults",err);
			}
			ACAPI_DisposeElemMemoHdls (&amp;amp;memo);&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 May 2018 19:41:26 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290533#M5472</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-13T19:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Library element (MEP) to the model</title>
      <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290534#M5473</link>
      <description>Have you started an undo session for this operation? If not, 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;ACAPI_CallUndoableCommand&lt;E&gt;&lt;/E&gt;</description>
      <pubDate>Sun, 13 May 2018 20:08:43 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290534#M5473</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2018-05-13T20:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Library element (MEP) to the model</title>
      <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290535#M5474</link>
      <description>Thank you very much that was what i missed.&lt;BR /&gt;
&lt;BR /&gt;
I thought it would be easier after that, but now i have problem with modification of the library element, however it is not giving me any error as it is changed but on the model that did not appear.&lt;BR /&gt;
&lt;BR /&gt;
What i did.&lt;BR /&gt;
1. initialize paramOwner (i want to modify the instance of the element so i set the GUID as well).
&lt;PRE&gt;paramOwner.libInd = element.object.libInd;
paramOwner.typeID = element.header.typeID;
paramOwner.variationID=element.header.variationID;
paramOwner.guid   = element.header.guid;&lt;/PRE&gt;
2. open parameters (NoError)
&lt;PRE&gt;err = ACAPI_Goodies (APIAny_OpenParametersID, &amp;amp;paramOwner, nullptr);&lt;/PRE&gt;
3. Created an array of structure to hold the required parameters, and fill that
&lt;PRE&gt;typedef struct parameter {	char name[32];
							short ID;
							double value;
} parameter;
parameter param[1]={};
strcpy(param[0].name,"MEP_StraightLength"); //that is the parameter name.
param[0].value=2;
param[0].ID=10;
...
&lt;/PRE&gt;

4. Get active parameters (NoError) and change them (NoError).
&lt;PRE&gt;err = ACAPI_Goodies (APIAny_GetActParametersID, &amp;amp;getParams, nullptr);
chgParam.index = param&lt;J&gt;.ID;
CHCopyC (param&lt;J&gt;.name, chgParam.name);
chgParam.realValue = param&lt;J&gt;.value;
									
err = ACAPI_Goodies (APIAny_ChangeAParameterID, &amp;amp;chgParam, nullptr);
&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/PRE&gt;

5. close opened parameters with success. And set memo.params to the new params. clear mask. Looks fine
&lt;PRE&gt;err=ACAPI_Goodies (APIAny_CloseParametersID, nullptr, nullptr);
memo.params = getParams.params;
ACAPI_ELEMENT_MASK_CLEAR(mask);
&lt;/PRE&gt;

6. Call the change with undoable command... It appears on the previous menu but nothing changed on the element... &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_sad.gif" style="display : inline;" /&gt;&lt;BR /&gt;

&lt;PRE&gt;err = ACAPI_CallUndoableCommand ("Change Element",
								[&amp;amp;] () -&amp;gt; GSErrCode {
									return ACAPI_Element_Change(&amp;amp;element, &amp;amp;mask, &amp;amp;memo,0,true);
								});&lt;/PRE&gt;

So I don't know whats wrong. Maybe you know something about this element. I tried to change a length(MEP_StraightLength) i can modify from the GUI, but not from the addon, but there is no error  under runtime...&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your help &lt;IMG src="https://community.graphisoft.com/legacyfs/online/emojis/icon_smile.gif" style="display : inline;" /&gt;</description>
      <pubDate>Mon, 14 May 2018 14:41:41 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290535#M5474</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-14T14:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Library element (MEP) to the model</title>
      <link>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290536#M5475</link>
      <description>Today I revisited my addon and i found out my mistake which was that my memoMask was invalid, because i didn't find any reference to memoMask so i used the default memoMask (0 which may be means nothing).&lt;BR /&gt;
But today i find memoMask's valid parameters on ACAPI_Element_GetMemo function page...&lt;A href="http://archicadapi.graphisoft.com/documentation/acapi_element_getmemo" target="_blank"&gt;&lt;/A&gt;&lt;S&gt;&lt;A href="http://archicadapi.graphisoft.com/documentation/acapi_element_getmemo" target="_blank"&gt;&lt;/A&gt;&lt;A href="&amp;lt;/s&amp;gt;&amp;lt;LINK_TEXT text=&amp;quot;http://archicadapi.graphisoft.com/docum ... nt_getmemo&amp;quot;&amp;gt;http://archicadapi.graphisoft.com/documentation/acapi_element_getmemo&amp;lt;/LINK_TEXT&amp;gt;&amp;lt;e&amp;gt;"&gt;&lt;/A&gt;&lt;/S&gt;&lt;LINK_TEXT text="http://archicadapi.graphisoft.com/docum ... nt_getmemo"&gt;http://archicadapi.graphisoft.com/documentation/acapi_element_getmemo&lt;/LINK_TEXT&gt;&lt;E&gt;&lt;/E&gt;&lt;BR /&gt;
&lt;BR /&gt;
Now it is working like charm.</description>
      <pubDate>Tue, 12 Jun 2018 08:58:07 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/GDL/Insert-Library-element-MEP-to-the-model/m-p/290536#M5475</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-12T08:58:07Z</dc:date>
    </item>
  </channel>
</rss>

