Pass parameter value to Revit family using .net api - vb.net

I want to pass the parameter values to Revit family.I have spend many hours on google. In result i got few links which tells Read and Write Parameter Values with VB.NET
Read and Write Parameter Values with VB.NET
in this example we are fetching parameters and writing a value in text file called ParametersValue.txt. But i am confused, how should i pass this file to Revit?
I'm hoping someone can steer me in the right direction. I would really appreciate it!

One of the first things I would do after downloading the SDK mentioned in the previous post, is install the included revit lookup addin. This has been incredibly valuable in figuring what elements are called in the API, as well as determining which storage type the parameter is using. If all of the parameters you want to update are strings, those will be fairly straightforward to set from your text file. However, if,for example, the parameter value that you think is a string is actually set by an elementid, then there will be some coding involved to get the proper info to set the parameter value.

You can easily pass parameters to component families using "FamilyManager" class. The FamilyManager class provides access to family types and parameters. Just get the parameter and set its value. As we are working in family editor for component families, we have to load the parameter values in the project. I have tried this on Revit 2019. You have to
Open family in family editor
Activate the plugin
Click on Load into Project button on addins ribbon.
Then check the parameter value in the properties of that family.
Public Sub SetParamtersForComponentFamilies(ByVal doc As Document, ByVal parameterValue As String)
Dim f As Family = doc.OwnerFamily
Using trans As Transaction = New Transaction(doc, "Creating transaction for parameters")
trans.Start()
Dim familyMgr As FamilyManager = doc.FamilyManager
Dim n As Integer = familyMgr.Parameters.Size
Dim comment As FamilyParameter = familyMgr.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS)
familyMgr.Set(comment, parameterValue)
TaskDialog.Show("Paramters", "TypeComments : Updated")
trans.Commit()
End Using
End Sub

I use C# when writing Revit API code because that's what all the samples are written in, but I might be able to get you pointed in the right direction with some additional details. Are you looking to assign a value to a specific parameter? For example: Height=30"?
If so you first have to "get" the parameter. In the example in spidernet he goes through every parameter of a selected element:
Dim element As Autodesk.Revit.DB.Element = SelElement(cmdData.Application.ActiveUIDocument.Selection).Element 'Prompts you to select an element
For Each p As Parameter In element.Parameters 'Goes through every parameter in "element" and assigns the parameter to "p"
If p.Definition.Name = "Height" Then 'Check if "p" is the name you want, "Height"
p.Set(2.5) 'Because Revit knows FEET, so in order to type in 30in you use 2.5
End If
Next 'Loop through parameters
If you're looking for it to do something else, please post again.
Also, not sure you're aware, but a blog that is FULL is great Revit API info is Jeremy Tammik's: http://thebuildingcoder.typepad.com. A lot of his examples are C#, which is why I started learning C# instead of VB.NET.
If you don't have it already, make sure you get the SDK for Revit 2014 here: http://images.autodesk.com/adsk/files/Revit2014SDK_RTM0.exe
It has a TON of samples that might help too. Good Luck!

Related

Fill a boolean array from checkbox control array

