News:

All posts discussing pricing or where to buy TurboCAD will be deleted.

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.

Macro processing

Started by AussieBloke, February 29, 2024, 04:56:00 PM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

AussieBloke

I did a search for macro processing and found ppm macro, not sure if thats a good candidate for using here.

Im interested making a macro that creates a text file for all objects in a drawing including the material assigned and then  saves that to a text file. Is that feasible?

A little more, saving the TurboLux engine and scene settings would be a bonus.

Torfinn

Are you sure it is not Macro for ppm you have found, or is it actually a ppm file named Macro Darryl ?

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

nikkipollard

#2
Quote from: Darryl W on February 29, 2024, 04:56:00 PMI did a search for macro processing and found ppm macro, not sure if thats a good candidate for using here.

Im interested making a macro that creates a text file for all objects in a drawing including the material assigned and then  saves that to a text file. Is that feasible?

A little more, saving the TurboLux engine and scene settings would be a bonus.


It's pretty easy to write a script that you can run in the macro recorder, to do this, Darryl.

I don't have Turbolux - So I am not sure how to extract that info -
but the graphic list with materials is easy.
Hopefully my self taught programming style doesn't offend the pro programmers.
Option Explicit
 '====================================================================
  '# DESCRIPTION
    'Extracts material and graphic list from selected Graphics
    'Select Graphics before running the program
'=====================================================================
Call Main
 '_______________________________________________________________________________
Sub Main
 
 Dim FileName
 Dim gf
 Dim gId
 Dim gName
 Dim gType
 Dim gMaterial
 Dim i
 Dim DwgName
 Dim objFSO
 Dim objFile
 Dim StartAt
 
 'Check if any graphics have been selected
  If Selection.Count = 0 Then
      MsgBox "Please Select First"
      Exit Sub
  End If
 Set obJFSO = CreateObject("Scripting.FileSystemObject")

 'get the active drawing Name
 DwgName = objFSO.GetFileName(ActiveDrawing.Name)
 ' the default file name, saves typing everytime you run the script
  StartAt = "C:\Users\User\Documents\" & DwgName & "_MaterialList"
 
  FileName =  Application.GetSaveAsFileName(StartAt,"*.csv")
  If FileName = "" Then Exit Sub    'The user cancelled don't do anything else
 
  FileName = FileName & ".csv"      'Add the extension to the name
 'open a new text file
  Set objFile = objFSO.CreateTextFile(FileName,2,False)
  'add the headings to the text file
  objFile.WriteLine("Graphic ID,Graphic Name,Graphic Type,Material")

  On Error Resume Next
  'loop through each graphic in the selection
 
 For i = 0 to Selection.Count-1
  Set gf = Selection(i)
  'Get graphic properties
  gId = gf.ID
  gName = gf.Name
  gMaterial = gf.Properties.Item("Material").Value
  gType = gf.Properties.Item("M_ObjectType").Value
  objFile.WriteLine(gId & "," & gName & "," & gType & "," & gMaterial)
  Next
  On Error GoTo 0
 
 objFile.Close
 MsgBox("File Saved to" & vbCrlf & FileName)
 Set objFSO = Nothing
 Set gf = Nothing
 
End Sub

'________________________________________________________________________________

The pdf - is the same code colour coded so it is easier to read.
You can copy the code into the macro recorder and hopefully it will run.
Test on an unimportant file first - just in case the newer versions of TC have issues with the macro recorder.

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

nikkipollard

#3
Darryl my script in the previous reply is very basic.
If you have Groups and blocks in the selection, you would have to loop through the list of Graphics in the group or block.
Something like the attached pdf
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

AussieBloke

Oh wow thanks Nikki, to be honest I was just looking to see if what I was after was possible. I will download tomorrow morning my time.  ;D

The reason I wanted a macro like what you've posted is because its a real pain to manually check each object/block etc. In my case one drawing has 1,970 objects covering about 72mb in size.


nikkipollard

#5
Yes Darryl I probably got a bit carried away - I am fairly certain you can use the Report tool to do the same thing.
But sometimes the report tool doesn't have the properties you want to extract. And then knowing how to extract data is cool
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

AussieBloke

Okay so with that report tool, what macro changes are required?

nikkipollard

