Batch import 3d building

Batch import 3d building

Anonymous
Not applicable
1,506 Views
10 Replies
Message 1 of 11

Batch import 3d building

Anonymous
Not applicable

Hi,

  

I am new to Infraworks and to scripting. 

 

I found this very useful process on how to batch import 3d building into Infraworks

 

https://knowledge.autodesk.com/support/infraworks-360/learn-explore/caas/simplecontent/content/aiw36...

 

 

I am trying to modify the javascript to import the models not to the base BUILDINGS class but to our custom class 3DBUILDINGS, but keep getting the following error message

 

ERROR: 3d model import for 3DBUILDINGS failed: /output/VANC0001/VANC0001.dae

 

Would very much appreciate any help on solving this problem.

 

Regards,

Olga

0 Likes
Accepted solutions (1)
1,507 Views
10 Replies
Replies (10)
Message 2 of 11

Matt__W
Advisor
Advisor
Without seeing the code and based solely on the error message, it would appear that the code isn't being passing the entire path of the file.


Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 3 of 11

Anonymous
Not applicable

Here is the script

 

instead of "BUILDINGS" base class, i would like to use "3DBUILDINGS" - the custom class

 

Thanks,

Olga

 

var listing = "Y:/output/listing.txt"
var cs = "UTM83-10";
var db = app.ActiveModelDb;

var Import3dModel = function (filePath, targetClassName, origin, scale, rotation, name) {

if (!file.FileExists(filePath)) {
print("ERROR: 3d model not found: " + filePath);
return false;
}

var providers = app.GetDataProviders(".dae");
var success = true;

for (p in providers) {

var configs = providers[p].FileConnect(app.ActiveModel, filePath);

for (c in configs) {

var cfg = configs[c];
cfg.Name = name;
cfg.TargetClassName = targetClassName;
cfg.SourceCoordSys = "UTM83-10";
cfg.PosCoordSys = cs;
cfg.AnchorType = adsk.Enums.LocalOrigin;
cfg.Position = origin;
cfg.Scaling = scale;
cfg.Rotation = rotation;
cfg.Is3D = false;
var result = cfg.Import();

if (result != null) {
success &= true;
} else {
print("ERROR: 3d model import for " + targetClassName + " failed: " + filePath);
success &= false;
}
}
}
app.Regenerate();
return success;
}

//Example on how to import multiple files
var importCollada = function () {
if (!file.FileExists(listing)) {
print("ERROR: Listing not found: " + listing);
return;
}
var dirs = file.ReadFile(listing);
var dirsa = dirs.replace(/\\/g, "/").split(/\n/);
for (var i = 0; i < dirsa.length; i++)
try {
var dir = dirsa[i].replace(/^\s+|\s+$/g, '');
var kml = dir + "/doc.kml";
var coords = file.ReadFile(kml);
var kmlImport = app.readXml(coords);
// If there is no Folder object, then go to Document object
if(kmlImport.kml.Folder == undefined || kmlImport.kml.Folder == null) {
var model = kmlImport.kml.Document.Placemark.Model;
} else {
var model = kmlImport.kml.Folder.Placemark.Model;
}

//Geo-location/Origin
var origin = new adsk.Vec3d(model.Location.longitude, model.Location.latitude, model.Location.altitude);
// Scale, if the scale is not set, then assume it is 1
if(model.Scale == undefined || model.Scale == null) {
var scale = new adsk.Vec3d(1,1,1);
} else {
var scale = new adsk.Vec3d(model.Scale.x, model.Scale.y, model.Scale.z);
}
// Rotation, if the rotation is not set, then there is no rotation applied.
if( model.Orientation == undefined || model.Orientation == null) {
var rotation = new adsk.Vec3d(0, 0, 0);
} else {
var rotation = new adsk.Vec3d(model.Orientation.tilt, model.Orientation.roll, model.Orientation.heading);
}

var name = dir.split("/");

Import3dModel(dir + "/" + model.Link.href, "BUILDINGS", origin, scale, rotation, name[name.length-1]);
} catch (err) {
print(err+ ": " + dir);
continue;
}
}
importCollada();

0 Likes
Message 4 of 11

Matt__W
Advisor
Advisor

Can you post the first few lines of this file? (Y:/output/listing.txt)

I'm assuming it's a comma delimited file? If so, the first line should be the "column" headers and the subsequent lines will represent each building.

 

Thanks.



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 5 of 11

Anonymous
Not applicable

Thank you Matt for looking into this

 

Here are the lines

 

Y:\GIS\Data\NEFC\VANC0290
Y:\GIS\Data\NEFC\VANC0291
Y:\GIS\Data\NEFC\VANC0292

 

Each directory has a DAE file (containing geometry), KML file (containing the coordinate of the insertion point) and texture files.

 

Thanks,

Olga

0 Likes
Message 6 of 11

Anonymous
Not applicable

Below is the instruction from the original site where i got the scripts

 

The workflow uses a Javascript and bat script. You need both scripts for correctly importing a number of 3D models. 3D Warehouse models can be downloaded in several formats including KMZ. The KMZ format is actually a ZIP file containing a KML file, Collada DAE model and textures in a separate folder. You can simply use a RMB (Right-Mouse-Button) on the KMZ file and choose extract. In some occasions it helps to have a SketchUp (Pro) license because after the RMB extraction no KML file is generated. When you use SketchUp to export the KMZ file then after RMB extract there will always be a KML file generated. You need the KML file because it holds the geographic position and rotation of the 3D model.

You can download the JS and bat script here. Then follow the next steps:

  1. Extract your KMZ models (if you downloaded them from 3D Warehouse) to folders holding a KML model and subfolder with the Collada DAE and textures. This is very simple by using your RMB on the KMZ file and choose Extract here. It's actually just a zip file.
  2. Then put your extracted models and folders in a separate folder preferably high in the root of the HD.
  3. Then copy the batscript in there and run it. This will create the listing.txt file holding all the KML model folders
  4. Then copy the JS also in and adjust that script using a script editor like Notepad++. The only thing you need to adjust is the first line mapping folder to your drive and folder: var listing ="D:/Temp/listing.txt"
  5. Then copy the whole script by CTRL-A and CTRL-C and paste it into the AIW360 ScriptEditor or load the script from there
  6. Run the script

Now AIW360 will start to import the 3D models one by one and place the Data Sources in the Buildings Model Category.

0 Likes
Message 7 of 11

Matt__W
Advisor
Advisor

Just out of curiosity, what does your MODEL EXPLORER look like? When I try to create a custom class I get this. 

 

USER_3DBUILDINGS.PNG



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 8 of 11

Anonymous
Not applicable

Hi Matt -

 

we modified the im.schema.json with the following lines

 

"name": "3DBUILDINGS",
"base": "BUILDINGS",
"Attributes": [


"name": "3DBUILDINGS",
"displayName": "3D Buildings",
"category": "Buildings"

 

and the result in the Infraworks 

 

 

 Capture.PNG

 

Thanks,

Olga

 

0 Likes
Message 9 of 11

Matt__W
Advisor
Advisor
Accepted solution

Okay...


Instead of using 3DBUILDINGS in the Javascript code, try passing "USER_3DBUILDINGS".



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 10 of 11

Anonymous
Not applicable

Hi Matt -

 

it worked !!!!

 

Can't thank you enough for helping with me this

 

Thanks,

Olga

Message 11 of 11

Matt__W
Advisor
Advisor

I'm glad we got it working for you!



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.