Last active
June 10, 2020 11:14
-
-
Save sancarn/693858434002f6d48bd5f4bcd4a6ea62 to your computer and use it in GitHub Desktop.
Get the WSOpenNetwork object as a WSNumbatNetwork object, allowing you to get properties like name, id etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getOpenNetworkObject() | |
#Get network name | |
net = WSApplication.current_network | |
net.clear_selection | |
net.row_objects('_Nodes')[0].selected=true | |
options=Hash.new | |
options ['Export Selection'] = true | |
tmpLoc = File.dirname(WSApplication.script_file) + '\tmp.' | |
File.open(tmpLoc + 'cfg', 'w') { |file| file.write("DBX001\nNode,{{,Special,Default,Default,Default,NetworkID}},") } | |
net.odec_export_ex('CSV',tmpLoc + 'cfg',options,'Node',tmpLoc + 'csv') | |
file = File.open(tmpLoc + 'csv','r') | |
networkID = [*file][2-1] | |
file.close unless file.nil? or file.closed? | |
begin | |
File.delete(tmpLoc + 'cfg') | |
File.delete(tmpLoc + 'csv') | |
rescue Errno::ENOENT | |
end | |
networkID = networkID.to_i | |
net.clear_selection | |
#Get model network | |
iwdb = WSApplication.current_database | |
return iwdb.model_object_from_type_and_id('Model Network',networkID) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment