Jump to content

Inserting from a file


Recommended Posts

Hello,
I am writing a script in order to automatize the manipulation of the workspace. In this context I want, to start with, to import a vector map and an observed wind climate.

My code is the following:

mappath="C:\Users\hdse\Documents\sea.map"
owcpath="C:\Users\hdse\Documents\Portugal.owc"

Set Project = ReportingAssistant.SelectedHierarchyMember
Set Cluster = Project.Insertions.New.ByClassID(ehmcTurbineSiteGroup).Execute
Set hmOwc = Project.Insertions.FromFile.ByClassID(ehmcObservedWindClimate).Execute(owcpath, Nothing)
Set MapSea = Project.Insertions.FromFile.ByClassID(ehmcVectorMap).Execute(mappath,Nothing)


The turbine site group is created successfully, but I have this error:

Script control reported the error: 
Object required: 'Project.Insertions.FromFile.ByClassID(...)'

The last execution line attempt was for an unknown line number.
Script: 'essai1', version: 11.01.0001


The problem is coming from the file insertion, but I could`nt find the mistake.
I hope you will be able to help me
Thank you !
Link to comment
Hi,


I assume you are using Wasp 11. This error occurs because you are attempting to add an OWC directly as a child of the project, which is not allowed. If you try to do this manually in Wasp you will see that Wasp inserts a generalised wind climate member with a met station child member and the OWC will be a child of the met station.


When automating Wasp you need to insert each of these members individually. So the basic idea would be:

1) Insert new generalised wind climate as child of the project member
2) Insert new met station as child of the generalised wind climate, set it's coordinates if desired
3) Insert OWC from file as child of met station


Similarly, in Wasp 11 the vector map cannot be added as a child of the project directly. You first need to add a Terrain Analysis IBZ member and then add the vector map to that.


Here is some code which demonstrates this. Note the use of the TypeCaster. When inserting items into the Wasp hierarchy they are of the general type IHierarchyMember. To perform an action that is specific to an particular member type you first need to type cast the general member to the appropriate type. I have demonstrated the use of the TypeCaster below for each member created.



mappath="X:\Work Folder\Script Forum Question\Waspdale.map"
owcpath="X:\Work Folder\Script Forum Question\Waspdale.owc"

Set Project = ReportingAssistant.SelectedHierarchyMember

' Insert a generalized wind climate
Set Member = Project.Insertions.New.ByClassID(ehmcWindAtlas).Execute
Set Gwc = ReportingAssistant.TypeCaster.CastMemberToWindAtlas(Member)
Gwc.AsIHierarchyMember.Description = "My GWC"

' Insert a met station and set its coordinates
Set Member = Gwc.AsIHierarchyMember.Insertions.New.ByClassID(ehmcMetStation).Execute
Set MetStation = ReportingAssistant.TypeCaster.CastMemberToMetStation(Member)
Call MetStation.AsIRveaSite.Move(LocationX, LocationY)

' Insert the OWC from file
Set Member = MetStation.AsIHierarchyMember.Insertions.FromFile.ByClassID(ehmcObservedWindClimate).Execute(owcpath, Nothing)
Set hmOwc = ReportingAssistant.TypeCaster.CastMemberToObservedWindClimate(Member)


' Insert a IBZ Terrain Analysis
Set Member = Project.Insertions.New.ByClassID(ehmcTerrainAnalysisIbz).Execute
Set TerrainIbz = ReportingAssistant.TypeCaster.CastMemberToTerrainAnalysisIbz(Member)

' Insert the vector map from file
Set Member = TerrainIbz.AsIHierarchyMember.Insertions.FromFile.ByClassID(ehmcVectorMap).Execute(mappath, Nothing)
Set VectorMap = ReportingAssistant.TypeCaster.CastMemberToVectorMap(Member)



Hope that helps.


Cheers,
Ray
Link to comment
Thank you very much, it helped a lot.
However, I don't know why the following is not working.
I want to create a Wind Farm and add wind turbine locations from a .txt file

turbinespath="C:\Users\hdse\Desktop\d300D900\test.txt"

Set Project = ReportingAssistant.SelectedHierarchyMember

' Insert a Wind Farm
Set Member = Project.Insertions.New.ByClassID(ehmcTurbineSiteGroup).Execute
Set WindFarm = ReportingAssistant.TypeCaster.CastMemberToWindFarm(Member)

' Insert the Turbine Sites
Set Member = WindFarm.AsIHierarchyMember.Insertions.FromFile.ByClassID(ehmcTurbineSite).Execute(turbinespath, Nothing)
Set TurbineSites = ReportingAssistant.TypeCaster.CastMemberToTurbineSite(Member)


The Wind Farm is created but the importing of the site locations is not working.

The error is:
Script control reported the error: 
Object required: 'ByClassID(...)'


I also tried to insert a generator in the wind farm like this:

generatorpath="C:\ProgramData\WAsP\WAsP11\Wind turbine generators\Vestas V112-3.0 MW"

' Insert a Wind Farm
Set Member = Project.Insertions.New.ByClassID(ehmcTurbineSiteGroup).Execute
Set WindFarm = ReportingAssistant.TypeCaster.CastMemberToWindFarm(Member)

' Insert a generator
Set Member = WindFarm.AsIhierarchyMember.Insertions.FromFile.ByClassID(ehmcWindTurbineGenerator).Execute(generatorpath, Nothing)
Set Generator = ReportingAssistant.TypeCaster.CastMemberToWindTurbineGenerator(Member)


and it says:

Script control reported the error: 
could not insert a Wind turbine generator to the hierarchy


Thank you for your help !
Link to comment
The problem with the generator insertion is that you have not specified the file extension (*.wtg or *.pow) in the file name.


Regarding the turbine sites, I don't think inserting turbine sites from file is available in a scripting context, so your code above wont work.


Instead what you can do is write some code to open the file (CSV or you could use Excel), loop through each line doing the following:


1) parse the site coordinates
2) insert a turbine site into the windfarm
3) set the turbine site's location


Once you have the location of a site parsed into coordinates, say LocationX and LocationY, here is some code that will perform the insertion and set the site location:



Set Member = WindFarm.AsIHierarchyMember.Insertions.New.ByClassID(ehmcTurbineSite).Execute
Set TurbineSite = ReportingAssistant.TypeCaster.CastMemberToTurbineSite(Member)
TurbineSite.Description = "My site name"
Call TurbineSite.AsIWaspSite.Move(LocationX, LocationY)
Link to comment
Thank you very much
I publish my code for importing turbines locations from a file, if it can be useful to someone.

turbinespath="C:\Users\hdse\Desktop\test.txt"

Set Project = ReportingAssistant.SelectedHierarchyMember


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set strData = objFSO.OpenTextFile("C:\Users\hdse\Desktop\test.txt")

Dim oRE : Set oRE = New RegExp
oRE.Global = True
oRE.Pattern = "\w+"

Dim arrFileLines()
i=0
Do Until strData.AtEndOfStream
ReDim Preserve arrFileLines(i)
arrFileLines(i) = strData.ReadLine
Dim oMTS : Set oMTS = oRE.Execute(arrFileLines(i))

Set Member = WindFarm.AsIHierarchyMember.Insertions.New.ByClassID(ehmcTurbineSite).Execute
Set TurbineSite = ReportingAssistant.TypeCaster.CastMemberToTurbineSite(Member)
TurbineSite.Description = oMTS(0)
TurbineSite.HubHeightAgl = Generator.DefaultHeight
Call TurbineSite.AsIWaspSite.Move(oMTS(1), oMTS(2))

i = i + 1
Loop
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...