Community
Vault Customization
Share your knowledge, ask questions, and explore popular Vault API, Data Standard, and VBA topics related to programming, creating add-ins, or working with the Vault API.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing Properties with the VDF

9 REPLIES 9
Reply
Message 1 of 10
Mzwijacz
1476 Views, 9 Replies

Accessing Properties with the VDF

I am learning the VDF and trying to search all items based on the value of a specific property . Once I have a list of the item, I want to extract other property values and write them to a file. lastly I want to change the value I was searching on . So far I've been able to get a list of all items per change order. but am having a problem getting property information. I was also thinking rather than get all items for change orders, it might be better to extract the data using LINK. I've not been able to find any examples using LINK with a property as one of the search criteria or examples of searching/extracting based on property values.
Tags (1)
9 REPLIES 9
Message 2 of 10
Mzwijacz
in reply to: Mzwijacz

Here is a code sample I've been trying. It would not send in the original message : File attached
Message 3 of 10
wayne.brill
in reply to: Mzwijacz

Hi,

 

Can you try uploading your code again? I don't see it attached.

 

The example in this DevBlog searches for items using the number property. (not sure if it will be any help) 

http://adndevblog.typepad.com/manufacturing/2012/08/get-where-used-information-for-an-item.html

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 4 of 10
Mzwijacz
in reply to: wayne.brill

