Subscribe to this thread
Home - General / All posts - manifold 8 jscript save text in file ( newbie question )
lionel

519 post(s)
#19-Nov-18 23:06

in manifold 8 whe nusing JScript howto save file in fielsystem ?

code

function Main() {

    var path = Application.DefaultFilePath;

    // object expected line..

    var fso = CreateObject("Scripting.FileSystemObject");

    var textFileStream = fso.OpenTextFile(path+"\file.txt");

     textFileStream.WriteLine( "Hello, World!");

    textFileStream.WriteLine( "This is fun!!");

    textFileStream.Close();

}

thank's


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

adamw


8,259 post(s)
#20-Nov-18 08:49

Try this:

//JScript

function Main() {

  var path = "c:\\test";

  var fso = new ActiveXObject("Scripting.FileSystemObject");

  var textFileStream = fso.CreateTextFile(path+"\\file.txt"true);

  textFileStream.WriteLine("Hello, World!");

  textFileStream.WriteLine("This is fun!!");

  textFileStream.Close();

}

I bolded the changes (new ActiveXObject instead of CreateObject, CreateTextFile instead of OpenTextFile, double slash in path instead of single slash because of escaping).

We might make plain CreateObject work as well, will look into it.

lionel

519 post(s)
#20-Nov-18 15:17

thank's a lot

i really begin to really mfd8 coding in Jscript

1) Jscript on client side and server side don' have the same context : server has activex context , client has browser API DOM and http API .

where I can find documentation ( context and language) for Javascript for client ( all browser) and server ( microsoft) but only on microsoft web site !!!I

2) after retrieve using record.data(" Geom(I)") inside mfd8 howto convert this content to be able to extract branchset ..... Does data( "geomNamecolumn) cast ther content to a geom type ? ( don't test debug but ll inspect the variable .....i think i ll find by myself but find nothing in the doc need to read it again )

3) why not link from manifold API doc to official Microsoft doc for type define in Microsoft environnement ?

regard


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

adamw


8,259 post(s)
#20-Nov-18 17:05

1 - API exposed to Javascript by browser is documented on W3C (opener, specs).

2 - Yes, Record.Data(...) for a geom field returns a Geom object.

3 - Microsoft docs frequently change locations, so if we are talking about linking to some generic entry page on MSDN, chances are, the link will just get outdated in a year or even in a couple of months and then we'll simply have a broken link which helps no one. We can of course try to keep a list of all links and regularly visit and update them, but for something as generic as "some Microsoft API" or "some non-Microsoft API as it is implemented in Microsoft products", we think it is just more productive to clearly spell what it is and let the user use a search engine.

lionel

519 post(s)
#20-Nov-18 23:46

it is strange when i use debug i read byteofarray not Geom type for varaiable geom !!!

regard's

Attachments:
geom-of-table-arrayofbyte.png


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

adamw


8,259 post(s)
#21-Nov-18 08:19

Does further code (var branches = geom.BranchSet and then looping by branches) work? If so, then you got a Geom and that it is not shown as a Geom is on whoever is showing it (the debugger), it might not understand that this is a Geom for the purposes of the Watch window. If the code does not work, then it would be helpful to see the MAP file with the data and the script.

lionel

519 post(s)
#21-Nov-18 23:20

Hi

the script come from IMS demo sv town i already convert to save to OS filesystem .

I do a capture screen to show that the script ( svg_table) has access to park Table ant then can extract / retrieve cell content for first row so retrieve ID and then Name and don't really block on Geom (I) but retrieve byteofarray instead GEom object Type. So Since BtyeofArray don't have any method in the debug that show that variable shure i cna't apply no method on it !! ( my opinion) . I am shure a casting should be use to convert bytearray to Geom since we have raw data content ...

try other variable , try the white space could not a problem beetwwem "m" and "(" inside "GEom ("

try to find in JScript a function to convert an array to object that could be convert ot GEom ...

I was Think JSCript has been update and don't behave the same since new windows OS or §JScript version with editor syntax i could avoid those kind of error but here i really don't find where the error is located !! ( not an error since that work but not the way i want ) .....hope it is more basic simple

Attachments:
manifold_branchset_bad.png
Town-debug.map


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

lionel

519 post(s)
#21-Nov-18 23:37

