How do I customize the auto commenting text in Visual Studio? - vb.net

When I type the trigger the auto comment feature in Visual Studio (by typing "'''" or "///"), most of the XML commenting details show up that I like. However, I typically add the history tag to the documentation so I can track and changes that are made to the method over time.
Is there any way I can customize the auto commenting feature so that it will add the history tag, and potentially some generic Name - Date - Change placeholder text?

I'd suggest using GhostDoc. It generates very smart comments using /// based on your method names and parameters. Also, it is fully customizable.

I think that you could use a tool as dgarcia said but try to chose one that makes the version control insetad, Personally I'm not a huge fan of keep the "history" or track of the project using comments in the code.
If you like that way you could create your own customized version of the snippet, this is easier if you use a tool like Snippy
Copy this file to your
My Documents\Visual Studio 2005\Code Snippets[Language]\My Code Snippets\
Just be carefull to change the file if you gonna use it in VB.NET
Hope this help

Just as followup to the comment to Olivier. Here is a copy of the macro now, look for the '' Do History section to see where I inserted code.
''// InsertDocComments goes through the current document using the VS Code Model
''// to add documentation style comments to each function.
''
Sub InsertDocComments()
Dim projectItem As ProjectItem
Dim fileCodeModel As FileCodeModel
Dim codeElement As CodeElement
Dim codeElementType As CodeType
Dim editPoint As EditPoint
Dim commentStart As String
projectItem = DTE.ActiveDocument.ProjectItem
fileCodeModel = projectItem.FileCodeModel
codeElement = fileCodeModel.CodeElements.Item(1)
''// For the sample, don't bother recursively descending all code like
''// the OutlineCode sample does. Just get a first CodeType in the
''// file.
If (TypeOf codeElement Is CodeNamespace) Then
codeElement = codeElement.members.item(1)
End If
If (TypeOf codeElement Is CodeType) Then
codeElementType = CType(codeElement, CodeType)
Else
Throw New Exception("Didn't find a type definition as first thing in file or find a namespace as the first thing with a type inside the namespace.")
End If
editPoint = codeElementType.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint()
''// Make doc comment start.
commentStart = LineOrientedCommentStart()
If (commentStart.Length = 2) Then
commentStart = commentStart & commentStart.Chars(1) & " "
ElseIf (commentStart.Length = 1) Then
commentStart = commentStart & commentStart.Chars(0) & commentStart.Chars(0) & " "
End If
''// Make this atomically undo'able. Use Try...Finally to ensure Undo
''// Context is close.
Try
DTE.UndoContext.Open("Insert Doc Comments")
''// Iterate over code elements emitting doc comments for functions.
For Each codeElement In codeElementType.Members
If (codeElement.Kind = vsCMElement.vsCMElementFunction) Then
''// Get Params.
Dim parameters As CodeElements
Dim codeFunction As CodeFunction
Dim codeElement2 As CodeElement
Dim codeParameter As CodeParameter
codeFunction = codeElement
editPoint.MoveToPoint(codeFunction.GetStartPoint(vsCMPart.vsCMPartHeader))
''//editPoint.LineUp()
parameters = codeFunction.Parameters
''// Do comment.
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.LineUp()
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "<summary>")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "Summary of " & codeElement.Name & ".")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "</summary>")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)
For Each codeElement2 In parameters
codeParameter = codeElement2
editPoint.Insert("<param name=" & codeParameter.Name & "></param>")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)
Next ''//param
''// Do history tag.
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.LineUp()
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "<history>")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "Name MM/DD/YYYY [Created]")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart & "</history>")
editPoint.Insert(Microsoft.VisualBasic.Constants.vbCrLf)
editPoint.Insert(Microsoft.VisualBasic.Constants.vbTab & commentStart)
End If ''//we have a function
Next ''//code elt member
Finally
DTE.UndoContext.Close()
End Try
End Sub
For some reason, after a save, rebuild, and a restart of Visual Studio, I'm not getting the history tag. Can anybody see something here I'm missing?

vb uses a xml file to load the defults. It is VBXMLDoc.xml and it depends on what version you are running as to the location of the file.

Related

Open a file in a new instance of program

