Problem getting the Distance property in a DistanceChamfer via API

Problem getting the Distance property in a DistanceChamfer via API

Anonymous
Not applicable
716 Views
11 Replies
Message 1 of 12

Problem getting the Distance property in a DistanceChamfer via API

Anonymous
Not applicable

Hi there,

 

I am using Inventor 2018 and programming an addin in C++. I would like to access the 'Distance' property in a DistanceChamferDefPtr object but I am getting a _com_error exception.

 Snippet

ChamferFeaturePtr chamferFeature = chamferColl->GetItem(itChamfer);
if (chamferFeature == NULL)
    return;
 
ChamferDefinitionPtr chamferDef = chamferFeature->GetDefinition();
if (chamferDef->Type == kDistanceChamferDefObject) {
    DistanceChamferDefPtr distanceChamfer = chamferDef;
    if (distanceChamfer) {
        ParameterPtr distanceParam = distanceChamfer->Distance;
        double value1 = (double)distanceParam->Value;
 
        VARIANT_BOOL setBack = VARIANT_FALSE;
        setBack = distanceChamfer->CornerSetback;
        double angle = 45.000;
    }
} 

When I try to get the Distance or CornerSetback ParameterPtr is when the program raises the exception. Any clue where my problem could be located?

 

Regards

0 Likes
Accepted solutions (2)
717 Views
11 Replies
Replies (11)
Message 2 of 12

YuhanZhang
Autodesk
Autodesk

Does the error happen to a specific part file or all parts there?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi,

I have seen it in many parts. I have managed to get the property values using the next piece of code.

 

Snippet

HRESULT hresult;
 
// Get parameter ID.
OLECHAR* szMember = parameterName;
DISPID dispid;
hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
if (FAILED(hresult)) {
    throw _com_error(hresult);
}
 
// Get id property.
DISPPARAMS dp = { nullptrnullptr, 0, 0 };
VARIANT pVarResult;
hresult = pdisp->Invoke(dispid, IID_NULLLOCALE_USER_DEFAULTDISPATCH_PROPERTYGET, &dp, &pVarResult, NULLNULL);
if (FAILED(hresult)) {
    throw _com_error(hresult);
}
 
return pVarResult;

 I think this could mean there is a bug in the API, because I can access the properties via Invoke but not directly. Not sure about it though.

 

Greetings

0 Likes
Message 4 of 12

Anonymous
Not applicable

Hi,

I have seen it in many parts. I have managed to get the property values using the next piece of code.

 

Snippet

HRESULT hresult;
 
// Get parameter ID.
OLECHAR* szMember = parameterName;
DISPID dispid;
hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
if (FAILED(hresult)) {
    throw _com_error(hresult);
}
 
// Get id property.
DISPPARAMS dp = { nullptrnullptr, 0, 0 };
VARIANT pVarResult;
hresult = pdisp->Invoke(dispid, IID_NULLLOCALE_USER_DEFAULTDISPATCH_PROPERTYGET, &dp, &pVarResult, NULLNULL);
if (FAILED(hresult)) {
    throw _com_error(hresult);
}
 
return pVarResult;

 I think this could mean there is a bug in the API, because I can access the properties via Invoke but not directly. Not sure about it though.

 

Greetings

0 Likes
Message 5 of 12

YuhanZhang
Autodesk
Autodesk

I can run the code in your first post successfully here with Inventor 2018.3, so can you share me your data to reproduce the problem? Don't share confidential data.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 6 of 12

Anonymous
Not applicable

I attach one of the parts i'm having troubles with.

0 Likes
Message 7 of 12

YuhanZhang
Autodesk
Autodesk

Missed the attachment?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 8 of 12

Anonymous
Not applicable

Maybe...

0 Likes
Message 9 of 12

YuhanZhang
Autodesk
Autodesk

I can't reproduce the problem, see attached picture:

 

Parameter.png

 

The Double value can be returned successfully. I am using Inventor 2018.3 build, and VS2017, can you let me which VS you are using, and let me the your setting in the project properties for C/C++->General->Additional Include Directories?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 10 of 12

Anonymous
Not applicable

Hi again,

 

I'm using VS2015 with an Inventor 2018.3, but in my 'C/C++->General->Additional Include Directories' configuration my project is including a V2017 API files that have been copied to the project folder. Since I have not installed the 2017 version, can this be the problem?

 

In another words, do I have to compile my addin whit the API2018 to use it in an Inventor 2018?

0 Likes
Message 11 of 12

YuhanZhang
Autodesk
Autodesk
Accepted solution

I recommend you to specify the directory to the active Inventor Bin folder when you DEBUG the project, it can make sure the project references to correct files. Please let me if when you update the "Additional Include Directories" solves the problem or not.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 12 of 12

Anonymous
Not applicable
Accepted solution

Okay, so I have changed the directory to my Bin folder and now it works just fine.

 

Thanks very very much for the help!

0 Likes