hdse Posted June 16, 2014 Posted June 16, 2014 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.SelectedHierarchyMemberSet Cluster = Project.Insertions.New.ByClassID(ehmcTurbineSiteGroup).ExecuteSet 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.0001The problem is coming from the file insertion, but I could`nt find the mistake.I hope you will be able to help meThank you !
Ray Posted June 18, 2014 Posted June 18, 2014 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 member2) Insert new met station as child of the generalised wind climate, set it's coordinates if desired3) Insert OWC from file as child of met stationSimilarly, 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 climateSet Member = Project.Insertions.New.ByClassID(ehmcWindAtlas).ExecuteSet Gwc = ReportingAssistant.TypeCaster.CastMemberToWindAtlas(Member)Gwc.AsIHierarchyMember.Description = "My GWC"' Insert a met station and set its coordinatesSet Member = Gwc.AsIHierarchyMember.Insertions.New.ByClassID(ehmcMetStation).ExecuteSet MetStation = ReportingAssistant.TypeCaster.CastMemberToMetStation(Member)Call MetStation.AsIRveaSite.Move(LocationX, LocationY)' Insert the OWC from fileSet Member = MetStation.AsIHierarchyMember.Insertions.FromFile.ByClassID(ehmcObservedWindClimate).Execute(owcpath, Nothing)Set hmOwc = ReportingAssistant.TypeCaster.CastMemberToObservedWindClimate(Member)' Insert a IBZ Terrain AnalysisSet Member = Project.Insertions.New.ByClassID(ehmcTerrainAnalysisIbz).ExecuteSet TerrainIbz = ReportingAssistant.TypeCaster.CastMemberToTerrainAnalysisIbz(Member)' Insert the vector map from fileSet Member = TerrainIbz.AsIHierarchyMember.Insertions.FromFile.ByClassID(ehmcVectorMap).Execute(mappath, Nothing)Set VectorMap = ReportingAssistant.TypeCaster.CastMemberToVectorMap(Member)Hope that helps.Cheers,Ray
hdse Posted June 18, 2014 Posted June 18, 2014 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 fileturbinespath="C:\Users\hdse\Desktop\d300D900\test.txt"Set Project = ReportingAssistant.SelectedHierarchyMember' Insert a Wind FarmSet Member = Project.Insertions.New.ByClassID(ehmcTurbineSiteGroup).ExecuteSet WindFarm = ReportingAssistant.TypeCaster.CastMemberToWindFarm(Member)' Insert the Turbine SitesSet 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 FarmSet Member = Project.Insertions.New.ByClassID(ehmcTurbineSiteGroup).ExecuteSet WindFarm = ReportingAssistant.TypeCaster.CastMemberToWindFarm(Member)' Insert a generatorSet 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 hierarchyThank you for your help !
Ray Posted June 18, 2014 Posted June 18, 2014 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 coordinates2) insert a turbine site into the windfarm3) set the turbine site's locationOnce 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)
hdse Posted June 23, 2014 Posted June 23, 2014 Thank you very muchI 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.SelectedHierarchyMemberSet objFSO = CreateObject("Scripting.FileSystemObject")Set strData = objFSO.OpenTextFile("C:\Users\hdse\Desktop\test.txt")Dim oRE : Set oRE = New RegExpoRE.Global = TrueoRE.Pattern = "\w+"Dim arrFileLines()i=0Do 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 + 1Loop
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now