thank a lot for your help adamw , even i have the code that work i ll try to understand why those change make sense and in which context !! this expplain why i post about where to find docymentation about language and some microsoft API ( fso file system) . the debugger is really great


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

vincent

1,733 post(s)
#22-Nov-18 13:51

so, at the end, are you able to get a geom from a geom field of a record and use it ? How ? I'm not able to achieve that in jscript.

adamw


8,259 post(s)
#22-Nov-18 16:10

This is my fault, I made a mistake.

Record.Data(...) for a geom field does not return a Geom object in M8, this only started being the case in builds on the way to M9. In the released version of M8, Record.Data(...) for a geom field returns a byte array.

Here is an example script, it's in VBScript, but the idea is hopefully clear:

'VBScript

Sub Main

  Set drw = Document.ComponentSet("Drawing")

  Set obj = drw.ObjectSet(0) ' assuming drawing is not empty

  Set rec = obj.Record ' record from table

' Application.MessageBox VarType(rec.Data("Geom (I)")) ' 8209 = blob

' Application.MessageBox VarType(obj.Geom) ' 9 = object

' Application.MessageBox VarType(obj) ' 9 = object, same as obj.Geom

' Application.MessageBox obj.Geom.BranchSet.Count ' 1

  blob = rec.Data("Geom (I)")

' Application.MessageBox blob.BranchSet.Count ' fails, not an object

  Application.MessageBox UBound(blob) ' 25 = 25 bytes

End Sub

That said, you can take the byte array and convert it to a Geom object using Application.NewGeomFromBinary:

'VBScript

Sub Main

  Set drw = Document.ComponentSet("Drawing")

  Set obj = drw.ObjectSet(0) ' assuming drawing is not empty

  Set rec = obj.Record ' record from table

  Set geom = Application.NewGeomFromBinary(rec.Data("Geom (I)"))

  Application.MessageBox VarType(geom) ' 9 = object

  Application.MessageBox geom.BranchSet.Count ' 1

End Sub

The latter works for all geom fields, not just for the intrinsic "Geom (I)".

Apologies for the confusion.

You can also get to the geom corresponding to a record (in a table that corresponds to a drawing) using Record.Object.Geom.

lionel

519 post(s)
#22-Nov-18 21:45

really happy to see there was a way to convert the value retrieve by geomt and aware now that manifold has implemented some functionnalities/tools/ helpers ( helpers word are use a lot in javascript client context ) to work on data easely !!. i ll read more application object API doc . you save my day !!

thank's a lot !!!


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

lionel

519 post(s)
#23-Nov-18 23:13

Using JScript in manifold 8 I test query parameters with geom but don't seem to Work !!

'JSCript

var updateps=update.ParameterSet;

 var  geomval = updateps(updateps.ItemByName("geomval"));//error here

.....

geomval.Value=Application.NewGeomFromBinary(sql.Table.RecordSet.Item(nBranch).Data("Geom (I)")) 

.

.

'SQL

PARAMETERS geomval GEOM;

''UPDATE [identify] SET [group] = groupval WHERE [ID]= groupval ;

UPDATE [identify] SET [group] = groupval WHERE [Geom (I)]= geomval ;

when use INT parameter all is ok ( also the name ofthe directory in the map file below ) , when i try to add a new parameter of type GEOM inside script and query parameter i have an error !! I copy the ok directory to new one to test with geom type .

any idea ?

Attachments:
identify_v8.map


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

lionel

519 post(s)
#23-Nov-18 23:35

Does this code is the same ? seem yes

'JScript

var groupval = updateps.item(updateps.ItemByName("groupval"));

var groupval = updateps(updateps.ItemByName("groupval"));

.

From manifold 8 Doc for Query ParameterSet

Number ItemByName(String name)

QueryParameter Item(Number index)

QueryParameter Item(String name)

Returns parameter with given index or name. Read only.

thank's for any confirmation


join image "Because my dad promised me" interstellar from Manifold: Time by Stephen Baxter. power Math destruction

adamw


8,259 post(s)
#11-Dec-18 14:17

A belated reply.

x.Item(...) and x(...) on Manifold 8 objects denote the same thing for many COM languages because Manifold 8 objects mark Item as a so-called default value property (which means that you can omit its name).

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.