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

Dimension witness gap settings

TomWaltz
Participant
I am trying to write an API which create dimensions in various situations, using a default made in the API.

I have most of the settings figured out, but the witnessVal seting in API_DimElem is killing me. It's the setting for the gap between the end of a witness line and the element being dimensioned.

Here is what I have so far:
  • API_Element element, mask;
    API_ElementMemo memo;
    GSErrCode err;
    //API_DimElem dimparts;

    BNZeroMemory (&element, sizeof (API_Element));
    BNZeroMemory (&memo, sizeof (API_ElementMemo));

    element.header.typeID = API_DimensionID;

    err = ACAPI_Element_GetDefaults (&element, &memo);
    if (err == NoError)


    ACAPI_ELEMENT_MASK_CLEAR (mask);

    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, ed_arrowAng);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, textPos);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, linPen);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, markerData.markerPen);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, markerData.markerSize);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, markerData.markerType);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, defNote.notePen);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, defNote.noteFont );
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, defNote.noteSize);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, dimAppear);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, defWitnessForm);
    ACAPI_ELEMENT_MASK_SET (mask, API_DimElem, witnessVal);

    element.dimension.ed_arrowAng = 2; // 45 degree tickmark
    element.dimension.textPos = API_TextPosID (APIPos_Above);
    element.dimension.linPen = 164; // dimension line pen
    element.dimension.markerData.markerPen = 166 ;// tickmark pen
    element.dimension.markerData.markerSize = 2.6; // tickmark size
    element.dimension.markerData.markerType = API_MarkerID(APIMark_SlashLine45);// tickmark type
    element.dimension.defNote.notePen = element.dimension.linPen; // text pen
    element.dimension.defNote.noteFont = 87; // Tekton Pro
    element.dimension.defNote.noteSize = 2.468265; // 7.00 points
    element.dimension.dimAppear = API_AppearID(APIApp_Normal); // Normal Dimensions
    element.dimension.defWitnessForm = API_WitnessID(APIWtn_Large); // Dynamic Witness Line
    // ----------------------------------------------------
    // Problem Here
    dimparts.witnessVal = 2; // Witness line gap, compiling, but having no effect
    //memo.dimension.witnessVal = API_DimElem(witnessVal, 2); // Not compiling
    // .... to here
    // ----------------------------------------------------

    ACAPI_Element_ChangeDefaults (&element, &memo, &mask);[list=]

I feel like there's something simple I'm missing.

I was hoping to work in a variable that checks the scale, and adjusts the witnessVal based on it, but right now I'll be happy just to set tha blasted thing!
Tom Waltz
4 REPLIES 4
Karl Ottenstein
Moderator
Hi Tom,

We'll have to wait for Ralph or Oleg to set us straight (or maybe Ferenc or someone else will join us?) ... but writing as another API newbie, the docs indicate that if you want the witnessVal to be treated as a gap, that you have to set witnessForm to APIWtn_Fix (an enum). Might be related to why setting the value doesn't do anything for you?

I'm not sure what you mean by:
memo.dimension.witnessVal = API_DimElem(witnessVal, 2);
The field of the API_ElementMemo struct is dimElems, not dimension, and that is a ** to an API_DimElem, and you're using API_DimElem as some kind of constructor that I don't recognize. But, I'm really rusty!!

Wish I was more up to speed to help more specifically, and hope I'm not too far off track to steer you in the wrong direction above.

Karl
One of the forum moderators
AC 27 USA and earlier   •   macOS Ventura 13.6.6, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
TomWaltz
Participant
I'm not sure what you mean by:

Code:
memo.dimension.witnessVal = API_DimElem(witnessVal, 2);
honestly, Karl, I'm not to sure either!! 😉

I'm just having a hard time getting the syntax to set the variable witnessVal, and was trying different things to get it to work. I'm new enought to C++ that the basic syntax on struct and enum is a little confusing sometimes, especially since GS seems a little inconsistant sometimes.
Tom Waltz
Oleg
Expert
I am not sure, that I have understood you. Do you want to change dimension tool defaults ?
If you want that it is not required to use API_DimElem and even API_ElementMemo.
( It will be required at dims creation on the floor plan and it is more complex a task )

Try this hints.

err = ACAPI_Element_GetDefaults (&element, 0);

What is it ? Delete this line.
ACAPI_ELEMENT_MASK_SET (mask, API_DimElem, witnessVal);

Add instead of it:
ACAPI_ELEMENT_MASK_SET (mask, API_DimensionType, defWitnessVal);

Also add (I dont remember is it value in meters or mm :
element.dimension.defWitnessVal = 2; // Default gap (APIWtn_Fix) or length (APIWtn_Large)

And then:
ACAPI_Element_ChangeDefaults (&element, 0, &mask);

PS:
By the way, you can use enums just as value (for example):
element.dimension.dimAppear = APIApp_Normal; // Normal Dimensions
element.dimension.defWitnessForm = APIWtn_Large; // Dynamic Witness Line

Instead of:
element.dimension.dimAppear = API_AppearID (APIApp_Normal); // Normal Dimensions
element.dimension.defWitnessForm = API_WitnessID (APIWtn_Large); // Dynamic Witness Line

Good luck
TomWaltz
Participant
That was it, Oleg. Thanks!!

Yes, I was trying to set the defaults for the dimensions.
Tom Waltz