Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Convert morph to an Object in C++ Add-On code

kency
Enthusiast

Hello,

 

Is there a function that would convert the given Morph GUID to an Object in C++ API like we do it in UI.

kency_0-1720005671602.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Akos Somorjai
Graphisoft
Graphisoft
13 REPLIES 13
Solution
Akos Somorjai
Graphisoft
Graphisoft

Hi kency,

 

Well, you can simulate that; please look at https://graphisoft.github.io/archicad-api-devkit/struct_a_p_i___save_pars___object.html.

 

Best, Akos

kency
Enthusiast

@Akos Somorjai Couple of doubts - 

  • We will need to write the GSM to a file right?
  • Will this convert the existing morph to a furniture object?
  • Got the errorCode -

    -2130312312 : APIERR_REFUSEDCMD

    when I tried the below:

 

GS::Array<API_Neig> selNeigs;
API_Neig neig (element.header.guid); // Element guid of a morph
selNeigs.Push(neig);
ACAPI_Selection_Select(selNeigs, true);
API_FileSavePars    fsp = {};
fsp.fileTypeID = APIFType_ObjectFile;
IO::Location outputFile (GetSpecialFolderLocation (API_UserDocumentsFolderID), IO::Name ("Test.gsm"));
fsp.file = &outputFile;
API_SavePars_Object objectPars = {};
objectPars.libItMode = APIConvMod_SymTxtGDL;
objectPars.removeLine = true;
objectPars.saveSelOnly = true;
objectPars.isPlaceable = true;
err = ACAPI_ProjectOperation_Save (&fsp, &objectPars);
if (err != NoError) {
    std::cout<< "Error " << err << std::endl;
}

 

 

Hello kency,

 

I've tried your code, and it works both from the Plan and the 3D window if I call it from the Test menu as a new command. When/where do you call that function? From the code that error message trivially may come from two places: if you are in a DEMO Archicad, or if command execution is not allowed.

 

It will save the object as a generic Model Element, you have to modify its subtype later, or classify it as a furniture.

 

Any ideas along that line?

 

Akos

kency
Enthusiast

@Akos Somorjai I was on non Demo version of Archicad. But the code was under Undoable command. After moving it out of the Undoable Command i could see that the gsm file got created in the specified location. But the morph still remained as a Morph element. How do we convert the morph element to furniture?

 

Update: My bad, i thought the UI option Save Selection created the gsm file as well as converted the existing morph to an object. 

Is there anything that can convert the morph as an object?

Hi kency,

 

There is no function on the API that would do the conversion.

But: you can delete the morph element (save its location first 😉), and place a new object instead that refers to that gsm file you saved. The delete and create operations should be under undoable scope...

Also, create the .gsm file in the embedded library instead of any generic folder so that it can become part of the plan file.

 

Best, Akos

kency
Enthusiast

Clear on this @Akos Somorjai thank you so much! The whole problem statement has been raised here. Any thoughts on that as well ?

kency
Enthusiast

Just another query is there any way to remove the lines between facets?  @Akos Somorjai 

image (1).png

Akos Somorjai
Graphisoft
Graphisoft

Could you please attach the GDL file itself?

Sure. Have attached the zip for gsm and even the pln file