PDM API why does GetVar / GetVarAsText rely on parent folder?

Programming and macros
User avatar
bnemec
Posts: 1869
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2463
x 1344

PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by bnemec »

Similar to an older question I asked that was answered.

https://www.cadforum.net/viewtopic.php?t=1055

I'm thinking that answer would only apply to getting references. I'm assuming that the variable values are applied to the document, not based on where the file might be shared to. In my mind (not implying my perception is correct) a Document ID should represent an object that only has one set of variables (well, there's versions and configs, but assuming latest version and only looking at the "Default" config for example). Needing to know the parent folder of a document to get the variables implies that a variable for single config in a single version of a specific docID can have more than one value, based on which project/folder the document is cached. That's a scary thought.

I'm getting an instance of the EnumeratorVariable from a specific instance of an edmFile. Another assumption I'm making is that any reference to an edmFile instance for part.sldprt will be identical regardless of where the file might be shared to. In the case of identical filenames in the vault (bad) they would have different DocIDs so the edmFile objects would be different. It just seems that if I have an instance of a PDM document there shouldn't be ambiguity so if I get the EnumeratorVariable from that file the parent folder should be inherent in that instance.

I'm missing something here or making a bad assumption again, or both.

Code: Select all

      IEdmEnumeratorVariable10 enumVar = (IEdmEnumeratorVariable10)edmFile.GetEnumeratorVariable();
      bool getVarSuccess;
      getVarSuccess = enumVar.GetVarAsText("CAD_DocNumber", "Default", ParentFolderID, out v);
      if(getVarSuccess)
      {
      string cadDocNum = (string)v;
      }
      
User avatar
AlexB
Posts: 449
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by AlexB »

I can only imagine it has something to do with the way the variables are stored in the SQL database. The main keys in the VariableValues table are for ConfigurationID, ProjectID, DocumentID and VariableID. This means you need to essentially specify the variable, file, folder and configuration. The EdmEnumeratorVariable "knows" the file, but not the folder. So, if the folder ID is not specified, it would essentially return multiple rows when you look for a variable name on a file that's shared to multiple folders.

It doesn't make the most sense but that's my best guess.
image.png
User avatar
bnemec
Posts: 1869
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2463
x 1344

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by bnemec »

AlexB wrote: Mon Feb 14, 2022 4:10 pm I can only imagine it has something to do with the way the variables are stored in the SQL database. The main keys in the VariableValues table are for ConfigurationID, ProjectID, DocumentID and VariableID. This means you need to essentially specify the variable, file, folder and configuration. The EdmEnumeratorVariable "knows" the file, but not the folder. So, if the folder ID is not specified, it would essentially return multiple rows when you look for a variable name on a file that's shared to multiple folders.

It doesn't make the most sense but that's my best guess.

image.png
That's what I was thinking too, until we realized that adding a where ProjectID <>2 clause returned a null set. So what is ProjectID = 2? "No Project" makes sense, usually the first couple rows are this kind of record. But since this table is universal and folders/projects can have data cards just like files, we're assuming that the ProjectID column is only used in records for folder data card variables in which case the DocumentID would == 1.

So I'm not so sure that the parentFolderID parameter has anything to do with the ProjectID column in the VariableValue table.
User avatar
AlexB
Posts: 449
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by AlexB »

bnemec wrote: Mon Feb 14, 2022 4:20 pm That's what I was thinking too, until we realized that adding a where ProjectID <>2 clause returned a null set. So what is ProjectID = 2? "No Project" makes sense, usually the first couple rows are this kind of record. But since this table is universal and folders/projects can have data cards just like files, we're assuming that the ProjectID column is only used in records for folder data card variables in which case the DocumentID would == 1.

So I'm not so sure that the parentFolderID parameter has anything to do with the ProjectID column in the VariableValue table.
Yep, you're right. All the variables for folders and files are stored in the same table. So, it seems that you either need to provide a project ID of 2 (No Project) or a file ID of 1 (No Document) to get the particular variable folder/file variable you're looking for. That makes a little bit more sense. I'd test it out a bit more just to be sure but that may be something you can just specify once without having to get the folder ID for every file.
User avatar
bnemec
Posts: 1869
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2463
x 1344

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by bnemec »

AlexB wrote: Mon Feb 14, 2022 4:34 pm Yep, you're right. All the variables for folders and files are stored in the same table. So, it seems that you either need to provide a project ID of 2 (No Project) or a file ID of 1 (No Document) to get the particular variable folder/file variable you're looking for. That makes a little bit more sense. I'd test it out a bit more just to be sure but that may be something you can just specify once without having to get the folder ID for every file.
yep, tested all kinds of things. Keeping a handle to the ParentFolder or storing the ID and then passing that works. Sometimes I don't have those and passing 0 has always worked for that but I don't like leaving it that way. Feels like it could not work at any moment without warning or indication.

It seems poor data abstraction to need to keep the parentFolderID right alongside an edmFile instance. But, there's a lot more to it than I understand or have awareness of.
User avatar
Diaval
Posts: 87
Joined: Wed Mar 17, 2021 12:01 pm
Answers: 7
Location: Stockholm
x 50
x 110

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by Diaval »

AlexB wrote: Mon Feb 14, 2022 4:10 pm So, if the folder ID is not specified, it would essentially return multiple rows when you look for a variable name on a file that's shared to multiple folders.
This is not actually accurate. The VariablValues table holds variable data for both files and folders in the vault since both of these objects have data cards that can have values set for any variable added to the card. (In some cases files are inheriting the folder card values when they are added to the folder if that is how the file data card is setup. The default SW file data cards are setup to do this for the Project Name and Project Number variables)

For entries in the VariableValues table, files will use a DocumentID based on the ID specified in the Documents table and a ProjectID of 2 (no folder). Folder values will use a DocumentID of 1 (no file) with the ProjectID of the folder from the Projects table.
-- To espouse elucidation we must eschew obfuscation
User avatar
AlexB
Posts: 449
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by AlexB »

Diaval wrote: Tue Feb 15, 2022 11:21 am For entries in the VariableValues table, files will use a DocumentID based on the ID specified in the Documents table and a ProjectID of 2 (no folder). Folder values will use a DocumentID of 1 (no file) with the ProjectID of the folder from the Projects table.
Yes, I think this is what we ended up settling on after discussing it further.
User avatar
bnemec
Posts: 1869
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2463
x 1344

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by bnemec »

Diaval wrote: Tue Feb 15, 2022 11:21 am This is not actually accurate. The VariablValues table holds variable data for both files and folders in the vault since both of these objects have data cards that can have values set for any variable added to the card. (In some cases files are inheriting the folder card values when they are added to the folder if that is how the file data card is setup. The default SW file data cards are setup to do this for the Project Name and Project Number variables)

For entries in the VariableValues table, files will use a DocumentID based on the ID specified in the Documents table and a ProjectID of 2 (no folder). Folder values will use a DocumentID of 1 (no file) with the ProjectID of the folder from the Projects table.
Thank you Diaval. Does that relate to parentFolderID parameter in the GetVar and GetVarAsText functions? Mostly what I'm wondering is why is the ParentFolderID neeeded? It appears that passing the actual parent folder ID or 0 both work when getting file variable values.

Chasing the rabbit a little bit, while looking at it from different angle, I asked myself, "How does one get the variable values for a folder (if folder data cards are in use)?" I had assumed edmFolder interface had an accessor to EdmEnumeratorVariable but I cannot find that. So how does one get the value of a folder data card variable?

Edit: After some searching of the webs it looks like one can set a edmEnumeratorVariable to an instance of an edmFolder.
Sorry to link to the other place but want to site where my info comes from:
https://r1132100503382-eu1-3dswym.3dexp ... TldvlAeSEw

edmEnumeratorVariable does not inherit IEdmObject so maybe operator overloading? I don't want to get into the weeds too far, I'm not in need of messing with Folder Data Cards, we don't use them. Just trying to get a clearer picture of what I'm doing with the API.
User avatar
AlexB
Posts: 449
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by AlexB »

bnemec wrote: Tue Feb 15, 2022 2:08 pm Thank you Diaval. Does that relate to parentFolderID parameter in the GetVar and GetVarAsText functions? Mostly what I'm wondering is why is the ParentFolderID neeeded? It appears that passing the actual parent folder ID or 0 both work when getting file variable values.

Chasing the rabbit a little bit, while looking at it from different angle, I asked myself, "How does one get the variable values for a folder (if folder data cards are in use)?" I had assumed edmFolder interface had an accessor to EdmEnumeratorVariable but I cannot find that. So how does one get the value of a folder data card variable?

Edit: After some searching of the webs it looks like one can set a edmEnumeratorVariable to an instance of an edmFolder.
Sorry to link to the other place but want to site where my info comes from:
https://r1132100503382-eu1-3dswym.3dexp ... TldvlAeSEw

edmEnumeratorVariable does not inherit IEdmObject so maybe operator overloading? I don't want to get into the weeds too far, I'm not in need of messing with Folder Data Cards, we don't use them. Just trying to get a clearer picture of what I'm doing with the API.
You can also get the folder card using this method. Pass a "." in for the extension and you can access the folder's card itself. Then you can iterate through the variables on the actual card, getting their values as needed.

http://help.solidworks.com/2014/english ... tcard.html
cdantonio
Posts: 11
Joined: Mon Nov 07, 2022 4:54 pm
Answers: 0
Location: Bay Area
x 8
x 2

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by cdantonio »

Quick question: how did you dimension your variable "out v"? Looking for how to properly declare poRetVal and can't find it anywhere.
User avatar
AlexB
Posts: 449
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 398

Re: PDM API why does GetVar / GetVarAsText rely on parent folder?

Unread post by AlexB »

cdantonio wrote: Mon Nov 07, 2022 4:56 pm Quick question: how did you dimension your variable "out v"? Looking for how to properly declare poRetVal and can't find it anywhere.
According to the help documentation, it is the type "object". Once you get the "object poRetValue", you can try to cast it to a string or whatever type you're expecting from that specific value.

https://help.solidworks.com/2018/englis ... stext.html
Post Reply