Greetings Friends,
What is the best way (least amount of keystrokes) to get Visual Studio 2010 to automatically insert the current date and my name/initials whenever I put a single line comment into my codebase? This should support C# and it'd be even better if it worked in my .aspx pages too.
Thanks -- I know someone out there has the perfect solution :).
Create a macro and assign a Shortcut key.
The easiest way is go to Tools->Macros->Macro Explorer and edit one of the samples, I used Samples->VSEditor, right click that one and edit.
Now youre in the Macro editor
Now create this function.
Sub NewCommentLinePersonal()
Dim textSelection As EnvDTE.TextSelection
textSelection = DTE.ActiveWindow.Selection
textSelection.NewLine()
textSelection.Insert(Utilities.LineOrientedCommentStart())
textSelection.Insert(" " + Date.Now + " - Your Initial ")
End Sub
then go to Tools->Options->Environment->Keyboard and type the NewCommentLinePersonal on textbox "Show commands containing:" then choose your shortcut key
Perhaps another way of approaching it, assuming the insertion of a timestamp and name is being done for change tracking, is to lean on source control.
For example, in my current codebase, we deprecated the use of putting in change comments, since we found that the field of green was cluttering things, and if I ever needed to see who changed what, I could simply look in our source control system, and even see how this one change was related to other modifications within the same changeset.
Related
Hello everybody,
around two or three month ago I started to learn Dynamo for Revit... finally :)
After learning and testing a lot, I got a few own scripts working. Then I learned Python, because I couldn't create the next script only with Dynamo-Nodes.
Then I thought "Let's see how difficult it is to get something done as a PlugIn".
I watched some Videos and read a lot of stuff.
Finally I got the Revit-AddIn-Wizard installed and made my first small Test-PlugIn.
Great...
Now I have a few problems which I do not understand... so I thought I will try my luck here... because I got so much information and help, reading through this site.
My goal was/is the following: (I tell you what I have now)
A form with a few buttons, comboboxes and a DataGridView.
I can load an Excelfile, click on "Show" to show it in the DataGridView.
The header of each row will be automatically put into 3 comboboxes.
In the first combobox you select the first search-parameter, in the second you CAN select another search-parameter and in the third combobox you select the parameter you want to set.
I have a checkbox to switch from type- to instance-parameter for the search- and the set-operation.
There is also a button which shows another small form with a list of categories (I won't search for ALL, only nearly all modelcategories).
PlugIn
I took me a lot of "watching Videos, reading through the internet, testing, testing and testing".
Thanks to this site here and a few others... I managed to get this whole PlugIn nearly 100% working.
But now I have a few strange issues and I have absolutely no clue on how to fix them or if it is possible. And I really hope that someone can help me.
First... I just tell you my problems and perhaps someone can say "this really IS an issue!" or that it is possible to get it done. Then I would post some code.
So... what do I do?!
1. I have a FilteredElementCollector which filters ALL elements.
2. Depending on my "Type/Instance-Checkboxes" I do .WhereElementIsElementType OR .WhereElementIsNotElementType.
3. Then it passes a MultiCategoryFilter to get the big list down to only the modelcategories.
4. Next, the collection passes one of ten different "methods" depending on all settings. There I filter this collection depending on the searchlists-comboboxes. When the combobox says "Familie" or "Typ" then it filters for ".BuiltInParameter.SymbolFamilyName" or ".Name" otherwise it just uses ".LookupParameter".
After that I have a collection with only the elements of selected categories which contains the values from the Excellist.
5. Depending on what my search- and set-settings are (e.g. search for type and set instance) I have to get the instances from the collected types or the other way around.
6. Then I pass it down to another method where I finally set the parameter.
So... Excelheader goes into comboboxes, depending on what you select in there it creates lists with the values of the selected rows.
I hope you all understand.
Now... where are my problems?
When I search for type-familynames or instance-parameter and set a typeparameter it works for ALL categories without any error.
1. When I try to set an instanceparameter (doesn't matter what my search-setting are) it works for all "normal" families but not for the systemfamilies (e.g. walls, floors, pipes etc.). No error, just nothing happens WHY? It seems that I cannot set an instance-parameter for system-families.
2. Roofs, Stairs, CurtainPanels and GenericModel make problems when I search for a typeparameter Error is something like "The object reference was not set to an object instance". Only with these 4 categories and it doesn't matter what I want to set... but when I search for family-/typeNAME or Instance-Parameter, then I can set type or instance and it works (except instance for sysfam).
3. When I try to search AND set an instance-parameter it works for ALL categories EXCEPT if one wall does not contain a search value... it really is enough that ONE wall does not have a search-param-value that everything will be cancelled.
I have a few other small problems... but I hope someone can help me with these problems... I would be extremely thankfull
greetings and have a nice day or night :)
Philipp
Tl; dr.
The three problems you describe sound like your own. I have no heard anybody else runAsk three separate questions and provide three separate minimal code snippets describing how they arise,. into those. I suggest that you create three separate independent minimal reproducible cases to demonstrate all three issues. Chances are, when you simplify and minimalise your code, the problem will go away. If it does not, it might just possibly be in a small and manageable enough state for other people to help you take a look at it. Given the long-winded description above, nobody in the world can help you.
Thank you for your answer Jeremy,
as I said, as a first start it is ok for me if you don't say "With theses categories, there are indeed some issues!"
I think I've managed to create 3 small examples of my problems.
For each problem I made a zip-file containing the complete visual-studio folder, a small exampleproject and a readme.txt with (I hope) enough information to understand everything in detail.
Problem1
Problem3
You only need to compile them or copy the .addin and .ddl files into the Revit AddIn folder. Then you get the new ribbons.
Short problem summary = I get problems when searching for parametervalues and setting values to another parameter.
Edit: I just solved the 2. problem when searching for familynames and setting system-families-parameter.
I used:
ElementClassFilter ecf = new ElementClassFilter(typeof(FamilyInstance));
FilteredElementColletor colle2 = new FilteredElementCollector(doc);
colle2.WherePasses(ecf);
I simply deleted the ClassFilter and do it now like in the other cases where I need instances.
FilteredElementCollector colle2 = new FilteredElementCollector(doc);
colle2.WhereElementIsNotElementType();
The 1. and 3. problem still exist :/
I would be thankful for any help someone can provide :)
Is it possible when debugging with visual studio to show the fields in an order not alphabetical?
Most times my objects have the usual "name" field but starting with n it ends much much lower in the list(yeah I know I could just call it aaaName) but i don't want to have to do it...
Can't vs just show with the order I put the fields on the code? If not is there a way to move the dispay fields around?
I have not seen any ordering in the debugger, but you can do something even better. With the DebuggerDisplay-Attribute you can change what the debugger by default displays. You can display the name for example. That's even easier than opening your object and looking for the name.
Quite some time ago I created a Powershell script to do what I wrote in the title: Copying a selection from File-A to File-B. The way I need it (and the way I did it) is to open a "Template" file when the application starts, the user selects a range, then they have 4 option buttons. The most-used is "Copy Selection", which will copy the contents of the range selection to all of the Excel files in a specific directory. With Powershell this works (although it took a long time to figure out) with the following code:
$strRow = $Excel.ActiveCell.Row
$strColumn = $Excel.ActiveCell.Column
$Range = $sourceWorksheet.Cells.item($strRow,$strColumn)
$Range.Select
$Excel.Selection.Copy() | Out-Null
foreach ($item in $files)
{
$destinationPath = $item.FullName
$destinationWorkBook = $Excel.WorkBooks.Open($destinationPath)
$destinationWorkSheet = $destinationWorkBook.worksheets.item(1)
$destRange = $destinationWorkSheet.Cells.item($strRow,$strColumn)
$destRange.Select
$destRange.PasteSpecial() | Out-Null
$destinationWorkBook.Close($true)
}
That works fine, but I obviously want to get rid of Powershell. I've created a C# application using WPF that will look and work great, I just have to get the logic working. I can't seem to actually target a range selection. I've tried a number of methods and properties, and none seem to get what I need. I can get the actual "selection" cell, but I can't get any type of range. The object I retrieve generally have Rows and Columns properties, so if need-be I guess I could extrapolate that information...but there's gotta be a better way.
Right now the closest thing I have would be to use Application.ActiveCell.Copy(); (or Select), but it seems to have issues when I try pasting it.
Any ideas? I can't seem to figure out why this isn't working.
EDIT: I've solved my own issue...sorry if anyone wasted time looking at this.
I'm an idiot...I spent a bit more time and figured out how to do it. The below code works perfectly - the main issue I was running into is that using Worksheet.Cells.item requires a bracket. I still have to loop through the documents to apply to, but this should take care of the actual logic:
int intRow = myApp.ActiveCell.Row;
int intCol = myApp.ActiveCell.Column;
myApp.Selection.Copy();
Range destRange = mySheet.Cells.Item[intRow,intCol];
destRange.PasteSpecial();
Hope I didn't waste anyone's time and they can figure this out now!
Is it possible to search inside an object for values and/or other field while debugging a C# application?
I'm looking for a deep search that can drill down the object for many levels.
What I'm looking for is a way to search (like F3 for documents search) inside very complex objects (while debugging, in the Quick watch window for example).
You could use OzCode (an add-on for Visual Studio), which lets you search for the members you want to see from within the on-hover-DataTip or the QuickWatch window.
See example in the following screenshot:
Full disclosure: I am the co-creator of "OzCode".
If you want to do whitout an add-on it can be done by going to the object list, selecting all objects (ctrl+a) and copy them to a searchable text-editor. This will give you a newline seperated list.
I think there is no built-in feature to lets you, dive in deep in the objects in debugging mode, Unless use extensions if available.
Besides Wilson Kao's post, you can also try the simplest approach that I use:
Put a breakpoint at a place where a variable referencing the object will be used.
Hover mouse over the variable when the breakpoint is hit. You should see a popup showing the top level properties of the object.
Use the little + buttons on the left to go deeper into the object. It could get confusing.
You can also pin certain properties that you find deep down so you don't have to look for them again and again (pin button appears on the right side of each property when you hover over the property)
Here's an exmaple of what it looks like (the variable is books):
Source: http://blogesh.wordpress.com/2008/09/09/visual-studio-debugging-tips-and-tricks/
Edit: There is a way to get all the properties and their values that you access through the manual hover-and-click method (ie in the above image, you can get ISBN and its value through code). However you have to use Visual Basic code. You can then do a search on the results for a specific value.
First, you need to go read up on Tracepoints and custom Macros:
Click and go to "TracePoints – Running a Custom Macro"
Also, here
Next you need to make a Macro to do what you want.
In Visual Studio, go to Tools -> Macros -> Macros IDE...
Add a new Macro. There should be a preset blank one called Module 1. In here, you add routines to do what you want. The following is a Macro I made that will go through a certain variable and output the properties of it (basically, output the data you get in the cover-and-click method). This outputs to the Output window, which you can open through View -> Output.
Sub DisplayAllProperties()
Dim outputWindow As EnvDTE.OutputWindow
outputWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object
Dim currentStackFrame As EnvDTE.StackFrame
currentStackFrame = DTE.Debugger.CurrentStackFrame
outputWindow.ActivePane.OutputString("*Dumping Local Variables*" + vbCrLf)
For Each exp As EnvDTE.Expression In currentStackFrame.Locals
If (exp.Name = "this") Then ' Here, I am only searching in a variable named "this"
outputWindow.ActivePane.OutputString("- " + exp.Name + ": " + exp.Value.ToString() + vbCrLf)
helperDisplay(exp.DataMembers, outputWindow, 1)
End If
Next
End Sub
Private Sub helperDisplay(ByRef exps As EnvDTE.Expressions, ByRef OutputWindow As EnvDTE.OutputWindow, ByVal n As Integer)
For Each ex In exps
helperTabs(n, OutputWindow)
If (ex.Name = "Non-Public members" Or ex.Name = "Static members") Then
OutputWindow.ActivePane.OutputString("~ " + ex.Name + ": There are " + ex.DataMembers.Count.ToString + vbCrLf)
Else
OutputWindow.ActivePane.OutputString("~ " + ex.Name + ": " + ex.Value.ToString() + vbCrLf)
If (ex.DataMembers.Count <> 0) Then
helperDisplay(ex.DataMembers, OutputWindow, n + 1)
End If
End If
Next
End Sub
Private Sub helperTabs(ByVal n As Integer, ByRef OutputWindow As EnvDTE.OutputWindow)
For i = 1 To n Step 1
OutputWindow.ActivePane.OutputString(vbTab)
Next
End Sub
This code is giving me exceptions for some DevExpress controls I tested it on. I think it's because some values can't be accessed. I have never coded in VB before so there are probably bugs in there...Play with it and see if it can do what you want (ie output only the properties that match what you need). The good part is, you can change the Macro code AS you are debugging, so no need to stop your project while you edit the Macro!
To use the Macro, you need to put a breakpoint somewhere in your code that will be hit, and will be able to access the object you want.
-> Right click the breakpoint and go to When Hit... Check off Run a macro: and select your Macro from the dropdown.
When you are in debug mode, go up to Debug on the menu bar, and go to the drop down menu of windows. There, you will see locals. This will tell you what values your variables are at your current breakpoints. You can also dive deep down into all of your objects as well through a tree menu. To look for a particular object, you can watch, and then input the variable you want to watch there. Make sure you have the breakpoints in the right place. Good luck!
I'm really sure that the title of my question depicts what i mean.i guess that's why i can't find that much on google.I think it needs to be explained.
Basically i've manage to pass programmatically discrete values to my report successfully.
Now i wanted to make use of the A4 paper format to have 2 A3 format.that means i want to have twice the display of the report.So i naively copy what i already did to the bottom of the report.The duplicated ones are not displaying for some reason.
The only workaround i can find is to create same set of parameters with different names and pass the same values to them.But that doesn't sound good to me and there are about 12 parameters.It should just be 24 if i want to do that.How you guys solve this?
Thanks for reading.
PS: using C#
Can you right click and choose Format Field and see if the "Suppress" or "Suppress if duplicated" field is ticked?