Infraworks - Using Bookmarks with a Script

Infraworks - Using Bookmarks with a Script

Anonymous
Not applicable
2,160 Views
18 Replies
Message 1 of 19

Infraworks - Using Bookmarks with a Script

Anonymous
Not applicable

Hello people !

 

My question is quite simple : how to move the point of view to a specific position with a script.

My first idea was to use the JS MoveToBookmark with a the bookmark recorded on the place i whant to spot.

 

var doc = app.ActiveDocument();    

doc.MoveToBookmark("Start.json");

 

But nothing append, the point of view does'nt move...

 

Something missing or the command MoveToBookmark isn't shape for that ?

 

Thanks for your help !

 

0 Likes
2,161 Views
18 Replies
Replies (18)
Message 2 of 19

Glenn.Coppard
Advocate
Advocate

I haven't tried jumping between bookmarks (and I'm sure you will be able to - like in a 'storyboard' essentially) but I have written a Script & UI to set Camera and Targets from entered Co-ords.

 

I presume you've got a copy of the "Autodesk InfraWorks - JavaScript API Documentation" c2014, this covers off the calls you need to look at.

 

Comes down to using the transforms for camera/target which you the set with "model.SetViewPoint"

 

 

If you can Vote these Ideas Up, we might get some traction on this 'stuff' that is a bit more user friendly.

 

My script looks much like what I've suggested here

 

ability-to-set-viewpoint-based-on-specific-coordinate

Message 3 of 19

Anonymous
Not applicable

Thanks Glen for your answer !

 

I have try to move the point of view with the transformation of the Cam Position with setcameraposition, and it give me a good result except for the point of view.

It's why i had the idea to use the bookmarks to transform in one time the CameraPosition, the CameraTarget and the CameraUP.

 

I'll read the docs and the tutos you send me !

 

Thanks again ! 

0 Likes
Message 4 of 19

Anonymous
Not applicable

Finaly, here the script i use to move the camera to the point of view i have choose on the map. I have pick the X, Y, Z from the bookmark of the position and point of view i have recorded :

 

// --------------------------
// --- Deplacement Camera ---
// --------------------------
// variables Camera
var model = app.ActiveModel; // modele actif
var dbWkt = app.ActiveModel.CoordSysWkt;
var wkt = app.GetBestFittingUTM84ProjectionWkt(model.Boundary.BBox2d, dbWkt);
//===========================================================
//CameraTarget
var targetVPDom = model.GetViewPoint()["target"];
var target = new adsk.Vec3d(targetVPDom[0], targetVPDom[1], targetVPDom[2]); // Vecteur Position Camera
//
target.X = -1484990.6099149927;
target.Y = -5006120.6829369618;
target.Z = 3653285.7432678165;
//
var targetPVDom = {target : [target.X, target.Y, target.Z]};
model.SetViewPoint(targetPVDom);
//=============================================================
//CameraHauteur
var upDom = model.GetViewPoint()["up"];
var up = new adsk.Vec3d(upDom[0], upDom[1], upDom[2]); // Vecteur Up Camera
//
up.X = 0.29674430945919844;
up.Y = -0.93338998989416577;
up.Z = -0.20180669356825784;
//
var upPVDom = {up : [up.X, up.Y, up.Z]};
model.SetViewPoint(upPVDom);
//============================================================
//CameraPosition
var posDom = model.GetViewPoint()["pos"];
var pos = new adsk.Vec3d(posDom[0], posDom[1], posDom[2]); // Vecteur Position Camera
//
pos.X = -1485292.4233285857;
pos.Y = -5006330.0850919047;
pos.Z = 3653810.4655176662;
//
var posPVDom = {pos : [pos.X, pos.Y, pos.Z]};
model.SetViewPoint(posPVDom);

It's working !

Thanks Glen !!

Message 5 of 19

Glenn.Coppard
Advocate
Advocate

Nice Work!!

Now you can have a go at making a UI panel for the user to enter the eye/target co-ords.

I use something like this to create my bookmarks from/of specific view locations.

 

Image and video hosting by TinyPic

 

Take a look HERE for some 'how to' inspiration.

Message 6 of 19