#7
You don't use a macro with the report tool.
On my system in the menu go to tools| database| report
click on Create
Choose a field you want and click add
If you have Groups or blocks, click on advanced and make sure that the option to extract from Groups and blocks is selected.
Once you have set up the report. Click ok
Select the report style that you have just made and click on report.
You can either dump a table onto your active drawing or save as a file.
TC used to remember all the reports you had ever defined. But in TCs programming wisdom you now have to save those reports Styles if you want to use them in other projects.
https://turbocaddoc.atlassian.net/wiki/spaces/T2UG/pages/100925670/Step+3-+Define+Fields+for+the+Report

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

Alvin Gregorio

Quote from: nikkipollard on February 29, 2024, 07:59:53 PMThe pdf - is the same code colour coded so it is easier to read
"Same" as what Nikki?
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

Quote from: Alvin Gregorio on March 01, 2024, 04:42:09 AM
Quote from: nikkipollard on February 29, 2024, 07:59:53 PMThe pdf - is the same code colour coded so it is easier to read
"Same" as what Nikki?
Same as the code in the reply Alvin
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: nikkipollard on March 01, 2024, 05:52:28 AM
Quote from: Alvin Gregorio on March 01, 2024, 04:42:09 AM
Quote from: nikkipollard on February 29, 2024, 07:59:53 PMThe pdf - is the same code colour coded so it is easier to read
"Same" as what Nikki?
Same as the code in the reply Alvin
I think what I and presumably some others don't know Nikki is in what application are you creating this Code, such that it is color-coded while you are creating and editing it?
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

#11
Quote from: Alvin Gregorio on March 01, 2024, 06:04:55 AM
Quote from: nikkipollard on March 01, 2024, 05:52:28 AM
Quote from: Alvin Gregorio on March 01, 2024, 04:42:09 AM
Quote from: nikkipollard on February 29, 2024, 07:59:53 PMThe pdf - is the same code colour coded so it is easier to read
"Same" as what Nikki?
Same as the code in the reply Alvin
I think what I and presumably some others don't know Nikki is in what application are you creating this Code, such that it is color-coded while you are creating and editing it?

I was trying to make it easier to follow Alvin.
You can type in the macro recorder directly. - The language the macro recorder palette uses is vbscript.
I don't think there is any IDE specifically designed for VBScript
I use Notepad++. I set up a user defined language for a combination of vbscript and the TC SDK.
But in all honesty I am a little worried about the future of our macro recorder  because windows is deprecating vbscript. Whatever that means. 
I am trying to convert all my small scripts to VB.net in Visual studio - which has a very powerful IDE - which is perfect for learning to navigate your way around TC SDK.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Dean

Quote from: Darryl W on February 29, 2024, 04:56:00 PMI did a search for macro processing and found ppm macro, not sure if thats a good candidate for using here.

Im interested making a macro that creates a text file for all objects in a drawing including the material assigned and then  saves that to a text file. Is that feasible?

A little more, saving the TurboLux engine and scene settings would be a bonus.


It's not talked about much here but the Database Connect is a powerful and useful Platinum feature.
Your custom database can be used in Reports and edited, assigning links and labels to objects.
that being said, there is a learning curve but you create what works best for your own needs.
attached is a snip of what is possible.
"What do I know, I'm still learning".
Lenovo Legion T5  Intel(R) Core(TM) i7-14th Gen 20 cores Nvidia RTX 4070 Super 16GB Windows 11 home TurboCad 2025 with Animation Lab 6.0

nikkipollard

Quote from: Dean on March 01, 2024, 07:42:10 AM
Quote from: Darryl W on February 29, 2024, 04:56:00 PMI did a search for macro processing and found ppm macro, not sure if thats a good candidate for using here.

Im interested making a macro that creates a text file for all objects in a drawing including the material assigned and then  saves that to a text file. Is that feasible?

A little more, saving the TurboLux engine and scene settings would be a bonus.


It's not talked about much here but the Database Connect is a powerful and useful Platinum feature.
Your custom database can be used in Reports and edited, assigning links and labels to objects.
that being said, there is a learning curve but you create what works best for your own needs.
attached is a snip of what is possible.


That was my suggestion too.
It sounds like he wants to extract standard properties which wouldn't even require using the Database connect tool.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h