My program creates an array of checkboxes at runtime as shown below:
For Looper = 0 To 36
Dim Ex1ConfigCheck As New CheckBox
frmSetup.Controls.Add(Ex1ConfigCheck) ' Add Control to from
Ex1ConfigCheck.Top = (Looper + 45) + (Looper * 18) ' Set Location
Ex1ConfigCheck.Left = 210
Ex1ConfigCheck.Text = Setup.ExCheckName(Looper) ' Set Text property from strArray
Next
This is where I don't know how to proceed.
I would like to fill a boolean array (ex. MyBoolean(37)) with the value of Ex1configCheck().Checked. The reason I would like to fill another array is because I need to be able to reference the value of the checkboxes in other parts of the code but can't access them until they are created. Also, I plan on saving the array out to a binary file.
Could someone point me in the right direction please?
If there are no other CheckBoxes in the same container as those ones then you can do this:
Dim flags = Me.Controls.OfType(Of CheckBox)().
Select(Function(cb) cb.Checked).
ToArray()
If the controls are in a different container than the form itself, replace Me with that container.
As suggested by #Jimi, you could also create a List(Of CheckBox) and assign that to a field, populating it when you create the controls. You can then use that list instead of creating one on demand:
Dim flags = myCheckBoxList.Select(Function(cb) cb.Checked).
ToArray()
Of course, if you know exactly how many CheckBoxes you are going to be adding, why do you need to wait until run time to create them? Why can't you create them at design time and then modify them at run time? You usually only create controls at run time if you don't know how many there will be until run time, but that seems not to be the case here.
Thanks all for your answers and comments. I always have a fear of being roasted when I ask what some may consider a simple question online.
I have found an alternative way of accomplishing my task. Instead of creating 8 "Arrays" of checkboxes, I have learned of a very simple control available called "CheckedListBox".
I really didn't need to create the checkboxes at runtime but was trying to find an easier way to create 8 groups of 37 checkboxes without having to manually name and set the properties of each one during design. I also wanted to be able to index them in my code to be able to update and read the value using simple loops. I could have done this by creating arrays of CheckBox but again, I would have had to manually initialize the arrays.
Once I found the CheckedListBox, I was able to accomplish what I want very quickly. I only had to set the properties of the 8 "groups" (CheckedListBox's) and fill them using the items property. The ListBox essentially created a List like Jimi suggested automatically and I can index thru each list with a loop as desired. Jimi's suggestion actually lead me to finding the CheckedListBox while I was searching for more information on using "List(of CheckBox)".
Sometimes talking to others helps me find the right questions to ask. Google was able to figure out what I wanted when I searched for "List(of CheckBox)". (:

VB Stored Reference Lists

I've successfully developed a good portion of a project i'm working on. To add greater functionality and ease coding I'd like to have a "reference list" of properties to bridge the gap between the UI and code. A lot of the code will end up looking like:
object.property(SuperLongStringWhichActsAs.Integer.AndIsUnusableInUI)
or
object.property(integer)
So the integer relating to the "width" property might be 1, with a possible substitute value of "bunchoftext.efields.width", and I'd like to show it in the UI as "Width". If the user selects "Width" in the UI, I'd like the returned value to be "1" for use in code, as "object.property(Width)" will not work, but "object.property(1)" will.
Is there any way to store a list of strings and their related values to be referenced by the program?
Thanks in advance for any help!

Visual Basic Web Browser change form when certain webpage content detected

I am trying to make a form on VB.NET that when a certain webpage is loaded into the web browser (in this case its a .txt file with a string of numbers). It will look for those numbers and if it finds them it will close that form and open another. I have tried to do it many times and my latest attempts came out with this code. Any help would be appreciated.
Dim passcontents As String
passcontents = WebBrowser.DocumentText = "test.com/test.txt"
If WebBrowser.DocumentText = "test.com/test.txt" And passcontents Then
ActualGen.Show()
Me.Close()
Else
End If
There are a couple of basic problems with the code you've posted.
1) Are you trying to test passcontents as a boolean or a string? You've defined it as a String, but then you are trying to assign the equality of two other strings to it, as you would a Boolean.
Try setting Option Strict On at the top of your code - it gives a few more helpful pointers to check in this case.
2) The If... Then condition is checking the same data as passcontents (may) already be providing. Are you just trying to check that the correct page is loaded, or do you want to check for certain page contents as well?
You appear to be getting mixed up between the browser's document URL and the loaded document contents.

Get Values from Listbox for if functions

