News:

Interested in some really terrific mobile apps? Visit www.turboapps.com for details.

Main Menu
TurboCAD 2026 Platinum box
Now available

TurboCAD 2026.2

The latest update for TurboCAD 2026. It installs over any 2026 build and keeps your activation, drawings and settings. Get it from the Start Page or Help > Check for Update.

how do I open a turbocad macro .tcm file in Turbocad Pro 64 bit 2022

Started by jrdarrah, June 25, 2022, 02:29:35 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

jrdarrah

I need to import coordinates from a .CSV file. I found a .tcm macro that I want to use as a starting point. How / Where do I open the macro so I can edit it to meet my requirements?

murray dickinson

.tcm macros are used in the macro recorder, in those versions that have it.  .csv coordinates need quite extensive formatting to be used in it, TC20_ImportXYZLines.rb and TC20_ImportXYZPoints.rb Ruby scripts are more direct if your version has Ruby. 

Torfinn

TC's macro files are .tcr, don't know if that is the same as .tcm
But Nikki use macro recorder when she test vb script i believe.

Torfinn
V20, V21, 2015 > 2024  Platinum
Deluxe 2015/ 16/ 19
RedSDK enabled
Windows 10 Home Premium (20H2/ 19042.1083) 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB

murray dickinson

Torfinn, I didn't pick that up, but .tcm macros are those composed in the old VBA editor, discontinued after TC V10.5....

nikkipollard

I am not sure what you want to convert the coordinates to but
Here is a  macro(language is vbscript) that reads coordinates from a .csv file and converts to a spline by fit points.
If you want to use that as an example. Copy the script to the macro recorder.
I used regular expressions so there is very little formatting of the .csv needed

vbscript is very close to vba - the Turbocad functions are the same so you can convert the tcm quite easily too.
Open the .tcm file with a text editor
This just shows how to open and read a file with vbscript.

Option Explicit
'_____________________________________________________________________________
'# macro to import points from csv file as a 3d or 2d  spline by fitpoints
'#only draws one spline
'#'If the end points are the same the spline will be closed
'# points can be separated by a comma ,a space, a tab or a semicolon.
' #The script will need to be edited if your local decimal separator is a comma.- see GetPointsFunction

'_______________________________________________________________________________

Call Main
'_______________________________________________________________________________
 Sub Main

Dim objFile,strLine,objFso,fileName
Dim Spline
Dim x1,y1,z1
Dim i, num,j
Dim IsClosed
Dim hasZ
Dim Points,Point
Dim sep
Dim Lay
Lay = "0"

fileName = Application.GetOpenFilename("CSV files (*.csv)|*.csv|XYZ files (*.xyz)|*.xyz|Text files (*.txt) |*.txt|All files (*.*)|*.*")
'" 'check filename
  If fileName = "" Then Exit Sub                                  '# User cancelled

sep = " "
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(fileName)

Do While Not objFile.AtEndOfStream
   strLine = GetPoint(objFile.readline)
  If strLine <> "" Then
  Call AddToArray(Points,strLine)
  End If
Loop

objFile.Close

If IsArray(Points) = False Then
MsgBox "The points don't seem to be in the right format"
Exit sub
End If

num = Ubound(Points)
On Error Resume Next

Point = Split(Points(0),sep)
hasZ = True
If Ubound(Point) < 2 Then
hasZ = False
z1 = 0
End If

If Points(0) = Points(num) Then
  IsClosed = True
  num = num - 1
Else
  Isclosed = False
End If

Set Spline = ActiveDrawing.Graphics.Add(11,"TCW30CURVE")
Spline.Vertices.UseWorldCS = True

For i = 0 to num
  Point = Split(Points(i),sep)
  x1 = cdbl(Point(0))
  y1 = cdbl(Point(1))
   If HasZ = True Then z1 = cdbl(Point(2))
  Spline.Vertices.Add x1,y1,z1
Next

  If IsClosed = True Then
  Spline.Vertices.AddClose
  End If
With Spline
.SetCurveByFitPoints
.Layer = Lay
.Properties.Item("BrushStyle").Value = "None"
.Update
.Draw
End With
Dim UndoRec
Set UndoRec = ActiveDrawing.AddUndoRecord("Add Spline from csv")
UndoRec.AddGraphic Spline
UndoRec.Close

Set Spline = Nothing
ActiveDrawing.ActiveView.Refresh

 End sub


'_____________________________________________________________________________________

  Sub AddToArray(ByRef a, v)
 
 If IsArray(a) Then
  ReDim Preserve a(UBound(a)+1)
  a(UBound(a)) = v
 Else
 Redim a(0)
 a(0) = v
 End If

 End Sub

'______________________________________________________________________________________

Function GetPoint(line)
   '# checks the line in file is in the correct point form and converts it to a space separated string

 Dim spat
 spat = "(; ?|, ?|\t| )"                                                                   ' #Coordinate Separator Pattern
'  # for comma decimal separator use
' spat = "(; ?|\t| )"         

 Dim pat,pat1


 pat1 = "(-?\d+\.?\d*)"                                                                    '# Coordinate Pattern
'  # for comma decimal separator use
'   "(-?\d+,?\d*)"

 pat = "(^" & pat1 & spat & pat1 & spat & "?" & pat1 & "?$)"
 Dim re
 Set re = New RegExp
  With re
            .Pattern    =   pat
            .IgnoreCase = False
            .Global = False
  End With

If re.Test(line) = False Then
GetPoint = ""
Else

dim res
Set res = New RegExp
  with res
.Pattern    =   spat
.IgnoreCase = False
.Global = True
  end with


GetPoint = res.Replace(line," ")

End If

End Function

'_____________________________________________________________________________________

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

jrdarrah

Thanks, this vbscript will work. If I have this as a starting point changing it to suite my exact need will be easy.

murray dickinson

Thanks, Nikki.  Your script is a great example of what's possible in the MR, and darned useful in its own right.  Question: purists will probably frown on such a practice if it's possible, but will a script run if you mix vbs with terms the MR's produced in recording actions?  Something like using your .vbs terms to prompt for an external profile's coordinates in a script that will then extrude it?   

nikkipollard

Quote from: murray dickinson on June 26, 2022, 07:28:53 PMThanks, Nikki.  Your script is a great example of what's possible in the MR, and darned useful in its own right.  Question: purists will probably frown on such a practice if it's possible, but will a script run if you mix vbs with terms the MR's produced in recording actions?  Something like using your .vbs terms to prompt for an external profile's coordinates in a script that will then extrude it?   
Yes it is the same language.
So if you are unsure how to code something. Recording that action with the macro recorder should guide you and you can copy the code.
If the macro recorder doesn't have a solution - then you need to wade through the SDK documentation.
Or google if it is not a TC question - There is lots of help for vbscript on the internet. I found the documents for Rhinoscript very helpful. - they have a vbscript section.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h