Hello everybody,
I'm very amateur in programming, but for my thesis I have to write a small piece of code in VSTA for Revit. I'm using VB. I want to export some strings to an .xml file.
What's the code for this please?
|
|
|
Hello everybody,
I'm very amateur in programming, but for my thesis I have to write a small piece of code in VSTA for Revit. I'm using VB. I want to export some strings to an .xml file.
What's the code for this please?
I managed to export a string to an .xml file, but it places my string between quotation marks
and adds a comma
example:
Microsoft.VisualBasic.FileOpen(1, "D:\school\4BK\eindwerk\VSTA\bestanden\export.xml", OpenMode.Output)
Write(1, "string1")
Write(1, "string2")
Microsoft.VisualBasic.FileClose(1)
this creates an .xml with the following content:
"string1","string2"
Is there a way to get rid of these quotation marks and commas, so I get this:
string1string2?
I think you need to look at the Print method - try looking at help for each method.
.NET is quite robust at creating and manipulating XML files. You should search the web for some good examples. Try this one which uses the brute force approach.
I wouldn't recommend LINQ at this point because it requires a later version of the .NET framework than Revit 2009 supports. I've had a lot of success with XML serialization, but it's not for amateurs like me. It took me several days to get the code working properly with collections of objects.
Hope that helps,
The Print method works better, I can now export strings to an .xml file without unnecessary quotation marks or commas.
I am now trying to find a way to export the category of a family (for example Generic Models, Furniture, Lighting Fixture, etc....)
Does anybody know the code for this or an example?
I have another question, when I iterate through all the selected families in Revit, the Print method is used every time, but it seems it overwrites the previous text in the .xml file every time.
So when I select 3 families and run the macro, it writes the family and type name of family 1, then overwrites it with the family and type name of family 2 and finally overwrite it again with the family and type name of family 3.
How can I prevent this? In other words, is there a method like Print that appends text to the existing text, instead of overwriting it?
This is what I have so far, in ThisApplication.vb:
Code:Public Sub test() Dim elem As Revit.Element Dim param As Parameter For Each elem In ActiveDocument.Selection.Elements Dim objType As Autodesk.Revit.Symbols.FamilySymbol = elem.ObjectType Dim objFamily As Autodesk.Revit.Elements.Family = objType.Family Microsoft.VisualBasic.FileOpen(1, "D:\school\4BK\eindwerk\VSTA\bestanden\export.xml", OpenMode.Output) Print(1, "<family>" + objFamily.Name + "</family>" + vbCr) Print(1, "<type>" + elem.Name + "</type>" + vbCr) Microsoft.VisualBasic.FileClose(1) Next End Sub
Nicolas,
You just need to move your FileOpen and FileClose lines outside of the For...Next loop. That will keep it open for each family, then close at the end.
HTH,
Is there a way to access the name or id of the Zone, Space and Room an element is in?
I have defined these so far:
Dim elem As Revit.Element
Dim objType As Autodesk.Revit.Symbols.FamilySymbol = elem.ObjectType
Dim objFamily As Autodesk.Revit.Elements.Family = objType.Family
I'm hoping there is something like a .getZone in one of the above, but I can't find anything
Last edited by nicholas.hendrickx; 2008-12-02 at 11:13 AM.
I managed to extract the room now via elem.Room.Name
I have a new question though:
Is it possible to access parameters of nested families, if so, how do I do it?
I cycle through all the selected families like this:
For Each elem In ActiveDocument.Selection.Elements