Looked at the page but the code is prior to VDF Web service calls. I'm trying to get comfortable with the VDF access. I think the problem I'm having is understanding the correct object types in the call to get properties. Here is the code again. public string GetItemPropertyByPropertyName(Item SuppliedItem, string PropertyName) { string returnString = string.Empty; try { //Settings VDF.Vault.Currency.Properties.PropertyValueSettings Settings = new VDF.Vault.Currency.Properties.PropertyValueSettings(); //Items //Item[] items = new Item[1]; //items[0] = SuppliedItem; //List Items = new List(); //Items.Add(SuppliedItem); //VDF.Vault.Currency.Entities.EntityClass[] Items = new VDF.Vault.Currency.Entities.EntityClass[1]; //Items[0] = (VDF.Vault.Currency.Entities.EntityClass)SuppliedItem; IEnumerable Items = new VDF.Vault.Currency.Entities.ItemRevision(m_VaultConnection,SuppliedItem); //PropDefs PropDef ItemPropDef = GetItemPropertyDefByName(PropertyName); //PropDef[] PropDefs = new PropDef[1]; //PropDefs[0] = ItemPropDef; List < PropDef > PropDefs = new List(); PropDefs.Add(ItemPropDef); //Object Prop = m_VaultConnection.WebServiceManager.PropertyService.GetPropertiesByEntityIds( //Object Prop = m_VaultConnection.PropertyManager.GetPropertyValue("Item", ItemPropDef, null); VDF.Vault.Currency.Properties.PropertyValues Props = m_VaultConnection.PropertyManager.GetPropertyValues(Items, PropDefs, null); } catch (Exception ex) { } finally { } return returnString; } I keep getting an invalid HTML error when I try and post the code.
Message 5 of 10
Mzwijacz
in reply to: Mzwijacz

The formating was messed up so am trying again. I think the problem is with the syntax of the new vdf calls for getproertyvalues public string GetItemPropertyByPropertyNameOld(Item SuppliedItem, string PropertyName) { string returnString = string.Empty; try { //Settings VDF.Vault.Currency.Properties.PropertyValueSettings Settings = new VDF.Vault.Currency.Properties.PropertyValueSettings(); //Items //Item[] items = new Item[1]; //items[0] = SuppliedItem; //List Items = new List(); //Items.Add(SuppliedItem); //VDF.Vault.Currency.Entities.EntityClass[] Items = new VDF.Vault.Currency.Entities.EntityClass[1]; /Items[0] = (VDF.Vault.Currency.Entities.EntityClass)SuppliedItem; IEnumerable Items = new VDF.Vault.Currency.Entities.ItemRevision(m_VaultConnection, SuppliedItem); //PropDefs PropDef ItemPropDef = GetItemPropertyDefByName(PropertyName); //PropDef[] PropDefs = new PropDef[1]; //PropDefs[0] = ItemPropDef; List PropDefs = new List(); PropDefs.Add(ItemPropDef); //Object Prop = m_VaultConnection.WebServiceManager.PropertyService.GetPropertiesByEntityIds( //Object Prop =_VaultConnection.PropertyManager.GetPropertyValue("Item", ItemPropDef, null); VDF.Vault.Currency.Properties.PropertyValues Props = m_VaultConnection.PropertyManager.GetPropertyValues(Items, PropDefs, null); } catch (Exception ex) { } finally { } return returnString; }
Message 6 of 10
Mzwijacz
in reply to: Mzwijacz

Every time I try and send the code the forum screws up the formatting.
Message 7 of 10
wayne.brill
in reply to: Mzwijacz

Hi,

 

I updated the Vault SDK ItemEditor sample so it gets a couple of properties. This sample is here on my system:

C:\Program Files (x86)\Autodesk\Autodesk Vault 2014 SDK\VS10\CSharp\ItemEditor

 

The attached zip file has the updated project. You will probably need to add the references back in to get it to build. It is not doing everything you wanted but it should be a starting point for getting properties of items.

 

Here is the function that gets the property. Some of the code is an update from an example in the SDK help. (LINQ is Your Friend - topic) 

 

//wB added

String myGetItemPropertyByPropertyNameOld(Item mySuppliedItem, string myPropertyName)

{

string returnString = string.Empty;

 

try

{

PropDef[] itemProps = m_connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("ITEM");

 

// use LINQ to query the array IEnumerable<PropDef> selection =

 

from propDef2 initemProps

 

wherepropDef2.DispName == myPropertyName

 

selectpropDef2;

 

if(selection.Count() == 0)

 

thrownewException("Property not found");

 

PropDefitemNamePropDef = selection.First();

 

long[] itemIdArray = new long[] { mySuppliedItem.Id };

 

PropInst[] propValues = m_connection.WebServiceManager.PropertyService.GetProperties(

 

"ITEM", itemIdArray, new long[] { itemNamePropDef.Id });

 

// LINQ will sort for you IEnumerable<PropInst> sortedValues =

 

from value in propValues

 

orderby value.Val

 

selectvalue;

 

PropInst[] values1 = sortedValues.ToArray();

 

PropInstmyPropInst = values1[0];

 

if (myPropInst.Val != null)

{

returnString = myPropInst.Val.ToString();

}

}

catch (Exceptionex) { }

 

finally{ }

 

return returnString;

}

//wB end added

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 8 of 10
wayne.brill
in reply to: wayne.brill

Hi,

 

I don't see the attachment. Adding again. (if it doesn't work I will email it to you)

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 9 of 10
Mzwijacz
in reply to: wayne.brill

Thank you for your response. A quick question. Why are you using the webserviceManager to access the root WebService API instead of using the Connection.PropertyManager ? Does this access the database using 2 hops as the old API does or does it access the database through the VDF 1 hop ?
Message 10 of 10
wayne.brill
in reply to: Mzwijacz

Hi,

 

I used the GetProperties of the PropertyService because GetPropertyValue() of PropertyManager takes an IEntity and Item does not derive from IEntity. I was getting a compile error or a runtime error when I tried to cast the Item. I ased a colleague in engineering about this. Here is an excerpt of their reply:

 

>> >>

While the Autodesk.Connectivity.WebServices.Item class does not implement the IEntity interface, the VDF’s Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.ItemRevision class does and can be constructed from an Item object. See this article for more info on converting between the web service proxy classes and VDF currency classes: http://help.autodesk.com/view/VAULT/Help/ENU/?guid=GUID-67E7D386-9361-4CA0-B878-E1B337A89AB6. Once you have the VDF’s ItemRevision instance, you should be able to use the PropertyManager to retrieve item properties. An additional benefit of using the VDF layer to retrieve properties is that it will handle caching for you.

 

I’m not sure what the one or two hops question is about, necessarily. Going through the VDF layer might result in multiple web service calls while going directly through the web services API will only result in one, but still, using the VDF layer typically will see better performance, I believe, because of optimizations such as caching.

<< <<

 

Thanks,

Wayne

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report