Results 1 to 10 of 10

Thread: Exporting data to an .xml file

  1. #1
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Exporting data to an .xml file

    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?

  2. #2
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    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?

  3. #3
    Active Member
    Join Date
    2005-09
    Posts
    69
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    I think you need to look at the Print method - try looking at help for each method.

  4. #4
    I could stop if I wanted to Danny Polkinhorn's Avatar
    Join Date
    2003-12
    Location
    San Francisco, CA
    Posts
    448
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    .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,

  5. #5
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    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?

  6. #6
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    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

  7. #7
    I could stop if I wanted to Danny Polkinhorn's Avatar
    Join Date
    2003-12
    Location
    San Francisco, CA
    Posts
    448
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    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,

  8. #8
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    Of course! Thank you!

  9. #9
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    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.

  10. #10
    Member
    Join Date
    2008-10
    Posts
    31
    Login to Give a bone
    0

    Default Re: Exporting data to an .xml file

    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

Similar Threads

  1. Replies: 1
    Last Post: 2015-04-29, 01:18 PM
  2. 2014: Recap - Data Loss when Exporting
    By mfullenkamp422885 in forum ReCap Studio - General
    Replies: 0
    Last Post: 2013-09-26, 12:41 PM
  3. Exporting Entity Data With Timeliner
    By dfrancis in forum NavisWorks - General
    Replies: 6
    Last Post: 2010-05-05, 05:41 AM
  4. Exporting Systems Data to gbXML
    By Tyveka in forum Revit MEP - General
    Replies: 4
    Last Post: 2007-11-09, 10:34 PM
  5. Land XML Importing/Exporting Data
    By hunterhyde in forum AutoCAD Civil 3D - General
    Replies: 0
    Last Post: 2006-07-10, 03:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •