TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Be sure your post is relevant to the current discussion.  Create a new topic within the appropriate board if you are unsure.

Save as script in animation lab
Read 5253 times
* July 16, 2015, 10:11:26 AM
Is it possible to put a script in animation lab that will save a drawing with a different name as each frame is rendered.


July 16, 2015, 11:13:47 AM

you do not need a script, if I understand you correctly.
Under AnimationLab Options you can select a name for all saved image frames which are automatically indexed as the Animation runs.

Regards Tim

Regards Tim

You can design without engineering, but you cannot engineer without design.
Using Win 10 with Designer 2017-2020 and TurboCAD Pro. Plat. 2018-2020 + Lightworks (64-bit versions) + AnimationLab 5.2.
Windows 10 Pro (1909) 64-bit

* July 16, 2015, 01:23:07 PM
On the AnimationLab Options "Preferences" page, make sure "Movie Creator" is set to "None".

John R.

V17—V21, 2015—2020
Designer, Deluxe, (Basic, Expert, Professional), Platinum
RedSDK enabled
Windows 10 Pro (1909), 64-bit

* July 17, 2015, 07:11:16 AM
Sorry Tim and John, I should have explained better, I am using a constrained shape that has variables that will change with each frame and want to save the drawing as a drawing with a different name after each frame updates the variable. Animation lab probably has the potential with a vbscript to do this but am not sure of the syntax that would be used.


* July 17, 2015, 07:47:26 PM
After some reading of various scripts I decided to have a play, but I'd suggest running it past the guys / gals in the SDK part of the forum.

## edited ## if you try this on your own file - always use a copy of your file never the original ## end edit ##

The attached file is just an example and something to think about (I'm not very good with VBS) it's a simply movement + constraint movement, the reason for the 4 to 4 movement 0,0,0, is because TC is running the script before the animation frame, so if it was left as 0 - 3 then the last movement wouldn't be saved.

BUT I had problems in v19 (not in my v21 which it was originally done in) in that  the constraints break, and TC changes the file to the last one saved, (in v21 the original file is still open), this needs keeping an eye on to ensure your not working on the wrong file, it may be my v19 which is faulty I don't know.

There is no error checking (need adding) which means that the SaveCopyAs command will overwrite any file it finds with the same name, whether you want it to or not, also the Set commands would normally be outside the sub, but that also caused problems, because AnimLab is running the script prior to actually running the animation so it hits the 'Set dwng = nothing when it still wants to run the script again for the animation - at least that what it appears to do.

Obviously your path will need to be entered, the one in the file is just where I saved them, a folder on C: called TC files, and sub folder called AnimSaveTest.

As I say it may be better checking in the SDK forum to see if anyone thinks it may cause expected problems and for error checking, especially having the set commands running in the sub, hope your v19 works better than mine.
« Last Edit: July 17, 2015, 08:20:18 PM by Andy H »


* July 18, 2015, 04:22:05 AM
Added a bit of simple file checking which will ask if user wants to overwrite existing files.

Problem, because AnimLab is running the script twice, once pre screen animation and then again during the message box comes up twice - not figured that bit out yet.

Code: [Select]
Sub PreScenarioAction
// TODO your code
end sub

Sub PostScenarioAction
// TODO your code
end sub

Dim appl ' TC application
Dim dwng ' active drawing
Dim fname ' file path
Dim newname ' after step number and .tcw added
Dim stepfm ' step numeber count -1
Dim stepend ' stepnumber for comparison
Dim fso ' file system object
Dim msg ' message box response
Dim flag ' if file exists exit
flag = 0

Sub StepCustomAction
// TODO your code
' // exit if user does not want to overwrite the files
If flag = 2 then
Exit Sub
End if

Set appl = CreateObject("TurboCAD.Application")
Set dwng = appl.ActiveDrawing
stepend = Stepcount - 1
stepfm = StepNum
fname = "C:\TC files\AnimSaveTest\testsave"
newname = fname & stepfm & ".tcw"

' // checking if file already exists //

If flag < 3 then   
  Set fso = CreateObject("Scripting.FileSystemObject")
  If (fso.FileExists(newname)) Then
      msg = msgbox ("Caution - clicking OK will overwrite the files" & vbcrlf & _
"Cancel will run scenario without overwriting files ", 48 + 1, "Caution")
  End If
End If

' // exit if user clicks cancel // 
If msg = 2 then
flag = 2
set fco = Nothing
set appl = Nothing
set dwng = Nothing
exit sub
flag = 3   
End if

dwng.SaveCopyAs  newname

' if last frame set to nothing
If stepfm = stepend then
Set fso = Nothing
Set appl = Nothing
Set dwng = Nothing
flag = 0
End If

end sub

Sub PostStepCustomAction
// TODO your code
end Sub
« Last Edit: July 18, 2015, 06:00:31 AM by Andy H »


* July 18, 2015, 11:39:11 AM
Many thanks for the assistance Andy, just about to give it a tryout.

I will get back to you tomorrow and let you know how I got on.


* July 18, 2015, 11:54:46 AM
Well Done Andy, this is the basic starter I  needed to get moving and it works as I had hoped.

I tried to get some information on this a few years back as it would also be handy to use animation lab to iterate through a series of viewports printing each one to PDF.
« Last Edit: July 18, 2015, 11:59:29 AM by Orion20036 »


* July 18, 2015, 12:04:01 PM
Glad I could help Michael.


* July 18, 2015, 12:12:11 PM
I used to do a lot of programming many years ago Andy, most with Borland Delphi but my programming days are limited now as I have filled my poor little head up in the last 45 years and hard getting anymore information to stick, obviously developed a neural leak along the way.

Thank You Again!.


* July 18, 2015, 12:20:21 PM
Just tried saving the drawing as a pdf and that works just fine also so something to iterate through each paper space page and print to pdf should be possible, probably with something that checks if the pdf has been created before moving to the next paper space page. It means that once you have all your paper spaces set up and ready for print, you can walk away from the machine and get on with something else.


* July 18, 2015, 12:45:10 PM
I know full well about memory leaks, mine is like a sieve.

pdf, that's a really interesting scenario and not something I had ever thought of, Delphi was the first thing I ever tried programming (many year ago) can't remember much about it these days, I potter around with some vba in Excel and Access occasionally but don't know much about the TC syntax, gotta try to learn it someday, maybe this winter if we get snow and ice in the North West UK and its too cold to go outside.


* July 18, 2015, 01:02:50 PM
Just as well you are in the UK Andy, same here and as you know we only have two seasons now wet and dry one lasts ten months and the other last 2 months if we are lucky. Kevin Chapman was a good lad with the SDK syntax as well as having a string of languages under his belt but not many others that have the insight into it.

IMSI badly need some permanent programmer CAD conversant people behind Turbocad here on the forums as we now have a great set of tools but are still lacking in our ability to automate many tasks.

You may have spurred me to pick up on some of my programming again but not too extensive as time and memory do not allow these days.