Dear all,
How to check whether a element having any UserAttributeData or not?
You can try to call function mdlElment_extractAttributes and test the returned attribute length.
HTH, YongAn
Hai Yongan,
Can you please send me a code snippet for reference?
int attrLen = -1;
short myAttrBuf[MAX_ATTRIBSIZE];
mdlElement_extractAttributes (&attrLen, myAttrBuf, &el);
if (0 == attrLen)
// No any user attribute data
else
// Has some user attribute data
Thanks Yongan,
I tried your code snippet in vba with a element having attribute in attributeID: 100 and 400. But the code returns zero (which is given below for your reference). Can you please clarify whether anything missing in my code?
Private Sub test()
Dim en As ElementEnumerator
Dim elem As Element
Set en = ActiveModelReference.GetSelectedElements
en.MoveNext
Set elem = en.Current
Dim myAttrBuf As Long
Dim tmpLen As Long
Dim attrLen As Long
attrLen = -1
myAttrBuf = 1000
tmpLen = mdlElement_extractAttributes(attrLen, myAttrBuf, elem.MdlElementDescrP)
Debug.Print tmpLen
Debug.Print attrLen
End Sub
Sorry, my code was written by using MDL. If you want to implement in VBA, it is somewhat complex as below:
Declare Function mdlElement_extractAttributes Lib "stdmdlbltin.dll" (ByRef length As Long, ByVal buffer As Long, ByVal pElement As Long) As LongDeclare Function ElmdscrAccessor_getMSElement Lib "stdmdlaccessor.dll" (ByVal ElementDescr As Long) As Long
Type MyBuffer buf(65535) As IntegerEnd Type
Sub test() Dim elem As Element Set elem = ActiveModelReference.GetElementByID(DLongFromLong(4247)) Dim myAttrBuf As MyBuffer Dim attrLen As Long mdlElement_extractAttributes attrLen, VarPtr(myAttrBuf), ElmdscrAccessor_getMSElement(elem.MdlElementDescrP) MsgBox attrLenEnd Sub
Thanks Yongan.
It's working fine with a slight modification. "buf(65535) As Integer" was replaced with "buf(6553) As Integer" to avoid compile error 'Fixed or static data can't be larger than 64K'.
I have one more doubt, in statement "buf(65535) As Integer", the value 65535 stands for what? Kindly clarify.
MAX_ATTRIBSIZE = 65535
Unknown said:'Fixed or static data can't be larger than 64K'.
This error is likely coming directly from the Microsoft VBA development environment once one (1) of your source code modules definitions exceed the design limitation of 64KB as documented in these links:
You may need to refactor your code, move common functions to a separate "utility" module, and/or ensure that the data types and buffers are dynamically allocated to the exact sizes needed vs. making the buffers as large as possible to account for the worst-case scenario.
HTH,Bob
Thanks Bob. The above information was very useful to understand the issue.