All;
I have a bit of code I've written that opens a design blueprint when I scan a bar code. It works well enough, but I'd like to open a new instance of the design software (Solidworks) and have the print display in the new instance. Right now, no matter how many Solidworks instances I have open, the print will only open in the first instance started.
The line commented out below is the line that works, just not in the right instance. The line below that is what I'd expect to work, but it returns a 'file not found' even though the path to solidworks and the print path are both correct.
Any explanation as to why this isn't working would be much appreciated as I'm obviously very new at this...and have no idea what I'm doing.
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim barcode As String = tb_barcode.Text
Dim filename As String = tb_barcode.Text
'Add File Extension to end of path
Dim ext As String = ".SLDDRW"
'Split job number from detail number in barcode textbox
barcode = Split(tb_barcode.Text, ".")(0)
filename = Split(tb_barcode.Text, ".")(1)
'- This works, just in primary instance
'System.Diagnostics.Process.Start("G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext)
'- This does not work
System.Diagnostics.Process.Start("'C:\Program files\Solidworks Corp\Solidwork\SLDWORKS.exe' 'G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")
Catch
MessageBox.Show("File Not Found")
End Try
End Sub
Sorry for naive approach but shouldn't there be a comma in Process.Start between 2 arguments?
Start(String, String)
Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component. docs
Why don't you use the Application.ExecutablePath.That returns the Application's path with its full name. Then your code should be
System.Diagnostics.Process.Start(Application.Executablepath, "G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")
Also make sure that the second string argument is a valid path.

How do I display the value of a shared parameter using an Element collector in Revit?

Thanks in advance for the help. I have no idea what I'm doing wrong and it's becoming very frustrating. First, a little background...
Program: Revit MEP 2015
IDE: VS 2013 Ultimate
I have created a Shared Parameter file and added the parameters in that file to the Project Parameters. These parameters have been applied to Conduit Runs, Conduit Fittings, and Conduits.
I'm using VB.NET to populate the parameters with no issue. After the code runs, I can see the expected text applied in the elements property window. Here is the code used to populate the values:
Populate:
Dim p as Parameter = Nothing
Dim VarName as String = "Parameter Name"
Dim VarVal as String = "Parameter Value"
p = elem.LookupParameter(VarName) <-- elem is passed in to the function as an Element
If p IsNot Nothing Then
p.Set(VarVal)
End if
Here's where I run into the error. When I attempt to retrieve the value, I am able to get the parameter by the parameter's definition name, but the value is always blank. Here is the code used to retrieve...
Try
For Each e As Element In fec.OfCategory(BuiltInCategory.OST_ConduitRun)
sTemp = sTemp & "Name: " & P.Definition.Name & vbCrLf & "Value: " & P.AsString & vbCrLf & "Value As: " & P.AsValueString & vbCrLf & vbCrLf
sTemp2 = sTemp2 & "Name: " & GetParamInfo(P, doc)
Next
MessageBox.Show(sTemp)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
The message box shows all of the parameter names correctly, and for the Revit parameters it gives me a value. The Shared parameters, however, only show the parameter names, the values are always blank. Is there another way that I'm supposed to be going about this? Oddly, I'm able to see the shared parameter values if I use a reference by user selection like so...
Dim uiDoc As UIDocument = app.ActiveUIDocument
Dim Sel As Selection = uiDoc.Selection
Dim pr As Reference = Nothing
Dim doc As Document = uiDoc.Document
Dim fec As New FilteredElementCollector(doc)
Dim filter As New ElementCategoryFilter(BuiltInCategory.OST_ConduitRun)
Dim sTemp As String = "", sTemp2 As String = ""
Dim elemcol As FilteredElementCollector = fec.OfCategory(BuiltInCategory.OST_ConduitRun)
Dim e As Element = Nothing, el As Element = Nothing
Dim P As Parameter
pr = Sel.PickObject(ObjectType.Element)
e = doc.GetElement(pr)
For Each P in e.Paramters
sTemp = sTemp & "Name: " & P.Definition.Name & vbCrLf & "Value: " & P.AsString & vbCrLf & "Value As: " & P.AsValueString & vbCrLf & vbCrLf
sTemp2 = sTemp2 & "Name: " & GetParamInfo(P, doc)
Next
MessageBox.Show(sTemp)
With the method above, when the user selects the object directly, I can see the values and the names of shared parameters. How are they different?
Is there some sort of binding that I should be looking at when the value is set to begin with? Thanks in advance for everyone's help.
Regards,
Glen
Holy Bejeesus... I figured it out, but I'm not sure why the methods are that different from each other... if anyone had any insight, that'd be great.
I wanted to post the answer here, just in case anyone else is fighting with the same thing, so... you can see the method I was using to try to read the parameters above. In the method being used now there are only a couple of things that are different... 1) An element set... 2) An active view Id was added as a parameter to the FilteredElementCollector... 3) A FilteredElementIterator was implemented.
As far as I can tell it's the iterator that's making it different... can anyone explain what it's doing differently?
Below is the method that actually works...
Public Sub Execute(app As UIApplication) Implements IExternalEventHandler.Execute
Dim prompt As String = ""
Dim uiDoc As UIDocument = app.ActiveUIDocument
Dim doc As Document = uiDoc.Document
Dim ElemSet As ElementSet = app.Application.Create.NewElementSet
Dim fec As New FilteredElementCollector(doc, doc.ActiveView.Id)
Dim fec_filter As New ElementCategoryFilter(BuiltInCategory.OST_Conduit)
fec.WhereElementIsNotElementType()
fec.WherePasses(fec_filter1)
Dim fec_i As FilteredElementIterator = fec.GetElementIterator
Dim e As Element = Nothing
fec_i.Reset()
Using trans As New Transaction(doc, "Reading Conduit")
trans.Start()
While (fec_i.MoveNext)
e = TryCast(fec_i.Current, Element)
ElemSet.Insert(e)
End While
Try
For Each ee As Element In ElemSet
GetElementParameterInformation(doc, ee)
Next
Catch ex As Exception
TaskDialog.Show("ERROR", ex.Message.ToString)
End Try
trans.Commit()
End Using
End Sub
At any rate, thanks for any help that was offered. I'm sure it won't be the last time that I post here.
Regards,
Runnin

