Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
7

EnergyPlus IDF editor copy paste

asked 2016-05-30 17:29:54 -0500

updated 2016-05-31 11:24:26 -0500

Is there a 'trick' or means to copy/paste from the IDF editor? I'm thinking of the eQuest 'trick' where one must use ctrl+shift and copy/paste works again; and wondered if anyone had anything that worked same/similar in IDF world. This is highly useful fro moving to/from MS excel. Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
10

answered 2016-05-30 18:27:00 -0500

updated 2016-05-31 11:46:00 -0500

IDF to Excel

To move from IDF to excel go under Edit > Copy for spreadsheet.

copy for spreadsheet IDF

Excel to IDF

Usage

For the other way around, I wrote a macro that will read in an excel table and export that to an IDF compatible object so that you can paste it in the IDF editor or in your .idf text file itself.

I've personally added this macro to an Excel Add-In and added a button on a separate tab for easy access:

Excel to IDF Button

To use the macro, place your cursor in any of the cells of the table and launch it. It will try to find the EPlus class name in the cell that's 2 rows above the top-left corner of the table to prepopulate a dialog box asking you for the class name: either it's good and click OK, or it isn't or it didn't find it, type the name of the class. It'll then generate proper IDF objects that you can paste in IDF editor or paste directly in the .idf file. It'll ask you whether you want to save it as a file (and subsequently ask for a file name) or copy it to clipboard.

Example

Here's an example:

Example Excel to IDF

And Here's the output it produced for the example table:

Eplus:ObjectClass,
    Object 1,
    (1,1),
    (1,2),
    (1,3);

Eplus:ObjectClass,
    Object 2,
    (2,1),
    (2,2),
    (2,3);

Eplus:ObjectClass,
    Object 3,
    (3,1),
    (3,2),
    (3,3);

Add-In

I've set up a quick Excel Add-In with some instructions a couple more things in my github: Useful Excel Macros for Energy Modeling. It includes:

  • Some shortcuts
  • A macro to export an Excel table to an IDF format for import into IDF Editor or to paste in the idf file directly
  • A macro to export an excel table to a JSON array of hash: useful when working with ruby and the OpenStudio bindings especially
  • And obviously a readme file

Want just the macro?

Sub Export_To_IDF()
' Author: Julien Marrec
' Date: 2014-05-13
' Version: 1.0
' References: Microsoft Forms Object 2.0, needed for using the Clipboard

' Export current region to an IDF readable format. Paste in text format

Dim wS As Worksheet
Set wS = ActiveSheet

Dim rS%, rE%, cS%, cE%
Dim i%, j%
Dim Class As String
Dim s As String


' Define active region (currentregion = same as CTRL +A) by start and end lines and rows
With ActiveCell.CurrentRegion

    rS = .Rows(1).row
    rE = rS + .Rows.Count - 1
    cS = .Columns(1).Column + 1
    cE = cS + .Columns.Count - 2

End With


' Try setting the IDF class from the cell two lines above the start of the table
Class = wS.Cells(rS - 2, cS - 1).Value


' Ask for the IDF Class of the object
Class = InputBox(Prompt:="Input Class of object (eg: Zone, Building, BuildingSurface:Detailed", Title:="Object Class", Default:=Class)

' If nothing was entered or "Cancel" pressed, exit the sub
If Class = "" Then Exit Sub



' Loop through each column
For j = cS To ...
(more)
edit flag offensive delete link more

Comments

Julien - Thanks for this. I'm glad there is an easy way to get data out. Now I'm interested to see how getting data back in works.

dradair gravatar imagedradair ( 2016-05-31 07:06:41 -0500 )edit
1

@Julien Marrec, Thank you for sharing!

Chris Jones gravatar imageChris Jones ( 2016-05-31 08:55:05 -0500 )edit

I've just added to my answer that I've set up a quick Excel Add-In with some instructions a couple more things in my github: Useful Excel Macros for Energy Modeling

Julien Marrec gravatar imageJulien Marrec ( 2016-05-31 11:59:54 -0500 )edit

Firstly, thank you for this macro, it's a godsend. Secondly, when I try to run it, i get an error "user defined type not defined" in regards to "Dim MyDataObj As New DataObject". Any way I can solve this? I'm fairly inexperienced in VBA and dying to use this macro. Thanks in advance.

LAlmeida gravatar imageLAlmeida ( 2016-12-05 15:57:33 -0500 )edit

As stated in the comments atop the macro: ' References: Microsoft Forms Object 2.0, needed for using the Clipboard. Enable this. Or just go to my Github and download the addin (xlam) and more and start using it right away (this is by far what I recommend doing especially if you're not experienced in VBA. And you'll get the possibility of using the add-in on any workbook, even those without integrated macros (xlsx, not xlsm). The readme should be detailed enough

Julien Marrec gravatar imageJulien Marrec ( 2016-12-21 12:21:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

 



Question Tools

1 follower

Stats

Asked: 2016-05-30 17:29:54 -0500

Seen: 1,106 times

Last updated: May 31 '16