Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Add a MeasureType in C# Bindings #2795

Closed
chriswmackey opened this issue Sep 25, 2017 · 3 comments · Fixed by #3959
Closed

Can't Add a MeasureType in C# Bindings #2795

chriswmackey opened this issue Sep 25, 2017 · 3 comments · Fixed by #3959

Comments

@chriswmackey
Copy link

Hello OpenStudio Team,

Thanks, as always for this wonderful software. I have been playing with the WorkflowJSON class for the past day and it's been generally smooth sailing except for one small issue. I am just trying to use the setMeasureStep() for the Workflow and all of my attempts to use the MeasureType class in C# bindings have given in the following error that seems to be the result of a bug:

Runtime error (ArgumentTypeException): expected SWIGTYPE_p_openstudio__MeasureType, got MeasureType

Here is some code that re-creates the issue using the compact_osw example that installs with OpenStudio:

import OpenStudio
osmPath = OpenStudio.Path(C:\openstudio-2.2.0\Examples\compact_osw\files)
epwPath = OpenStudio.Path('C:\openstudio-2.2.0\Examples\compact_osw\files\srrl_2013_amy.epw')
oswPath = OpenStudio.Path('C:\openstudio-2.2.0\Examples\compact_osw\compact2.osw')
measurePath = OpenStudio.Path(''C:\openstudio-2.2.0\Examples\compact_osw\measures\IncreaseRoofRValue')

wf = OpenStudio.WorkflowJSON()
measure = OpenStudio.MeasureStep(measurePath )
measure.setArgument('r_value', '45')
measureType = OpenStudio.MeasureType('ModelMeasure')
wf.setMeasureSteps(measureType, measure)

Let me know if there's anything else that you need to recreate the issue and I apologize in advance if I'm just not understanding the MeasureType class correctly. I have tried a lot of variations on this that have resulted in the same error, which has lead me to believe that it's a bug and belongs here instead of on unmethours. Thanks again.

@macumber
Copy link
Contributor

Hmm that might be a weird SWIG order thing. I've never actually used that method, I have been using:

bool setWorkflowSteps(const std::vector<WorkflowStep>& steps);

to set all the steps at once. In either case, you will need to construct either a OpenStudio.MeasureStepVector or OpenStudio.WorkflowStepVector and add the measure to that before calling setWorkflowSteps. You might try a few variations on that? I tried this in Ruby and got this error when calling the set steps with type method:

wf = OpenStudio::WorkflowJSON.new
type = OpenStudio::MeasureType.new("ModelMeasure")
steps = OpenStudio::MeasureStepVector.new
wf.setWorkflowSteps(type, steps)

ArgumentError: wrong # of arguments(2 for 1)
        from (irb):8:in `setWorkflowSteps'
        from (irb):8
        from C:/ruby-2.2.4-x64-mingw32/bin/irb:11:in `<main>'

the following worked:

wf = OpenStudio::WorkflowJSON.new
type = OpenStudio::MeasureType.new("ModelMeasure")
steps = OpenStudio::WorkflowStepVector.new
wf.setWorkflowSteps(steps)

So I think you are right that there is a bug, I'd suggest going with the second method as a work around

@chriswmackey
Copy link
Author

@macumber ,
Thank you, as always, for the wonderful support! Your proposed solution works on my end. Here's the final code that I used to solve the issue (I only include the second half here as most of the first part is extraneous):

wf = OpenStudio.WorkflowJSON()
measure = OpenStudio.MeasureStep(measurePath )
measure.setArgument('r_value', '45')
stepVector = OpenStudio.WorkflowStepVector([measure])
wf.setWorkflowSteps(measureType, measure)

I'll leave it up to you, @macumber if you would rather close the issue (since I have what I need now) or just leave it open until you can investigate the SWIG order for the MeasureType.
Thanks again!
-Chris

@macumber
Copy link
Contributor

Cool, good to hear you are unblocked. Let's leave this open for now since it still is a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants