TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

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

Macro Palette
Read 1282 times
* April 20, 2017, 10:19:12 AM
No idea if anyone uses the Macro Palette, anyway, I needed to  create lots of concentric circles, I couldn't decide the best tool to use so used the macro recorded to record a single alteration as seen below.
Start "Edit|Select"
      Drag xOrigin + 1268.5349766673933000, yOrigin + 241.8858788353384500, zOrigin + 0.0000000000000000, 0
      ChangeEditField 4, "3mm"
      Drag xOrigin + 1268.5349766673933000, yOrigin + 241.8858788353384500, zOrigin + 0.0000000000000000, 0
      ChangeEditField 4, "31mm"
      Drag xOrigin + 1268.5349766673933000, yOrigin + 241.8858788353384500, zOrigin + 0.0000000000000000, 0
      ChangeEditField 5, "3mm"
      Drag xOrigin + 1268.5349766673933000, yOrigin + 241.8858788353384500, zOrigin + 0.0000000000000000, 0
      ChangeEditField 5, "31mm"

Then with a slight modification to the code
 
For I = 31 to 181 step 2
temp = I & " mm"
   Start "Edit|Select"
      Drag xOrigin + 1226.7351720312176000, yOrigin + 195.9666514229270400, zOrigin + 0.0000000000000000, 0
      ChangeEditField 4, temp
      Drag xOrigin + 1226.7351720312176000, yOrigin + 195.9666514229270400, zOrigin + 0.0000000000000000, 0
      ChangeEditField 5, temp
      EnterKey
Next

Selected object, turned on the make copy tool, ran the macro and got all the circles (75 of them)

Just posting in case any new users are unaware of the Macro Recorder
« Last Edit: April 20, 2017, 10:21:06 AM by Andy H »

Logged


April 22, 2017, 02:55:16 AM
#1
That is interesting information.

Thank you.


Jeff


Logged
TC Pro Platinum 2017, 2016 & 2015 (all with LightWorks) & V21
System: i7-5820K @ 3.30GHz, ASRock X99 Extreme4, 16GB DDR4-2133 RAM, Gigabyte GTX 970, Samsung NVMe SSD 950 (256GB), Windows 7 Pro (64-bit) SP1


* April 29, 2017, 06:32:24 PM
#2
Not having done any serious coding since the days of C++ under DOS, may I ask a couple of naive questions, Andy...?

1. What is the significance of the digit that immediately follows "ChangeEditField"? In some of the code it's "4" and sometimes it's "5."

2. What does "EnterKey" do?

Henry H

Logged


* April 30, 2017, 04:58:00 AM
#3
Hi Henry.

1).  The figure after ChangeEditField is the inspection bar field, for example 1 = Scale x, 4 = Size x, etc.  the macro palette can be odd though, using it to record something means one cannot write a macro for distribution (unlike when it was vba), in that if someone didn't have the Scale boxes ticked in the selector properties, it would mean Size x would then be 1 not 4.

2). The EnterKey is the keyboard Enter or Return key press.

For me, the macro recorder is a bit limiting as there is no specific documentation as to how it works, but it can be useful for replicating some tasks, in a similar way the Transform recorder works.   

Logged


* April 30, 2017, 09:31:34 AM
#4
Thanks, Andy.

Henry H

Logged


* May 28, 2017, 01:16:03 PM
#5
Just another little Macro example,  -  many moons ago (back in tc v9) I adapted one of Tom Snape's macro's to revolve a load of circles around their own axes, when I recently found it again I decided to update it to the script type macro's in 2017 (and some earlier version).

Attached is an example of an item - an offset turned candlestick,  which is not easily constructed without lofting circles, and to loft it completely as a single item with no Booleans involved took a lot of circles (47), plus I find it easier to draw the circles on the same workplane using 2 point circle, then revolve into place, using the macro rotates all the circles in one operation (all circles must be selected before running macro).

just an example of how a little macro can simplify some tasks, and when things are out of place (which they were) its quick to delete, redraw, and revolve multiple objects, obviously for one off things then macros will take longer to write than actually doing things by hand (and probably not worth the effort), but for doing multiple repetitive tasks a macro can help.

macro supplied as a .txt file if anyone wishes to have a look at it (it can be copy/pasted into marcro palette.   
« Last Edit: May 28, 2017, 01:23:42 PM by Andy H »

Logged


* May 28, 2017, 02:51:20 PM
#6
This last macro was an experiment which 'sort of' works (with limitations) but shows a couple of the problems that can be encountered with recording macros, a part recorded and part scripted macro which inserts multiple new rows at the bottom of a table (but is slow so patience is required).

There are two main problems, the macro uses the bounding box to find the vertex of the bottom left of the table, if the table is moved, especially after an undo operation is carried out on the table, this vertex can be messed up as far as the macro is concerned, therefore the table needs to be placed on workplane before attempting to add  any rows.

Secondly, is the line DoLocalMenu 107, 0, xOrigin etc.   the 107 is an ID number of 'insert row' from the bottom section of the right click menu,  However - this is not constant between versions,  for example IMSI recently added 'Move along coordinate vectors' to the local menu which set the ID as 107,  prior to that (v21 to 2016) the ID would have to be altered to 106, and in v20 and previous, i.e. before 'on/off node filter' was added to the right click menu the ID would have to be 105.

Posting just to illustrate that one has to be aware things are not always constant in TC if producing a macro for use in multiple versions of TC,  and putting comments into changeable macros should always be done (IMO).   

Oh, if anyone wants to try it - the DoLocalMenu is currently set to tc2017 ID 107,  draw a small table (placed on workplane), copy/paste the text into macro palette, select table, run macro ---- wait until it says complete

Logged


* June 03, 2017, 05:18:33 AM
#7
Following another thread about scaling multiple objects on their own axes,  I adapted an earlier macro to accomplish this (Pro versions only),  there is a section near the top pf the macro to type in the scale factor and 2d or 3d, (typed in as just 2 or 3), this is simply to avoid having to write code to detect what sort of objects are selected, which at present I've no idea how to do.

As with any macro, I'd advise never use it on the master file but always on a copy,  macro's can be flaky at times AND there is no error checking in this macro, a message box has been added saying macro running, as when tested on 400 boxes it took about 10 seconds to complete (Macro's have no progress bar showing the macro is doing anything).

Macro attached in case anyone wants a play and/or improve it.  CAUTION - do not use if the reference point of any object is not at default,   code can be added to reset the referenced point of an object before scaling (but its not a simple one liner - I don't know of any single line code for reset)

Logged