SOLVED!
Draw Text

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2019-02-17
07:46 AM
- last edited on
ā2022-10-04
04:39 PM
by
Daniel Kassai
ā2019-02-17
07:46 AM
Trying to draw some simple text at the origin. I'm guessing I need to use the function API_Element_Create() but I'm obviously doing something wrong as I get a compile message of 'no suitable conversion function from API_TextType to API_Element'
Can't seem to find a example in the Examples files. Here's the code I'm using -- Obviously wrong -- Any one have a example?
Can't seem to find a example in the Examples files. Here's the code I'm using -- Obviously wrong -- Any one have a example?
API_TextType element; BNZeroMemory(&element , sizeof(API_TextType)); API_ElementMemo memo; BNZeroMemory(&memo, sizeof(API_ElementMemo)); element.head.typeID = API_TextID; element.head.hasMemo = true; element.head.guid = APINULLGuid; element.loc.x = 0; element.loc.y = 0; element.font = 131; CHCopyC(*memo.textContent , "some text"); ACAPI_Element_Create(&element, &memo);
Gerry
Windows 11 - Visual Studio 2022; ArchiCAD 27
Windows 11 - Visual Studio 2022; ArchiCAD 27
Solved! Go to Solution.
Labels:
- Labels:
-
Add-On (C++)
1 ACCEPTED SOLUTION
Accepted Solutions
Solution

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2019-02-18 09:56 AM
ā2019-02-18
09:56 AM
You have to bother with paragraphs only if you want to create a text with multi style.
Here is a simple function to create text element (extracted from Communication_Client example Add-On):
Here is a simple function to create text element (extracted from Communication_Client example Add-On):
static GSErrCode CreateAText (const char* content, short pen, double size, double xPos, double yPos) { API_Element element = {}; element.header.typeID = API_TextID; GSErrCode err = ACAPI_Element_GetDefaults (&element, nullptr); if (err != NoError) { ErrorBeep ("ACAPI_Element_GetDefaults (text)", err); return err; } element.text.pen = pen; element.text.size = size; element.text.anchor = APIAnc_LT; element.text.just = APIJust_Left; element.text.loc.x = xPos; element.text.loc.y = yPos; element.text.nonBreaking = true; element.text.nLine = 1; API_ElementMemo memo = {}; memo.textContent = BMAllocateHandle (Strlen32 (content) + 1, ALLOCATE_CLEAR, 0); strcpy (*memo.textContent, content); err = ACAPI_CallUndoableCommand ("Create text", [&] () -> GSErrCode { return ACAPI_Element_Create (&element, &memo); }); if (err != NoError) ErrorBeep ("ACAPI_Element_Create (text)", err); ACAPI_DisposeElemMemoHdls (&memo); return err; } // CreateAText
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2019-02-18 12:17 AM
ā2019-02-18
12:17 AM
OK -- I found the example in Element_test under mutistyle text and found the paragraph stuff to be immensely confusing. I'd appreciate some direction for an explanation of paragraphs in the documentation -- if someone could direct me to that section. I could not find any pertinent documentation to explain paragraphs in the API?
In the mean time, I think I'll just stick to the non-associated label example for just one/lines of text.
In the mean time, I think I'll just stick to the non-associated label example for just one/lines of text.
Gerry
Windows 11 - Visual Studio 2022; ArchiCAD 27
Windows 11 - Visual Studio 2022; ArchiCAD 27
Solution

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2019-02-18 09:56 AM
ā2019-02-18
09:56 AM
You have to bother with paragraphs only if you want to create a text with multi style.
Here is a simple function to create text element (extracted from Communication_Client example Add-On):
Here is a simple function to create text element (extracted from Communication_Client example Add-On):
static GSErrCode CreateAText (const char* content, short pen, double size, double xPos, double yPos) { API_Element element = {}; element.header.typeID = API_TextID; GSErrCode err = ACAPI_Element_GetDefaults (&element, nullptr); if (err != NoError) { ErrorBeep ("ACAPI_Element_GetDefaults (text)", err); return err; } element.text.pen = pen; element.text.size = size; element.text.anchor = APIAnc_LT; element.text.just = APIJust_Left; element.text.loc.x = xPos; element.text.loc.y = yPos; element.text.nonBreaking = true; element.text.nLine = 1; API_ElementMemo memo = {}; memo.textContent = BMAllocateHandle (Strlen32 (content) + 1, ALLOCATE_CLEAR, 0); strcpy (*memo.textContent, content); err = ACAPI_CallUndoableCommand ("Create text", [&] () -> GSErrCode { return ACAPI_Element_Create (&element, &memo); }); if (err != NoError) ErrorBeep ("ACAPI_Element_Create (text)", err); ACAPI_DisposeElemMemoHdls (&memo); return err; } // CreateAText
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2019-02-18 04:37 PM
ā2019-02-18
04:37 PM
Ćkos also wrote a nice "Hello World" example on the API blog that shows how to place a text element: http://archicadapi.graphisoft.com/hello-world
Ralph Wessel BArch
Central Innovation
Central Innovation