Retrieve CustomXMLParts in Excel Addin using VB.NET

I'm needing a little help retrieving the values stored in a CustomXMLPart in an Excel Addin using VB.NET. I've searched and haven't found a lot of detail on this. From what I've found, the code that I have should work. At first, I thought my xml part wasn't being added so to persist across sessions, but I displayed the count of the CustomXMLParts collection before (3) and after (4) adding my custom xml part and the count did increase by one. I, also displayed the count upon opening the saved Excel workbook and it was the same number (4) after adding my CustomXMLPart to the collection. Here's the pertinent code below. Any help would be greatly appreciated. Need more information just let me know.
In the Excel addin, I have a popup window where I ask for user input and that's the information that I need to persist. In the code behind, that's where I create the xml and add to the collection.
Code:
Dim workbook As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
Dim xml As String
xml = "<?xml version=""1.0"" encoding=""utf-8"" ?>" _
& "<refreshViewPointData xmlns=""http://refreshviewpointdata.com"">" _
& "<dataReference>" _
& "<system>" & cboSystem.Text & "</system>" _
& "<library>" & cboLibraries.Text & "</library>" _
& "<view>" & txtObject.Text & "</view>" _
& "<headers>" & chkInclColumnHdrs.Checked.ToString() & "</headers>" _
& "<numOfRecords>" & txtRowCount.Text & "</numOfRecords>" _
& "<reference>" & txtReference.Text & "</reference>" _
& "</dataReference>" _
& "</refreshViewPointData>"
workbook.CustomXMLParts.Add(xml, System.Type.Missing)
In the ThisAddIn_Startup() method of ThisAddIn.vb file is where I attempt to retrieve the CustomXMLPart. I call a RetrieveCustomXMLPart() method from ThisAddIn_Startup().
Code for RetrieveCustomXMLParts():
Dim parts As Microsoft.Office.Core.CustomXMLParts
parts = Application.ActiveWorkbook.CustomXMLParts.SelectByNamespace("http://refreshviewpointdata.com")
If parts.Count > 0 Then
RefreshData(parts.ToString())
End If
Code for RefreshData():
Dim r As New RibbonViewPoint
Dim viewXMLPart As New XmlDocument
Dim system, library, sObject, reference As String
Dim headers As Boolean
Dim numRecords As Integer
'Load the xml from the string.
viewXMLPart.LoadXml(part)
'Retrieve the values from the xml document.
system = viewXMLPart.SelectSingleNode("/dataReference/system").Value
library = viewXMLPart.SelectSingleNode("/dataReference/library").Value
sObject = viewXMLPart.SelectSingleNode("/dataReference/view").Value
headers = CType(viewXMLPart.SelectSingleNode("/dataReference/headers").Value, Boolean)
numRecords = CType(viewXMLPart.SelectSingleNode("/dataReference/numOfRecords").Value, Integer)
reference = viewXMLPart.SelectSingleNode("/dataReference/reference").Value
'Call method to run the object to refresh the data.
r.RunSelectedObject(system, library, sObject, headers, reference, numRecords)
In the RetrieveCustomXMLPart() method, the SelectByNamespace() method is not returning my CustomXMLPart that clearly has the same namespace as what I'm passing in. Anyone know what's wrong?
Also, if anyone has any insight on something else I didn't understand that would be great as well. In the RefreshData() method, I made the viewXMLPart variable as an XMLDocument to load the data and get the values from there. Prior to I had it defined as "Dim viewXMLPart As New Microsoft.Office.Core.CustomXMLPart", which kept giving me a syntax error saying that "'Microsoft.Office.Core.CustomXMLPartClass.Friend Sub New()' is not accessible in this context because it is Friend."
Thanks!!!
Found a solution. The below is what worked.
Dim workbook = Application.ActiveWorkbook
Dim customXMLParts = workbook.CustomXMLParts.SelectByNamespace("urn:viewpoint-refresh")
Dim customXMLPart = customXMLParts.Cast(Of CustomXMLPart)().FirstOrDefault()