Eric_Chappell
Community Manager
Community Manager

Let me know if you'd like this script featured here: https://knowledge.autodesk.com/community/collection/152456?preview 

 

I'll need the following:

 

  • Name of the Script
  • Short description of what the script does
  • Author of the script
  • The script itself
  • Step by step explanation of how to install and use the script (screen shots are always nice)
  • Image that depicts what the script does
  • Links to supporting information (like discussion board or blog posts about the script)

You can send the info to eric.chappell@autodesk.com



Eric Chappell
0 Likes
Message 7 of 19

Anonymous
Not applicable

Thanks Glenn for your support !

 

I have already try this UI solution, but i fail on the very first part of the code :

 

TypeError: Result of expression 'form.findChild("moveElevation")' [null] is not an object.

 

At this moment i had no time to work on this part of the code, but now the code of the main part is working, it's time for the UI...

0 Likes
Message 8 of 19

Anonymous
Not applicable

Ok, it's fixed. Smiley Happy

With a clear mind, i see better !

Now, let's try the UI implementation... 

0 Likes
Message 9 of 19

Anonymous
Not applicable

Hello Eric,

 

I don't understand what you need.

You ask me to visit a page about a script and tell you the name of author ?

I'm not very easy with english as you can read, perhaps some misunderstanding...

 

José

0 Likes
Message 10 of 19

kathy.feng
Autodesk
Autodesk

The command MoveToBookmark( string bookmarkName) will jump to the bookmark defined the model.  If you have sets of viewpoints from bookmarks,  app.ActiveModel.SetViewPoint(viewPoint) are the easier way to jump to the target place as you used in script.

 

 

Regards,

Kathy

0 Likes
Message 11 of 19

Anonymous
Not applicable

Thanks Kathy for your help.

 

My first wish was to move the cam and the point of view on the spot of my script transformations.

So i have create a bookmark on the location and named it "Start.json".

 

I have try with :

var doc = app.ActiveDocument();    

doc.MoveToBookmark("Start.json");

 

Result :No error, No move...

 

Now, my firt move work with the script above (03-02-2018).

 

In your example, "app.ActiveModel.SetViewPoint(viewPoint)" what is "viewPoint" ?

 

José

 

 

0 Likes
Message 12 of 19

Eric_Chappell
Community Manager
Community Manager

@Anonymous what I'd like to do is include your script in an AKN collection that I'm building. Right now the collection only has one script in it (I just started). If you provide the information I've asked for, I will post the AKN article and add it to the collection.

 

I hope that clears it up.

 

Thanks!

 

Eric



Eric Chappell
0 Likes
Message 13 of 19

kathy.feng
Autodesk
Autodesk

Hi José,

 

Thank you for providing the info, I just realized the 'Start.json' was a bookmark name not a filename.  In this case, your first scripts should work. 

I defined the bookmark in the model, and tried your two lines at Script console with InfraWorks 2018, InfraWorks did jump to the targeted position (as snapshot shown).

  

bookmarkjs2018.png

 

I'm interesting in the issue you ran into at the first try, if you have time to provide: 

1) which version of InfraWorks you used

2) Did you reposition the camera before run the script 

3) Did you succeed in executing the scripts in the script console? Any script log if didn't. 

 

For the viewpoint, it's the same as you defined but it's in JSON format, including 'pos', 'target' and 'up' coordinates, one example is as:

var viewPoint = {
"pos": [-2419728.664933832,-3626788.4103535595,4639743.238359936],

"target": [-2419719.1017979556,-3626773.6304270504,4639728.932772671],

"up": [0.28308449080396597,0.5661543042365506,0.7741656637055707]
}; 

 

Thanks for your post. 

 

Regards,

Kathy

 

0 Likes
Message 14 of 19

Anonymous
Not applicable

Hello Eric

 

This script is interesting to try or learn, but it's seam there some better way to move the cam !

doc.MoveToBookmark do the same in one Line !

The script have no name... Move_Cam...

The author ? Me, inspired by a script posted by Elliott Rosenfeld : "Change viewport elevation using this script" and the help of Glenn Coppard.

The script set the coordinate of the cam, of the point of view and the height of the cam.

That's all !

 

