Adding data sources to project with javascript

Adding data sources to project with javascript

Anonymous
Not applicable
900 Views
3 Replies
Message 1 of 4

Adding data sources to project with javascript

Anonymous
Not applicable

I have a *.sqlite base that was created in Infraworks sometime before and a I need to load some sources from it to the new project using javascript

While looking through some tips and js samples, I found one of the way to load data. As far as I undesrstood it uses providers method.

Here is a code where I want ro add BUILDINGS_NEW to the data source list:

 

 

var wkt = app.ActiveModel.CoordSysWkt;
file = "D:/Projects/MyModel.sqlite"
var sd = fdo.OpenDb(file)

print (sd.TableCount);
var providers = app.GetDataProviders(".sqlite");

for (i=0; i<sd.TableCount; i++) {
    if (sd.Table(i).Name == 'USER_BUILDINGS_NEW'){
        print ('        your table has been found');
        var tb_f = sd.Table(i)
        path_t = file + '/' + sd.Table(i).Name;
        for (p in providers) {
            var configs = providers[p].FileConnect(md, path_t);
            for (c in configs) {
                print (c);
                for (mm in c){
                    print (mm);
                }
                var cfg = configs[c];
                cfg.TargetClassName = 'BUILDINGS';
                cfg.SourceCoordSys = "XY-M";
                cfg.PosCoordSys = wkt;
                cfg.Name = 'USER_BUILDINGS_NEW';
                cfg.Description = 'DEAF';
                cfg.AnchorType = adsk.Enums.LocalOrigin;
                // cfg.Position = point.BBox3d.Center;
                cfg.Is3D = false;   
                var result = cfg.Import();

                if (result) {
                    print("INFO: 3d model imported for " + 'USER_BUILDINGS_NEW' + "; bbox = " + result.AffectedExtent.ToString());}
                else {
                    print("ERROR: 3d model import for " + 'USER_BUILDINGS_NEW' + " failed: " + path_t);
                    success = false;
                }
            }
        }               
    }
}

Here I've got nothing.

What can be wrong or is there a completely another way to add new data?

 

 

 

0 Likes
Accepted solutions (1)
901 Views
3 Replies
Replies (3)
Message 2 of 4

Karsten.Saenger
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous

 

do you know the Java Script API documentation of InfraWorks?

It's attached in the following knowledge base article:

http://knowledge.autodesk.com/article/Autodesk-InfraWorks-JavaScript-API-Documentation

 

Start searching for "SaveActiveCityAsJson" and "CreateCityFromJson" or "ImportDataSourcesIntoActiveModel" or "ImportDataSourcesIntoActiveModel"...

 

Regards,

Karsten



Karsten Saenger
Message 3 of 4

Anonymous
Not applicable

Yes, already found and tested it. However *.dwg models do not load properly, Infraworks says that datasource is missing but json file contains all needed data for import.

0 Likes
Message 4 of 4

Karsten.Saenger
Autodesk Support
Autodesk Support

Hi @Anonymous

 

the explanation is probably that the API is from 2014 and was not developed/updated since then.

The Civil 3D DWG import - and other functions - were added later to InfarWorks, so the API doesn't "know" about those.

 

Regards,

Karsten.



Karsten Saenger
0 Likes