Hey guys very new here.
Have a listbox that gets account names from a specific game server using this command line
Dim apikeyinfo As APIKeyInfo = api.getApiKeyInfo()
lstbxCharacters.DataSource = apikeyinfo.Characters
this code gets all the characters in a single account by displaying it in a listbox.
Now i would like to reference a character from the lisbox but not sure how
Any method such as Listbox.Get to get the value and compare it with something else?
Thanks
you can try something like
lstbxCharacters.SelectedItem
Update
To read the data from the listbox I think there are multiple ways (Assuming that it is readable).
-> Usually listbox display strings, so it should work to read to a string variable
Dim a_string as Strin = lstbxCharacters.SelectedItem
also you may like to add a small check before, assuring that an Item is currently selected:
If lstbxCharacters.SelectedIndex < 0 then return
This jumps out of current sub if no item is selected
And finally, to read the first entry, you can also do it this way:
a_string = lstbxCharacters.Items(0)
if it returns objects, then instead of accessing the object directly, it may work to do
a_string = lstbxCharacters.Items(0).ToString
(most objects allow a .ToString() Function )
Here two ideas for different solutions:
As a user commented, you could access the DataSource directly + the information which listIndex was selected. But if you do so, then maybe it is more easy (if you need to access it anyways, to go with solution 2)
Create a variable of type list(Of some_object) and fill it with the data from the datasource. It will take some time to do this, but if you define for the class some_object a function ToString, then you can fill all objects directly to the lstbxCharacters, and access them without any worries, by doing CType(lstbxCharacters.SelectedItem, some_object)
Update 2
If with reference you mean to access further information from the datasource, then you need to build some kind of query, or set the content of the listbox in relation to another control that shows the database content (in that way the listbox lstbxCharacters would act like a filter)

How to run a string as a command in Visual Basic (VB.NET)

i am running a Sub which takes as arguments a Datatable and a String.
Private Sub Populate(ByVal dttemp As DataTable, ByVal strWhichPart As String)
At one point there is a combobox which is populated with some of the data in the datatable. The name of the combobox is cmd plus the name of the string for example when the string is Person_FirstName the name of the combobox is cmbPerson_FirstName. Then i add items to the combobox like this:
cmbPerson_FirstName.Items.Add(strHold(rr))
My question is this can i make a String into a command? Because i have many comboboxes which have the same name as the string argument of the sub how can i do something like this to work
strWhichPart.Items.Add(strHold(rr))
in which strWhichPart is a string. Is there a command that i can execute a string as a command?
Thank you.
If I understand correctly, just grab the correct control from the Form's Controls collection using the string as the key:
CType(Controls(strWhichPart), ComboBox).Items.Add(strHold(rr))
You can use reflection to achieve this by creating an assembly with the code in a method, but its really not recommended. As in, it's insane. I suspect there are no problems in .NET development that need this approach.
Rather than using this approach, actually pass the relevant combo box as an argument - not an arbitrary string. Combo boxes are objects like anything else. You could create a dictionary which allows you to lookup combo boxes by a string. Something like:
Dictionary(Of String, ComboBox) MyDictionary = new Dictionary(Of String, ComboBox)()
MyDictionary.Add("ComboBoxA", objComboBoxA)
ComboBox objTheComboBox = MyDictionary("ComboBoxA")
The name you give your objects should not be semantically relevant in your code. If I name an object "lstMyObjectNamedThisWayForAReason1" I should NOT be using that to reference it. Instead, there should be a separation between what constitutes a GUI element and how it is referenced.
For example, if I create a WinForms GUI and reference all the items directly, then later have to write another front-end using a different framework I have to rewrite every reference. This isn't a problem if you don't tie your logic directly into your controls.
The only reason to tie them together is laziness and lack of respect for co-workers who might have to improve on your code in future. Why should they care what the GUI looks like? They might not even be using Visual Studio! They certainly can't take your code and use it elsewhere without ripping out your GUI dependency.
With a minor modification of ho1 it worked. Thanks a lot
CType(Controls("cmb" + strWhichPart), ComboBox).Items.Add(strHold(rr))