J.Rubio

 

// ------------------------------------
// --- Deplacement Camera ---
// ------------------------------------
// variables Camera
var model = app.ActiveModel; // modele actif
//===========================================================
//CameraTarget
var targetVPDom = model.GetViewPoint()["target"];
var target = new adsk.Vec3d(targetVPDom[0], targetVPDom[1], targetVPDom[2]); // Vecteur Position Camera
//
target.X = -1484990.6099149927;
target.Y = -5006120.6829369618;
target.Z = 3653285.7432678165;
//
var targetPVDom = {target : [target.X, target.Y, target.Z]};
model.SetViewPoint(targetPVDom);
//=============================================================
//CameraHauteur
var upDom = model.GetViewPoint()["up"];
var up = new adsk.Vec3d(upDom[0], upDom[1], upDom[2]); // Vecteur Up Camera
//
up.X = 0.29674430945919844;
up.Y = -0.93338998989416577;
up.Z = -0.20180669356825784;
//
var upPVDom = {up : [up.X, up.Y, up.Z]};
model.SetViewPoint(upPVDom);
//============================================================
//CameraPosition
var posDom = model.GetViewPoint()["pos"];
var pos = new adsk.Vec3d(posDom[0], posDom[1], posDom[2]); // Vecteur Position Camera
//
pos.X = -1485292.4233285857;
pos.Y = -5006330.0850919047;
pos.Z = 3653810.4655176662;
//
var posPVDom = {pos : [pos.X, pos.Y, pos.Z]};
model.SetViewPoint(posPVDom);

0 Likes
Message 15 of 19

Anonymous
Not applicable

Hi Cathy,

 

In fact, "Start.json" is the name of the bookmark file.

I have create a bookmark in Infraworks. The file was store in \unver\bookmarks.

The name of the bookmark file was something like 1abba8358-ddd3e-ddd22.... .JSON

I have renamed it in Start.json to be human readable.

 

If i understand your explanation, it was a mistake !

in the command doc.MoveToBookmark("XXX");

XXX is the name of the bookmark in infraworks, not the name of the file of the bookmarks !

 

I will try that way soon !

 

Thanks Catherine !

José.

0 Likes
Message 16 of 19

Anonymous
Not applicable

Hello people,

 

I have rewrite the script to be call with the CSV file as parameter.

I have write two version :

One with the model.SetViewPoint(XX) command

the second with doc.MoveToBookmark(XX) command.

 

I have write a CVS file with 3 differents Cam position to define a path in 3 steps.

 

I have try to move the cam with the script, but even if each camera position is define, only the last step is show.

For example :

doc.MoveToBookmark(Step[1]);

doc.MoveToBookmark(Step[2]);

doc.MoveToBookmark(Step[3]);

Only the move Step 3 is visible.

 

Perhaps i need a kind of "refresh" or a "wait" to let Infraworks completed the move before i ask for another one...

doc.MoveToBookmark(Step[1]);

"Refresh";

doc.MoveToBookmark(Step[2]);

"Refresh";

doc.MoveToBookmark(Step[3]);

"Refresh";

 

A good idea is welcome ! Smiley Happy

José.

0 Likes
Message 17 of 19

kathy.feng
Autodesk
Autodesk

Hi José,

 

Here're scripts to make InfraWorks refresh or wait. You can try appending after each navigation.  

app.Regenerate();

app.Sleep(x); //x seconds

 

 

Regards,

Kathy

0 Likes
Message 18 of 19

Anonymous
Not applicable

Thanks Kathy !

I have try :

app.Regenerate(); = It does'nt work and the app freeze for a very long time before give back the hand...

 

app.Sleep(x); //x seconds = It's working. Not as good as is want, but it's working... I have try many set, the best one is 0,4 second. It's working, the cam move from one point to the second one but with a black screen. No smooth move, no interpolation like when you jump from a bookmark to another.

 

I probably will try the player include in Infraworks. Perhaps we can pilot it with a script...

José.

0 Likes
Message 19 of 19

Glenn.Coppard
Advocate
Advocate

[edit]Image from post 5 re-hosted[/edit]

Specific Coordinate UISpecific Coordinate UI

0 Likes