BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

How to add and apply an .lcf file?

Anonymous
Not applicable
Hi guys and Happy New Year

Does anybody know how can I add and "Reload & Apply" an .lcf file?
I looked through all API functions and did not find any. In the Library Manager I saw that the default Archicad Library 22 has a corresponding file Archicad Library 22.lcf and it is located in C:\Program Files\Graphisoft\Archicad 22\ . Should I copy my .lcf file there as well and then with some API function add and apply it?
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Sorry, I didn't have enough time to try it, but this should do the trick:
GS::Array<API_LibraryInfo>	libInfo;
if (ACAPI_Environment (APIEnv_GetLibrariesID, &libInfo) == NoError) {
	API_LibraryInfo	li;
	li.location = IO::Location ("<path to the lcf file>");
	libInfo.Push (li);

	ACAPI_Environment (APIEnv_SetLibrariesID, &libInfo);
}

View solution in original post

14 REPLIES 14
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Sorry, I didn't have enough time to try it, but this should do the trick:
GS::Array<API_LibraryInfo>	libInfo;
if (ACAPI_Environment (APIEnv_GetLibrariesID, &libInfo) == NoError) {
	API_LibraryInfo	li;
	li.location = IO::Location ("<path to the lcf file>");
	libInfo.Push (li);

	ACAPI_Environment (APIEnv_SetLibrariesID, &libInfo);
}
Anonymous
Not applicable
It works great!
Thank you very much, Tibor!
Anonymous
Not applicable
And is it possible to create a new property group (ACAPI_Property_CreatePropertyGroup) with properties for an object that I added with the .lcf file or they should be included in the .lcf file?
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
n.mihaylov wrote:
And is it possible to create a new property group (ACAPI_Property_CreatePropertyGroup) with properties for an object that I added with the .lcf file or they should be included in the .lcf file?
Properties are available for certain Classifications. So if a Property Definition is available for a Classification then all elements with the given Classification will have the specified Property.
So of course you can add new Property Groups and new Property Definitions, just make sure to set the 'availability' member of the Property Definitions to the same as your objects' Classification.
Anonymous
Not applicable
Thank you! The perfect guidance for the direction I should start digging
Anonymous
Not applicable
Maybe a last question: what is the proper way to obtain the guid of the element that I imported from the .lcf file (in order to set its properties)? Do I have to get all the elements from that classification (I think I will know it in advance)? All the functions that I found required the element guid as an [in] parameter but I need to get this guid.
Ralph Wessel
Mentor
n.mihaylov wrote:
Maybe a last question: what is the proper way to obtain the guid of the element that I imported from the .lcf file (in order to set its properties)?
An .lcf file doesn't contain elements. It contains library parts (or objects) that describe what will happen if an element is created of that type, e.g. how it will be rendered in 2D or 3D. So you only have an element with a guid when you place an instance of a library part in the project.

If the element is created with the appropriate classification(s), it will automatically bind to the associated properties. I hope that makes sense.

Which functions were you hoping to call with the element guid?
Ralph Wessel BArch
Anonymous
Not applicable
Now I am beginning to understand.
When I create an element and add a new property group with properties for it, for example a wall, it is immediately placed and has these properties (names and values) - this is the current instance. When I draw another wall (new instance) - it also has this property group but the properties have no values and I have to use Pick Up/Inject Parameters from the instance I created with my addon.
If this is the normal flow, then when I import a library object and add properties for its classification (in my case Building Element Proxy but I have to find a way to get it automatically), the object is not placed immediately and when I place an instance of it I will have the properties with no values again, like in the case of a wall, right?

I hoped ACAPI_Element_SetProperties would set the "properties" to the element with "elemGuid".

P.S. The colleague who wrote this addon left before I came and now I am trying to understand what he has done in order to implement the new things that I am asked.
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
n.mihaylov wrote:
When I draw another wall (new instance) - it also has this property group but the properties have no values and I have to use Pick Up/Inject Parameters from the instance I created with my addon.
It's not true that those properties won't have value! Those properties will have the default value of the property.
You can set default value for a property definition and also you can set the default property values for walls in the Wall Default settings.
n.mihaylov wrote:
If this is the normal flow, then when I import a library object and add properties for its classification (in my case Building Element Proxy but I have to find a way to get it automatically), the object is not placed immediately and when I place an instance of it I will have the properties with no values again, like in the case of a wall, right?
It's right.
n.mihaylov wrote:
I hoped ACAPI_Element_SetProperties would set the "properties" to the element with "elemGuid".
Yes, that's right. You can use that function to set properties of an element instance (already placed).
So for example if your placed wall instance has two properties 'PropA' and 'PropB' then you can set the values of those, BUT this function will return error code (APIERR_BADPROPERTYFORELEM) if you tried to set property with name 'PropX', because the wall instance does not have that property.

You can use ACAPI_ElementList_AddProperty function to make a property available for given elements. So if the given property is not exists for the element, then it will be created by this function (by making the property available for the element's classification).
Learn and get certified!