List the names of a cube in a server

Post Reply
samuvk
Posts: 9
Joined: Wed Jan 27, 2010 9:53 pm
OLAP Product: TM1
Version: v9.0
Excel Version: 2003

List the names of a cube in a server

Post by samuvk »

I'm trying to get the cubes's names in a server with the next code throught the APIs.

ServerInt = TM1ObjectListHandleByNameGet(hPool, hServer, Tm1PropertyList, TM1ValString(hPool, cube, 100))

My problem is that after execute this sentence I don't know how to get the names.

I think to understand that I get the result in TM1ValString(hPool, cube, 100), But I don't know if this is true, or how to use the result and get the names, one by one.

For example: If for the server I have to cubes: (Cube1, cube2) My goal is to get those two names.

Thank you very much
User avatar
Martin Ryan
Site Admin
Posts: 2003
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: List the names of a cube in a server

Post by Martin Ryan »

Instead of getting into the API you could cycle through the control dimension }Cubes and ignore any elements that start with a } as they will be control objects

Code: Select all

sub getCubeNames()
Dim myDim as string, i as integer, cubeName as string
myDim="server:}Cubes"
for i=1 to application.run ("dimsiz", myDim)
cubeName=application.run ("dimix", myDim, i)
callYourFunction(cubeName)
next i
end sub
Martin
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: List the names of a cube in a server

Post by Alan Kirk »

samuvk wrote:I'm trying to get the cubes's names in a server with the next code throught the APIs.

ServerInt = TM1ObjectListHandleByNameGet(hPool, hServer, Tm1PropertyList, TM1ValString(hPool, cube, 100))

My problem is that after execute this sentence I don't know how to get the names.

I think to understand that I get the result in TM1ValString(hPool, cube, 100),
Alas, you do not. That is where you PASS the name of the object TO the function.
samuvk wrote:But I don't know if this is true, or how to use the result and get the names, one by one.

For example: If for the server I have to cubes: (Cube1, cube2) My goal is to get those two names.

Thank you very much
I agree with Martin; don't use the API, his method is much simpler.

In addition to which you're using the wrong function. You'd already need to know the names to use TM1ObjectListHandleByNameGet, and that would only be returning a handle to the object, not the name of the object.

Getting a list of cubes is actually one of the easier ( :shock: ??!!) things to do in the API, but "easy" is a relative term when working with that monster.

Assuming that you already have a user handle (hUser), a handle to the server (hServer) and a handle to a value pool (hPool), you would need to do the following:

1/ Get a value capsule containing the number of cubes:
vhCubes = TM1ObjectListCountGet(hPool, hServer, TM1ServerCubes())

2/ Extract that as an integer value:
i_CubesCnt = TM1ValIndexGet(hUser, vhCubes)

Then use a loop from 1 to i_CubesCnt in which you do the following.

3/ Initialise the string that will hold the cube name. There are other ways of doing this but I do it as:
sCubeName = String$(gIC_TM1STRING_SIZE_DEFT, Chr(0))

You need to do that because the API functions won't clear the previous contents of the variable, so if you have a long cube name (say "ProfitAndLoss") followed by a short cube name (like "Stats") and don't clear the variable, you'll get "StatstAndLoss") returned when you get the second cube's name.)

(Note: gIC_TM1STRING_SIZE_DEFT is a constant that I had defined with a value of 255. Also, the variable itself was declared as a fixed length string; Dim sCubeName As String * gIC_TM1STRING_SIZE_DEFT)

4/ Get a handle to the cube by using its index, since you don't know its name. (i_CubesIdx is being used to loop through the cubes from 1 to i_CubesCnt):
hCube = TM1ObjectListHandleByIndexGet(hPool, hServer, TM1ServerCubes(), TM1ValIndex(hPool, i_CubesIdx))

5/ Get a value capsule containing the cube name from that handle:
vhCubeName = TM1ObjectPropertyGet(hPool, hCube, TM1ObjectName())

6/ Convert the contents of the value capsule to a string:
TM1ValStringGet_VB hUser, vhCubeName, sCubeName, gIC_TM1STRING_SIZE_DEFT

7/ Trim the trailing null characters from the sCubeName variable.

Then do the cleanup; destroy your pool handle, blah, blah.

And I'd also generally check the value capsules using TM1ValType at each step to ensure that they contained what you think they contained and not an error.

I'll bet Martin's method is looking pretty good about now, no? :lol:
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
samuvk
Posts: 9
Joined: Wed Jan 27, 2010 9:53 pm
OLAP Product: TM1
Version: v9.0
Excel Version: 2003

Re: List the names of a cube in a server

Post by samuvk »

Thank you very much both, for your help.

It's true that Martin's method look like easier.

I tried his method, but I don't know why I having the next problem. (I'm working with Visual Basic in Excel 2003 and TM1 Version 9.0)

I attach the problem that I having in a word document calls VB.


Then, I have a different question. I'm trying to work with Visual Basic 2008, so I want to load the Apis libraries, tm1li.dll, tm1api.dll and tm1sip.dll, but I having the problemm that I attach in the word document calls TM1.

Thank you very much again for your help.
Attachments
TM1.doc
Error load TM1 apis libraries
(298.5 KiB) Downloaded 249 times
VBExcel.doc
Error Calling Sub
(24 KiB) Downloaded 265 times
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: List the names of a cube in a server

Post by Alan Kirk »

samuvk wrote:Thank you very much both, for your help.

It's true that Martin's method look like easier.

I tried his method, but I don't know why I having the next problem. (I'm working with Visual Basic in Excel 2003 and TM1 Version 9.0)

I attach the problem that I having in a word document calls VB.
(For the record, the error was "Compile Error: Expected =")

Get rid of the brackets around
TM1ValStringGet_VB(hUser, hName, name, 100)

TM1ValStringGet_VB is a sub, not a function. By having brackets around the arguments you're telling VBA that you expect it to return a value. The procedure itself doesn't; the only value returned is by reference, via the "Name" argument.

(Clarification edit: I am of course talking about when you're calling the procedure, not about the function declaration in the tm1api.bas module which is an entirely different thing.)
samuvk wrote: Then, I have a different question. I'm trying to work with Visual Basic 2008, so I want to load the Apis libraries, tm1li.dll, tm1api.dll and tm1sip.dll, but I having the problemm that I attach in the word document calls TM1.
So-called Visual Basic 2008 is not Visual Basic, which finished at Version 6 regardless of what Microsoft claims.

See the FAQ thread heading "Location of API Libraries, .Net vs C/VB and Other Issues" for a link to a useful treatise on the subject by Mike Cowie.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Post Reply