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();