Customize Menu to Add New Custom Object

Customize Menu to Add New Custom Object

Anonymous
Not applicable
1,135 Views
3 Replies
Message 1 of 4

Customize Menu to Add New Custom Object

Anonymous
Not applicable

Hi,

 

I am using Data Standards with PowerVault trying to modify the default RMB Context menu entry to create "New Custom Object..." and I wanted kindly request for some assistance, as my programming skills are not that good to be honest.

 

I have created a Custom Object Definition in the Vault client called "Companies" and created three companies inside by using the default context-menu command that appears when you RMB (Right-Mouse-Button) the "Companies" Object definition.

 

I would like to modify the dialog box that this command fires up, or even better, to create my own RMB context menu command and my own XAML form that I am creating in Visual Studio.

 

In the "mymenu.mnu" file, I have created a new 'item' and 'site' as per below:

 

item newCompanyObj
{
    Description = "$UIString[MNU24]";
    Id = "myNewCompanyObject";
    Hint = "$UIString[MNU25]";
    Label = "$UIString[MNU26]";
    MultiSelectEnabled = false;
    NavigationTypes = [{$UIString[MNU30]}];
    ToolbarPaintStyle = TextAndGlyph;
    PSFile = "NewCompanyObject.ps1";
    Image="icon-building.ico";
}

 

site Company
{
    Id="DSCompany";
    Label="Company";
    DeployAsPulldown=false;
    Location={Company,ContextMenu};
    MenuItems=[$newCompanyObj];
}

 

My first question in the above file is: How do I get my command to appear when I actually RMB on the Custom Object Definition ("Companies") and not when I RMB on one of the companies instance I have already create, which is what is happening with the code above?

 

I have tried to research this and from what I understand, I might have to create my SelectionTypeId... I think I have the right code to do that below, but I have no idea where to place this code to get to work.

 

$selectionType = New-Object -TypeName Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId {Company}

 

Anyway, at the moment I can see my command (in the wrong place) and it fires up my XAML form, but I am then struggling to get it to actually create my Custom Object entry (New Company) - Please see code below for "NewCompanyObject.ps1"

 

Import-Module powerVault
$companyId = $vaultContext.CurrentSelectionSet[0].Id

$dialog = $dsCommands.GetCreateCustomObjectDialog($companyId)
$xamlFile = New-Object CreateObject.WPF.XamlFile "CustomEntityXaml", "%ProgramData%\Autodesk\Vault 2016\Extensions\DataStandard\Vault\Configuration\Company\Company.xaml"
$dialog.XamlFile = $xamlFile

$SelectionType = New-Object -TypeName Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId(SelectionTypeId.Company)

$result = $dialog.Execute()
$dsDiag.Trace($result)

if($result)
{
$customObjects = $vault.CustomEntityService.GetAllCustomEntityDefinitions() | Where-Object { $_.dispName -eq "Company" }
 
$SelectionType = New-Object -TypeName Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId {Company}
$companyName = "TEST COMPANY"
$newCompany = New-Object -TypeName $vault.CustomEntityService.AddCustomEntity ($customObjects.Id, $companyName)
}

 

The error I am getting is:

New-Object : Cannot find type [Autodesk.Connectivity.WebServices.CustEnt AddCustomEntity(long custEntDefId, string name)]: make sure the assembly containing this type is loaded.

 

I am probably using the wrong assembly but I have no way to find out what is needed... I noticed in some of Marco Mirandole's videos of PowerVault, there is an extra toolbar on the right with Command Lets but I have no idea how to activate this.. I have installed PowerGate, PowerJobs but this is still not available. I am generally struggling to find an effective way to be able to dig into the different functions available and their syntax.

 

A prompt response and assistance would be greatly appreciated.

 

Best Regards,

Vas

0 Likes
1,136 Views
3 Replies
Replies (3)
Message 2 of 4

wangdu
Collaborator
Collaborator

Hi Vas,

 

Here is my take on your questions.

 

My first question in the above file is: How do I get my command to appear when I actually RMB on the Custom Object Definition ("Companies") and not when I RMB on one of the companies instance I have already create, which is what is happening with the code above?

 

It is the same behaviour on the Sample "Task" provided with the DataStandard. If you want, you can try to add it to some other location e.g "AdvancedToolbar" if it is more convenient for you.

 

The error I am getting is:

New-Object : Cannot find type [Autodesk.Connectivity.WebServices.CustEnt AddCustomEntity(long custEntDefId, string name)]: make sure the assembly containing this type is loaded.

 

The script for adding the custom object which you have placed inside the "if($result)" doesn't need to be there in the first place. Since, when the user clicks on the "OK" button, DataStandard is creating the custom object for you including the properties. This isn't the answer to why the error is coming up, but ...

 

 

I noticed in some of Marco Mirandole's videos of PowerVault, there is an extra toolbar on the right with Command Lets but I have no idea how to activate this.. I have installed PowerGate, PowerJobs but this is still not available. I am generally struggling to find an effective way to be able to dig into the different functions available and their syntax.

 

I think you are talking about powershell ISE. In that case, to display the right hand side "Commands" toolbar, you need to activate it like this:

View->Show Command Add-on.

 

Don't forget to hit "Accept as Solution" or kudos, if this post has been helpful.

 

Wangdu

www.coolOrange.com

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Wangdu,

 

Thank you very much for the information, they are useful indeed but I am still had a few question on these if that's alright, again apologies for my lack of programming knowledge in this case... still trying to get my head around this.

 

In regards to the Context menu command, I have replicated the "Task" sample correctly in this case, haven't I? What I was looking to do it to place my command and add it below or replace the RMB cntext menu for the Custom Object definition (please see creenshot attached). If that is not possible then I will indeed add it to the "AdvancedToolbar" menu instead.

 

In regards to actually creating a new "Comapny" object and my powershell code, I am struggling to understand the code.. what does "if($result)" loop actually do? If I place the line below outside the "if($result)" loop still nothing happens (no new company created).. when I try the same action in PowerVault, I still get the same error.

 

Finally, in regards to the "Commands" Toolbar... please see screenshot attached, in PowerVault ISE I haven't got the option you mention to show Command Add-On at all.

 

Further help to these issue would be much appreaciated.

 

Many thanks & regards,

Vas

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi Wangdu,

 

Regarding my second question on how to actually create the custom object "Company" and the PS1 code.. you were right, I managed to find the solution using the example from CoolOrange...

 

#$vaultContext.ForceRefresh = $true
$selectionSet = $vaultContext.CurrentSelectionSet[0]
$id= $selectionSet.Id
$dialog = $dsCommands.GetCreateCustomObjectDialog($id)

$xamlFile = New-Object CreateObject.WPF.XamlFile "CustomEntityXaml", "%ProgramData%\Autodesk\Vault 2016\Extensions\DataStandard\Vault\Configuration\Company\Company.xaml"
$dialog.XamlFile = $xamlFile

$result = $dialog.Execute()
$dsDiag.Trace($result)

if ($result)
{
    $entityNumber = $dialog.CurrentEntity.Num
    $entityGuid = $selectionSet.TypeId.EntityClassSubType
    $selectionTypeId = New-Object Autodesk.Connectivity.Explorer.Extensibility.SelectionTypeId $entityGuid
    $location = New-Object Autodesk.Connectivity.Explorer.Extensibility.LocationContext $selectionTypeId, $entityNumber
    $vaultContext.GoToLocation = $location
}

 

This seems to do the trick... Many thanks!

 

Please let me know if there are any further feedback to the other question when you get the chance.

 

Best Regards,

Vas

0 Likes