Issue with an LPR Command in VB

I am creating a VB app which will "move" xls reports from a directory to a ReportSafe app. I am also working in an existing VB app which does just that, so I am using it for reference.
It isn't as simple as moving files from one directory to another, because ReportSafe requires an lpr command to tell it (ReportSafe) which file to pick up.
Here is what I have so far:
Imports System.IO
Module Module1
Sub Main()
''Declarations
Dim Files As ArrayList = New ArrayList()
Dim FileName As String
''Write All Files in *directory* to ReportSafe
Files.Clear()
Files.AddRange(Directory.GetFiles(*directory*))
For Each FileName In Files
Dim RPname As String
Dim RealName As String
RPname = FileName.ToString
RealName = "/"
RealName = RealName & RPname.Remove(0, 34)
Dim a As New Process
a.StartInfo.FileName = "C:\Windows\system32\lpr.exe"
a.StartInfo.Arguments = "-S*ServerName* -Plp -J" & Chr(34) & RealName & Chr(34) & " " & Chr(34) & RPname & Chr(34)
a.StartInfo.UseShellExecute = False
Next
End Sub
End Module
The whole lpr command/arguments are throwing me for a loop. I'm not sure if my question is specific to ReportSafe, and if that's the case, I may be out of luck here. I have pulled this code from the already existing app which moves reports to ReportSafe, and adjusted for my own use, but no luck so far.
FYI, I had to turn on LPR Monitor services to obtain to the lpr.exe
Questions:
What are the proper arguments to pass through to this lpr command?
Is there a problem with the logic that is causing the issue?
I continued to tinker and look at my reference code and discovered some flaws in logic:
For one, the report name I was passing did not include the complete file path.
Another thing is that I never started the process with a.Start(). Rookie mistakes for sure... haha

Adding icons to application

I am trying to add to my application some icons via the code.
When i run my executable from debug / release compilation folder it works good .
But when I move my executable files to other folders it tells me that it doesn't find the icon files .
Any idea how/where I should tell the compiler to add those files to my final executable version ,that they will be visible .
my code looks like that
Private Sub Set_Application_Icon()
Dim Current As String
Dim Parent As DirectoryInfo
'current path is /bin/solution/
Current = Directory.GetCurrentDirectory()
Parent = Directory.GetParent(Current)
ChDir(Parent.FullName)
'/bin
Current = Directory.GetCurrentDirectory()
Parent = Directory.GetParent(Current)
ChDir(Parent.FullName)
'icons located at current directory now
#If WizardVersion = 0 And ViewerVersion = 0 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009c.ico")
#ElseIf WizardVersion = 0 And ViewerVersion = 1 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009v.ico")
#Else
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009.ico")
#End If
End Sub
thanks a lot for help
I suggest you look into adding icons as Resources, instead of referencing them as external files.
#If WizardVersion = 0 And ViewerVersion = 0 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009c.ico")
#ElseIf WizardVersion = 0 And ViewerVersion = 1 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009v.ico")
#Else
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009.ico")
#End If
First, those are compile time conditional statements. Not sure if you were wanting that evaluated at compile time, or run time. Second, CurDir is considered unreliable in determining application directory. In VS 2008, you can use the application's My namespace (My.Application.Info.DirectoryPath), or use Reflection to get the application's path. Last, as a previous answerer mentioned, the most reliable/portable way to do this would be to add the icons to your project as embedded resources. Hope that helps.
EDIT: The last link that I posted (embedded resources) shows how to do that. Here is a method from that article that retrieves an embedded icon from the assembly using Reflection.
Function GetEmbeddedIcon(ByVal strName As String) As Icon
Return New Icon(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strName))
End Function
That should do it for you.