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.

Find matching volume (Sorry - Long)

Started by PCSteel, August 02, 2025, 10:39:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PCSteel

I've mentioned previously how much I would like a tool that would search a drawing for solid objects with matching volumes. Recent discussion about AI prompted me to do my first ever AI query.

My first question was:

How can I search a TurboCAD drawing to find ACIS solid objects with matching volumes?

AI's reply was:
1. Open the Drawing
Launch TurboCAD and open the drawing file you want to analyze.
2. Access the Object Properties
Use the Object Properties tool to inspect the properties of the solid objects in your drawing. This can usually be found in the Properties palette or by right-clicking on an object and selecting Properties.
3. Identify ACIS Solids
Ensure that you are specifically looking for ACIS solid objects. You can filter the objects by type in the properties panel.
4. Calculate Volumes
For each ACIS solid, check the volume property. You may need to select each object individually to view its volume in the properties panel.
5. Create a List of Volumes
As you identify the volumes, create a list (either on paper or in a digital format) to keep track of the volumes of each ACIS solid.
6. Find Matching Volumes
Compare the volumes in your list to find any matches. You can do this manually or use a spreadsheet program to help with the comparison.
7. Highlight or Select Matching Objects
Once you identify matching volumes, you can highlight or select these objects in TurboCAD for further analysis or modification.
8. Use Scripting (Optional)
If you are familiar with TurboCAD's scripting capabilities, you can write a script to automate the process of finding and comparing volumes of ACIS solids.
By following these steps, you should be able to effectively search for and identify ACIS solid objects with matching volumes in your TurboCAD drawing. If you have any specific questions about any of the steps, feel free to ask!


I then asked:
Provide a script to automate the process of finding and comparing volumes of ACIS solids in a TurboCAD drawing.

And the reply was:
🖥� TurboCAD Script for Finding ACIS Solid Volumes
vbscript

Copy Code
' TurboCAD Script to find and compare volumes of ACIS solids

Dim obj As Object
Dim volumeDict As Object
Set volumeDict = CreateObject("Scripting.Dictionary")

' Loop through all objects in the drawing
For Each obj In ActiveModel.Entities
    ' Check if the object is an ACIS solid
    If obj.Type = acSolid Then
        ' Get the volume of the solid
        Dim volume As Double
        volume = obj.Volume
       
        ' Check if the volume already exists in the dictionary
        If volumeDict.Exists(volume) Then
            ' If it exists, add the current object to the existing list
            volumeDict(volume).Add obj
        Else
            ' If it doesn't exist, create a new list for this volume
            Dim objList As Object
            Set objList = CreateObject("Scripting.Dictionary")
            objList.Add obj
            volumeDict.Add volume, objList
        End If
    End If
Next

' Output the results
Dim key As Variant
For Each key In volumeDict.Keys
    If volumeDict(key).Count > 1 Then
        ' Print the matching volumes and the objects
        Print "Volume: " & key & " has " & volumeDict(key).Count & " matching objects:"
        Dim matchingObj As Object
        For Each matchingObj In volumeDict(key)
            Print " - Object ID: " & matchingObj.ID
        Next
    End If
Next

' Clean up
Set volumeDict = Nothing
📝 How to Use the Script
Open TurboCAD: Launch TurboCAD and open the drawing you want to analyze.
Access the Script Editor: Go to the Tools menu and select Script Editor.
Copy and Paste the Script: Copy the provided script and paste it into the Script Editor.
Run the Script: Execute the script by clicking the Run button in the Script Editor.
View Results: The script will output the volumes and the corresponding object IDs of ACIS solids with matching volumes in the TurboCAD console.
⚠️ Notes
Ensure that your TurboCAD version supports scripting and that you have the necessary permissions to run scripts.
You may need to adjust the script based on your specific TurboCAD version or any additional requirements you have.
Feel free to modify the script as needed, and let me know if you have any questions or need further assistance!


I tried the above with no result and then replied:
That didn't work in TurboCAD 2023 Platinum.  Message is "Undefined Identifier: Dim", any suggestions?

AI's reply was:
It seems that the scripting language used in TurboCAD 2023 Platinum may differ from the one I provided. TurboCAD uses a specific scripting language that may not support certain constructs like Dim. Instead, you can use TurboCAD's built-in scripting commands.

Here's a revised version of the script that should work in TurboCAD 2023 Platinum:

🖥� Revised TurboCAD Script for Finding ACIS Solid Volumes
vbscript

Copy Code
' TurboCAD Script to find and compare volumes of ACIS solids

' Create a dictionary to store volumes and their corresponding objects
volumeDict = CreateObject("Scripting.Dictionary")

' Loop through all entities in the active model
For Each obj In ActiveModel.Entities
    ' Check if the object is an ACIS solid
    If obj.Type = acSolid Then
        ' Get the volume of the solid
        volume = obj.Volume
       
        ' Check if the volume already exists in the dictionary
        If volumeDict.Exists(volume) Then
            ' If it exists, add the current object to the existing list
            volumeDict(volume).Add obj
        Else
            ' If it doesn't exist, create a new list for this volume
            Set objList = CreateObject("Scripting.Dictionary")
            objList.Add obj
            volumeDict.Add volume, objList
        End If
    End If
Next

' Output the results
For Each key In volumeDict.Keys
    If volumeDict(key).Count > 1 Then
        ' Print the matching volumes and the objects
        Print "Volume: " & key & " has " & volumeDict(key).Count & " matching objects:"
        For Each matchingObj In volumeDict(key)
            Print " - Object ID: " & matchingObj.ID
        Next
    End If
Next

' Clean up
Set volumeDict = Nothing
📝 How to Use the Revised Script
Open TurboCAD: Launch TurboCAD and open the drawing you want to analyze.
Access the Script Editor: Go to the Tools menu and select Script Editor.
Copy and Paste the Revised Script: Copy the revised script and paste it into the Script Editor.
Run the Script: Execute the script by clicking the Run button in the Script Editor.
View Results: The script will output the volumes and the corresponding object IDs of ACIS solids with matching volumes in the TurboCAD console.
⚠️ Additional Tips
Ensure that your TurboCAD version supports the scripting features used in this script.
If you encounter any further issues, please check the TurboCAD documentation for specific scripting syntax and commands relevant to your version.
Let me know if this works or if you need further adjustments!


This script failed also. So if anyone is still with me after all this  ;) , did any of this have a chance of working or am I flogging a dead horse here?

Any other ideas, anyone.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

nikkipollard

#1
So this seems to be a vba script
The macro recorder uses vbscript as a programming language.
Can you ask the AI to convert to vbscript.
That should run in the macro recorder.

Other wise remove all the "As xxx" part of the
Dim x as xyz statements

Or you could try running it in excel - just remember to reference IMSIGX.dll

They seem to have the wrong object Types for Turbocads API.
So viewing it in the Excel developer Console would Highlight where they are wrong
Basically we have Drawings not Models
and Graphics - Not Entities.

The other thing I couldn't find was a "volume" property for a Turbocad Acis Solid.
But maybe your version of Turbocad has a volume property for Axis Solids.
If it does you would access the property like this
If Obj.Type = "TCW60ACISSOLID" then
dim Volume
Volume = Obj.Properties.Item("M_Volume").Value
End If

But neither M_Volume or Volume worked so I am not sure how to extract the volume from a Surface or a solid.
Most probably it would need to be calculated from the faces. Which would get quite complicated I would think.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

I wonder if you fed, our chm document (from the Turbocad SDK docs) to the AI if you would have better results.

Although the property names are a guess because there is no documentation for them.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: PCSteel on August 02, 2025, 10:39:21 PMI've mentioned previously how much I would like a tool that would search a drawing for solid objects with matching volumes.
Hello John,
I don't know if this topic thread is more about what is quoted above, or about utilizing AI to achieve the above.
I feel confident if one stuck with it, they could adequately teach and train their AI to achieve the above.

When you state "matching volumes", is there any tolerance?  Or does the volume have to match within the nth-decimal-place exactly?

What method(s) are you now using to achieve the above?

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

#4
Quote from: Alvin Gregorio on August 03, 2025, 05:30:48 AM
Quote from: PCSteel on August 02, 2025, 10:39:21 PMI've mentioned previously how much I would like a tool that would search a drawing for solid objects with matching volumes.
Hello John,
I don't know if this topic thread is more about what is quoted above, or about utilizing AI to achieve the above.
I feel confident if one stuck with it, they could adequately teach and train their AI to achieve the above.

When you state "matching volumes", is there any tolerance?  Or does the volume have to match within the nth-decimal-place exactly?

What method(s) are you now using to achieve the above?


At the moment I don't believe there is enough documentation on the Turbocad API on the web. So I am fairly certain that Tims Ai will work because he has taught it. But you can't teach AI if you have poor documentation and you don't know anything. As far as I know Turbocad still needs to update the SDK documentation.

However I could be wrong.
It would be interesting to see how AI would be able to handle the complexities of a seemingly simple task like this.
Initially I thought it would be as simple as adjusting the syntax to match TC. But after discovering that my version doesn't have a property for volume I realised I would have to use the facets of the surface to calculate the volume which would be easy except we have 3 different types of 3d graphics - a smesh a solid and a surface. which is easy to solve. Set the solid value to 0 but that doesn't work for extrudes etc.

an AI that understood how complex TC is would be a godsend
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

PCSteel

Thanks so much for looking at this Nikki and for your suggestions. Most All this is way above my level of understanding, so I need all the help I can get.
Thanks to you also Alvin. "Find matching volume" is what it's all about and how that is achieved is not important as long as it's faster than looking over hundreds of objects in the model and checking those that look the same to confirm they are - or not. As far as tolerance goes, ideally I would like to be able to specify a range (eg. + or - 10mm³). At present I'm entering the volumes into a spreadsheet as I identify each part and using the spreadsheet to check for matches.
Thanks again.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

I have an idea. Or two.
Can probably achieve the desired result in less than 20 minutes.
  I'll work on it. (when I'm not working)
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)

Alvin Gregorio

#7
I'm starting with Mass Properties  (within the Measurement Info, for me)
Then creating Custom Properties from that.*
BOM Report is one way to go.  Once into Excel, Object IDs can be used in a Select_by_Query.  Some formatting or something can make populating the Query fairly quick and simple.

Select_by_Query method:
  I tried a >= AND <= , but that didn't work.  Exact volume—  that is, just the =—  works in Select by Query.  But what's the odds that out of the hundreds of objects, John only wants to select those with the exact same volume.

*First issue I am running into— John said "hundreds" of objects.  Dang Mass Properties doesn't have a drag-window option; we have to hold the Shift-key down and select the objects one at a time.  Not good for "hundreds" of objects.
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

#8
Quote from: Alvin Gregorio on August 03, 2025, 05:56:26 PMI'm starting with Mass Properties  (within the Measurement Info, for me)
Then creating Custom Properties from that.*
BOM Report is one way to go.  Once into Excel, Object IDs can be used in a Select_by_Query.  Some formatting or something can make populating the Query fairly quick and simple.

Select_by_Query method:
  I tried a >= AND <= , but that didn't work.  Exact volume—  that is, just the =—  works in Select by Query.  But what's the odds that out of the hundreds of objects, John only wants to select those with the exact same volume.

*First issue I am running into— John said "hundreds" of objects.  Dang Mass Properties doesn't have a drag-window option; we have to hold the Shift-key down and select the objects one at a time.  Not good for "hundreds" of objects.

I don't have mass properties in my version,  that is new.
Does Volume show up under metrics in the SI palette in your version?
If it does, a little bit of tweaking to the AI script might work. We just need to find out that property name to search for it.
I normally get the macro recorder to list all the properties for a selected object.
'====================================================================
   '# DESCRIPTION
'Find property names of the selected graphic
'=====================================================================
'Select the graphic and run the code

Dim gfx : Set gfx = Selection(0)

dim props, prop
Set props = gfx.properties
dim names
names = ""
On Error Resume Next

For Each prop In props
names = names & vbCrlf & prop.name

Next

call ActiveDrawing.Graphics.AddText(names,0,0,0,50)




Run the code and see if there is a property for Volume in your version.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

PCSteel

Quote from: nikkipollard on August 03, 2025, 10:00:28 PMDoes Volume show up under metrics in the SI palette in your version?

It does Nikki if you extend to show 'Solid-state Physics'.

You cannot view this attachment.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

PCSteel

Quote from: nikkipollard on August 03, 2025, 10:00:28 PMI normally get the macro recorder to list all the properties for a selected object.
Should that script run in the 'Macro Recorder' Nikki? I tried it and got an error message.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

#11
The script below works in MacroRecorder.  Have to have an object selected.
It takes a couple of seconds to run.  Once completed, a pop-up window will display "Script playback completed" and a Text object will have been inserted.  Look for that Text object (or F7) and read its Attribute (text within).

'====================================================
'# DESCRIPTION
'Lists property names of the selected graphic
'====================================================

Dim gfx, props, prop, names
Set gfx = Selection(0)

On Error Resume Next
Set props = gfx.properties ' Consider checking this with If Not IsEmpty or proper method

names = ""
If Not props Is Nothing Then
    For Each prop In props
        If Not prop Is Nothing Then
            names = names & vbCrLf & prop.name
        End If
    Next
End If

Call ActiveDrawing.Graphics.AddText(names, 10, 10, 0, 50)

My having done so, the Text Attribute lists below.  "Volume" is not listed.:
PenColor
PenWidth
PenWidthGeometric
PenScale
PenStyle
BrushColor
HatchBGColor
TextBGColor
TextTransformation
TextBackward
TextUpsideDown
BrushScale
BrushAngle
BrushStyle
BrushTransparency
BrushGFFitMode
BrushGFCenterPointMode
BrushGFFocusScale
BrushGFPoints
TextStyle
ScaleSystem
Layer
Info
URL
StyleId
TextFont
TextFormat
TextSize
HatchCross
BrushDrawMode
PenAlignment
StyleTree
HatchOriginMode
HatchOriginOffsetX
HatchOriginOffsetY
TextMode
TextObliquity
DatabaseID
Kind
Closed
Selected
RegenMethod
LimitVertices
AttTag
AttPrompt
AttValue
AttInvisible
AttConstant
AttVerify
AttPreset
AttDef
Thickness
ThicknessBody
Material
MaterialUsesPenColor
MaterialImage
Solid
NamedView
OleItemID
ViewportTransparent
ViewportScaleFixed
ViewportScale
ViewportLayerSetName
ViewportRenderingForPrint
ViewportRenderQuality
ViewportRenderType
ViewportRenderMode
ViewportRenderExternalMode
ViewportRenderIterationCount
ViewportRenderRadQuality
ViewportRenderRadMinArea
ViewportRenderRadMaxArea
ViewportRenderPerspective
ViewportRenderPerspectiveAngle
ViewportRenderLayersname
ViewportBackgroundColor
ViewportVisibleBox
CameraPerspective
CameraViewAngle
CameraPosition
CameraTarget
CameraTheUp
RenderQuality_Type
RenderQuality_Mode
RenderQuality_ForegroundWireframe
RQHL_AlwaysClipObjs
RQHL_DHL_AsDashed
RQHL_DHL_AsCustom
RQHL_DrawIntr
RQHL_SuppressTanHL
RQQ_RadRenderMode
RQQ_RadIterations
RQQ_RadQMinArea
RQQ_RadQMaxArea
VgiCached
HLCached
VgiKeepAspectRatio
VgiUpdateType
VgiSizeX
VgiSizeY
RQHL_HLP_Style
RQHL_HLP_Color
RQHL_HLP_Scale
RQHL_HLP_Alignment
RQHL_HLP_Width
Print style
M_ObjectType
M_StartPoint
M_FinishPoint
M_Length
M_Angle
M_Vertices
M_VertexArray
M_Area
M_Perimeter
M_Center
M_Radius
M_Circumference
M_MajorRadius
M_MinorRadius
M_StartAngle
M_FinishAngle
M_ArcLength
M_WedgeArea
M_Rotation
M_Size
M_BlockName
M_Members
M_VertThread
M_HorThread
M_Smooth
M_Facets
M_Normals
M_ViewName
M_ShapedViewport
M_Height
M_Width
M_Phisics
M_Matrix
M_RefPointOff
M_Offset
M_Rotate
M_ConvertPenColor
M_ConvertPenColor
M_Copies
M_MPositionX
M_MPositionY
M_MPositionZ
M_MRotationX
M_MRotationY
M_MRotationZ
M_MSizeX
M_MSizeY
M_MSizeZ
M_MCopy
M_ExtentsSize
M_Closed
VP_LockCamera
VP_LockScale
VP_On
VP_OverLayersVisibility
RQAD_RenderStyle
PropertySets
RemoveHiddenLine
$CONEBASERADIUS
$CONETOPRADIUS
$CONEHEIGHT
$CONECUTHEIGHT
$CONEANGLE
$APPROCSIMCURVE
$SMOOTH
$SMOOTHLEVEL
$CONE AXIS DIVISIONS
$CONE HEIGHT DIVISIONS
$CONE BASE DIVISIONS
#$AUX@_ToolInfo Properties
#$AUX@_UniqueName
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)

murray dickinson

Is shape important, or volume the only criterion ie is this to find copies or iterations of objects?

nikkipollard

It doesn't seem like the properties have changed in the last 5 years.

You can always calculate the volume using the facets of the surface. But it gets complicated when you have different graphic types in the drawing.
What type of graphics are they? The AI code was looking for acis solids.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

PCSteel

Quote from: murray dickinson on August 04, 2025, 05:31:23 AMIs shape important, or volume the only criterion ie is this to find copies or iterations of objects?
Yes Murray, shape is important and I know it's possible but I find that I don't see differing shapes when volumes match.

Quote from: nikkipollard on August 04, 2025, 08:34:58 AMWhat type of graphics are they? The AI code was looking for acis solids.
Yes Nikki, they're ACIS solids. My misleading screen shot above is from another drawing that I happened to have open where I chose an extrusion.  :-[
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

Quote from: PCSteel on August 04, 2025, 03:00:33 PMshape is important and I know it's possible but I find that I don't see differing shapes when volumes match.
What does that mean, John?
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)

PCSteel

I know it's possible to have objects with the same volume but with different shapes but I find that with the objects I'm dealing with, when the volume is the same, the shape is the same. Of course that doesn't mean that I'm not going to get caught out one day.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

Quote from: PCSteel on August 04, 2025, 07:53:26 PMI know it's possible to have objects with the same volume but with different shapes but I find that with the objects I'm dealing with, when the volume is the same, the shape is the same. Of course that doesn't mean that I'm not going to get caught out one day.
Are you able to give us part of a .tcw file to work with?  Maybe 20% of the "hundreds" of objects.  You can name the .tcw file something generic, so that we don't know what it's proprietary-ly for.
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)

murray dickinson

If they have the same orientation bounding box dimensions might be easier to recognise.

PCSteel

Ok Alvin, a small sample attached. This sample is more simple than the usual stuff because its orientation is all horizontal.You cannot view this attachment.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

PCSteel

Quote from: murray dickinson on August 04, 2025, 09:00:49 PMIf they have the same orientation bounding box dimensions might be easier to recognise.

That's one of the problems Murray, they are often on 6 or more different planes and orientations. 'Select by Similar/Shape" works very well when they're on the same plane.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

nikkipollard

 I managed to get this to work. The problem is it takes a long long time because it needs to calculate each volume. Anyone who is a programmer - please weigh in here.
The AI solution confused me, and the macro recorder
So I came up with my own solution which is similar but not quite.

Select the graphics you want to sort and run the script.
The attached document is a pdf of the code colour coded. Because that makes it easier to read.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

PCSteel

Thanks for all the trouble you have gone to Nikki.
I copy and pasted the contents of the PDF into the macro recorder, selected the objects in the drawing I wanted to check and hit the play button. I don't know if I have done something wrong but I get an error message.
You cannot view this attachment.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

#23
I wasn't able to Copy the text in the PDF without also copying the Line numbers.  Which I know isn't what is intended nor would work in TC MacroRecorder if I Pasted that into it (I assume).
  So I worked through Excel to eliminate the Line numbers.  Copied/Pasted that into TC MacroRecorder.  Selected a bunch of objects, ran the script.
Error Message returned:

  You cannot view this attachment.
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)

PCSteel

Yeah, I wondered about the numbers too but knowing as much as I do about this stuff, I used it as it was. Thanks for looking Alvin.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

nikkipollard

#25
 
Quote from: Alvin Gregorio on August 05, 2025, 06:33:09 PMI wasn't able to Copy the text in the PDF without also copying the Line numbers.  Which I know isn't what is intended nor would work in TC MacroRecorder if I Pasted that into it (I assume).
  So I worked through Excel to eliminate the Line numbers.  Copied/Pasted that into TC MacroRecorder.  Selected a bunch of objects, ran the script.
Error Message returned:

  You cannot view this attachment.
Ha Ha I was trying to force you to read it Alvin. You can always remove the numbers in notepad or notepad++.
They are Line numbers. It makes it easy to find errors when the script doesn't work.
I have attached an updated version which changes the name of the graphic as well as listing the graphic Ids.
You can use that name and query by info to find all the Graphics with the same volume easily.
So refine the selected Graphics - Before running the script.

Option Explicit
'====================================================================
   '# DESCRIPTION
   'sorts dumb solids by volume
   'changes the name of the graphic - So you can select by query
   ' lists the volume and graphic ids for each volume at 0,0,0 on the drawing
   ' note the algorythm for the volume hasn't been tested on complex shapes with holes in them
   'This takes very long
'=====================================================================

Call Main

Code deleted


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

PCSteel

By George I think you've got it!  ;D
It is slow but I'll give it some test runs and see if I can work with it. Thanks so much Nikki you must have spent a lot of time on this - very clever.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

#27
I got an SEH Handler Crash when I ran it on about 8 objects :'(
============
EDIT: Restarted TC.  Ran the script again, this time first Saving it as a .tcr in MR.  Worked.

Quote from: nikkipollard on August 05, 2025, 10:04:30 PMYou can use that name and query by info to find all the Graphics with the same volume easily.
What is the query (text string supposed to be)?
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 August 06, 2025, 04:15:04 AMI got an SEH Handler Crash when I ran it on about 8 objects :'(
============
EDIT: Restarted TC.  Ran the script again, this time first Saving it as a .tcr in MR.  Worked.

Quote from: nikkipollard on August 05, 2025, 10:04:30 PMYou can use that name and query by info to find all the Graphics with the same volume easily.
What is the query (text string supposed to be)?
It's ctrl+Q for select by query
'Info'='volType2' (whichever graphic you are looking for)
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

#29
Quote from: PCSteel on August 05, 2025, 11:25:14 PMBy George I think you've got it!  ;D
It is slow but I'll give it some test runs and see if I can work with it. Thanks so much Nikki you must have spent a lot of time on this - very clever.
Not clever, I enjoy problem solving
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

#30
I realised something. I converted the mm cubed to metres cubed, and rounded the result off.
If the graphics are really really small they won't get sorted, because the volume will be zero for all of them.
And if you work in other units you will need to adjust that.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: nikkipollard on August 06, 2025, 06:02:07 AMI enjoy problem solving
I think that's the same reason many of us keep checking in here.
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)

PCSteel

Quote from: nikkipollard on August 06, 2025, 09:26:05 AMI realised something. I converted the mm cubed to metres cubed, and rounded the result off.
If the graphics are really really small they won't get sorted, because the volume will be zero for all of them.
And if you work in other units you will need to adjust that.

Yeah Nikki that is causing some problems, mm³ would be the go and it wouldn't matter if it was rounded to whole units. I thought I might have been able to find that part of the code and change it but I should have known better.  :-[
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

#33
Quote from: PCSteel on August 06, 2025, 11:04:45 PMYeah Nikki that is causing some problems, mm³ would be the go and it wouldn't matter if it was rounded to whole units. I thought I might have been able to find that part of the code and change it but I should have known better.  :-[
Isn't it Line 77 and/or Line 134 ?
____
No way I would have known it needs to be spelled metres rather than meters.  We spell it meters, over here.
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

#34

I




Option Explicit
'====================================================================
   '# DESCRIPTION
   'sorts dumb solids by volume
   'changes the name of the graphic - So you can select by query
   ' lists the volume and graphic ids for each volume at 0,0,0 on the drawing
   ' note the algorythm for the area hasn't been tested on complex shapes with holes in them
   'This takes very long
'=====================================================================

Code deleted to avoid confusion


I changed it.
It was in the function called CalculateVolume Right at the end.
Instead of Dividing by 1000000000 and rounding to the nearest 4. It is rounding to the nearest mm.

I was thinking about it at work today, If you have graphics with a lot of  facets(lots of facets = slow ), but you know how many facets the graphics you are looking for has we can refine the search within the script so that it only compares the volume of graphics with a certain amount of facets.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

PCSteel

Thanks Nikki, I thought it was probably that line but I changed too much of it. I'll do some more testing today while it's still quiet around here.  ;D
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

nikkipollard

#36
No Problem.
I am still trying to see if I can make it faster.
And to learn from your AI script.
This is the latest test
I tested it on about 106 very simple exploded boxes - (rotated different angles with varying sizes)
It took about a minute to run the script.
I did add a custom property to each graphic - so that you can use the Report tool to extract the volumes (and quantities) using the Database. (You will need to Regenerate the database, after running the script. Tools,Database,Regenerate.)



Option Explicit
'====================================================================
   '# DESCRIPTION
   'sorts dumb solids by volume
   'changes the name of the graphic - So you can select by query
   ' lists the volume and graphic ids for each volume at 0,0,0 on the drawing
   ' note the algorithm for the area hasn't been tested on complex shapes with holes in them
   '
'=====================================================================

Call Main

'_______________________________________________________________________________
Sub Main
     
Dim obj
Dim volumeDict
Set volumeDict = CreateObject("Scripting.Dictionary")

   If Selection.Count = 0 Then
     MsgBox "Please Select Graphics First"
     Exit Sub
   End If
Dim k,i
k = 0
Dim gfx : Set gfx = Selection(0)
Dim IdsList   '

' Loop through the selected graphics in the drawing
For Each obj In Selection
    ' Check if the Graphic object is an ACIS solid or a Surface
   
    If obj.Type = "TCW60ACISSOLID" or obj.Type = "SURFACE" Then
        ' Calculate the volume of the solid or surface object - Note the graphics do need to be dumb solids or surfaces
        Dim volume
        volume = CalculateVolume(obj)
        ' Check if the volume already exists in the dictionary
     
      If volumeDict.Exists(volume) Then
         ' thare are other graphics with the same Volume as this Graphic
       
          Set IdsList = volumeDict(volume)
          Idslist.add obj.ID
          Set volumeDict(volume)= IdsList
     
       Else
            ' If it doesn't exist, add to the new volume to the dictionary
            ' The Calculated Volume is the Dictionary Key, and the value will be a list of Graphic IDS with that volume.
            'This is the first graphic with that Volume
                   
                  Set IdsList = CreateObject("System.Collections.Arraylist")
                  IdsList.Add obj.ID
                  volumeDict.Add volume,IdsList
      End If
    End If

Next
Dim Words
Words = ""

' Output the results

Dim key
Dim IdsArray

For Each key In volumeDict.Keys
     
     Set IdsList = volumeDict(key)
     
     dim num
     num = IdsList.Count
     dim newName
     newName = "volType" & k
     
     'change the name of the Graphic, to use the name property to find the graphics in the drawing with the same name using a query search
     For i = 0 to num-1
       Dim g
       'Use the Graphic ID to reference the Graphic
       Set g = ActiveDrawing.Graphics.GraphicFromID(IdsList(i))
       g.Name = newName
       'Add a volume property to the Graphic
       AddCustomProperty g,"M_Volume",key
     Next
     
     IdsArray = IdsList.ToArray
     Words = words & vbcrlf & "Volume = " & Key & "mm" & Chr(0179) & vbcrlf & "Count = " & num & vbcrlf & "Graphic IDS = " & Join(IdsArray,";") & vbcrlf
     k= k+1
  Next
'add the results as a text graphic to Turbocad at (0,0,0)
Call ActiveDrawing.Graphics.AddText(words,0,0,0,500)

' Clean up
Set volumeDict = Nothing
Set IdsList = Nothing
Set obj = Nothing

ActiveDrawing.ActiveView.Refresh

End Sub

'*____________________________________________________________________________________
Function CalculateVolume(gfx)
   
    Dim gCopy
    Dim gsurf
    Dim facts
    Dim nods
    Dim fact
    Dim n1,n2,n3
    Dim tvol,tv
    Dim i
    Dim P
    Set P = New PointD
   'make a copy of the graphic
   Set gCopy = gfx.Duplicate
  ' convert the copy to a Surface
    gCopy.Properties.Item("Solid").Value = 0
    'reference a list of facets for the graphic
    Set gsurf = gCopy.Surface
    Set facts = gsurf.facets
   
    tvol = 0.0
 'loop through each facet in the list of facets
    For Each fact In facts
       'List of nodes for the facet
       Set nods = fact.Nodes
       nods.UseWorldCS = True
       Set n1 = P.FromTcNode(nods(0))
             For i  = 1 To nods.Count - 2
               Set n2 = P.FromTcNode(nods(i))
               Set n3 = P.FromTcNode(nods(i + 1))
               tv = SignedVolumeofTriangle(n1, n2, n3)
               tvol = tvol + tv
            Next
    Next
    gcopy.Delete
   
Set gCopy = Nothing
Set gsurf = Nothing
Set facts = Nothing
Set nods = Nothing
Set n1 = Nothing
Set n2 = Nothing
Set n3 = Nothing

CalculateVolume = Round(tvol)           'mm cubed

End Function


'***************************************************************************************************************

Function SignedVolumeofTriangle(ByVal N1, ByVal N2, ByVal N3)
    Dim d
    d = 1 / 6 * (N1.X * (N2.Y * N3.Z - N3.Y * N2.Z) - N1.Y * (N2.X * N3.Z - N3.X * N2.Z) + N1.Z * (N2.X * N3.Y - N3.X * N2.Y))
   SignedVolumeofTriangle = d
End Function
'*****************************************************************************************

 Sub AddCustomProperty(gf,PName,PValue)
'creates a custom property - only if the property doesn't Exist
On Error Resume Next
Dim ix : Set ix = gf.Properties.Item(PName).Value
If Err <> 0 Then
'Property doesn't Exist
gf.Properties.Add PName,PValue
End If
Err.Clear

End Sub

'*******************************************************************************************

Class PointD
'Seems to be faster then working with the TC node
Public X
Public Y
Public Z

 Public Default Function Init(x1,y1,z1)
    x = x1
    y = y1
    z = z1
  Set Init = Me
  End Function

Public Function FromTcNode(Node)
Dim P
Set P = (New PointD)(Node.X,Node.Y,Node.Z)
Set FromTcNode = P
End Function

End Class



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

Alvin Gregorio

Quote from: nikkipollard on August 08, 2025, 02:14:34 AMI did add a custom property to each graphic
When I run the script on multiple already-selected objects, then Attach the (3) Custom Properties* in their Custom Properties, then Regenerate, I get the (3) Custom Properties listed, but no Values listed.

Including (after Regenerate) when I run a Detail Report, it is blank— The (3) Properties' Column headings are there, but no Values listed.

*BoM Material, Volume, Weight
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

#38
MMM I wonder if that is not a version problem. It's working for me.
When you open the properties of a Graphic can you see M_Volume property?

(I tried using "Volume" as the property name but I got errors. I presume that somewhere in TC there is a volume property and we can't use that.)


But From your description it sounds like you are doing something wrong.
The script attaches the custom property. You don't need  to manually add a custom property. That would defeat the purpose of adding it via the script.
For some reason, the Database can only see the Volume after regeneration.





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

nikkipollard

#39
Oh Alvin I think you have solved a mystery.

There is a tool for calculating the mass properties which Alvin mentioned earlier.
Tools| Inquiry | Mass properties
If you run that tool on all your graphics - it adds a "Mass" and a "Volume" custom property to the graphic properties collection.
You can then run a script or use the Database tools to extract the data.
You should be able to use ctrl+Q to select similar objects based on the volume custom property

Here is a simple script similar to the AI script. with a select similar option.

The problem with the BOM method is selecting hundreds of Graphics one at a time is more time consuming then waiting for the script to calculate the Volume. At least you can make coffee while you wait for the script to run.



Option Explicit

'====================================================================
   '# DESCRIPTION
'Generate mass properties via tools,inquiry,Mass properties before running the script
' select the graphics and Run the script
'=====================================================================

dim todo

todo = InputBox("What to do?" & vbCrlf & "1 Extract Volume Data" & vbCrlf & "2 Select Similar by volume","",1)

 Select Case todo
 Case 1
Call Main
 Case 2
Call SelectSimilar
 Case Else

 End Select




'_______________________________________________________________________________
Sub Main
   
Dim g
Dim volumeDict
Dim Idslist
Set volumeDict = CreateObject("Scripting.Dictionary")

   If Selection.Count = 0 Then
     MsgBox "Please Select Graphics First, remember to generate the mass properties before running the script"
     Exit Sub
   End If
 
 On Error Resume Next
 dim volume

For Each g In Selection
    If g.Type = "TCW60ACISSOLID" Then
    volume = g.Properties.Item("Volume").Value

    If volumeDict.Exists(volume) Then
              Set IdsList = volumeDict(volume)
              Idslist.add g.ID
              Set volumeDict(volume)= IdsList

    Else
             
      Set IdsList = CreateObject("System.Collections.Arraylist")
                      IdsList.Add g.ID
                      volumeDict.Add volume,IdsList
    End If
   End If
Next
   
   Dim Words
Words = ""

'Output the results

Dim key
Dim IdsArray

For Each key In volumeDict.Keys
     
     Set IdsList = volumeDict(key)
      dim num
     num = IdsList.Count
     dim newName
     newName = "volType" & k
     
     'change the name of the Graphic, to use the name property to find the graphics in the drawing with the same name using a query search
     For i = 0 to num-1
     
      ' Use the Graphic ID to reference the Graphic
       Set g = ActiveDrawing.Graphics.GraphicFromID(IdsList(i))
       g.Name = newName
   
     Next
     
     IdsArray = IdsList.ToArray
     Words = words & vbcrlf & "Volume = " & Key & vbcrlf & "Count = " & num & vbcrlf & "Graphic IDS = " & Join(IdsArray,";") & vbcrlf
     k = k + 1
  Next
'add the results as a text graphic to Turbocad at (0,0,0)
Call ActiveDrawing.Graphics.AddText(words,0,0,0,500)

'''Clean up
Set volumeDict = Nothing
Set IdsList = Nothing
Set g = Nothing


ActiveDrawing.ActiveView.Refresh

End Sub

'________________________________________________________________________________

Sub SelectSimilar()

 If Selection.Count = 0 Then
MsgBox "Please Select one Graphic First"
Exit Sub
 End If

Dim gfx : Set gfx = Selection(0)
dim Volume,vol2
Volume = GetVolume(gfx)


If Volume <> ""  Then
Selection.UnSelect

For each gfx in ActiveDrawing.Graphics

vol2 = GetVolume(gfx)

If vol2 = Volume then gfx.Select

Next

End If
End Sub
'**************************************

Function GetVolume(gfx)

 On Error Resume Next
  Dim ix : ix = gfx.Properties.Item("Volume").Value
 If Err <> 0 Then
 
  GetVolume = ""
 
  Else
  GetVolume = ix
 
  End IF
 
  Err.Clear
 
End Function



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

nikkipollard

Quote from: Alvin Gregorio on August 08, 2025, 04:40:05 AM
Quote from: nikkipollard on August 08, 2025, 02:14:34 AMI did add a custom property to each graphic
When I run the script on multiple already-selected objects, then Attach the (3) Custom Properties* in their Custom Properties, then Regenerate, I get the (3) Custom Properties listed, but no Values listed.

Including (after Regenerate) when I run a Detail Report, it is blank— The (3) Properties' Column headings are there, but no Values listed.

*BoM Material, Volume, Weight


I think that might be a bug with the BOM tools. It happened to me when I was testing the BOM tool.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Dean

#41
Quote from: nikkipollard on August 08, 2025, 08:40:35 AM
Quote from: Alvin Gregorio on August 08, 2025, 04:40:05 AM
Quote from: nikkipollard on August 08, 2025, 02:14:34 AMI did add a custom property to each graphic
When I run the script on multiple already-selected objects, then Attach the (3) Custom Properties* in their Custom Properties, then Regenerate, I get the (3) Custom Properties listed, but no Values listed.

Including (after Regenerate) when I run a Detail Report, it is blank— The (3) Properties' Column headings are there, but no Values listed.

*BoM Material, Volume, Weight


I think that might be a bug with the BOM tools. It happened to me when I was testing the BOM tool.

I don't see a bug with the bom tools in 2025.
:) Good work with the script Nikki.
:) Option 2 worked good.
Option 1, I needed to make two changes in order for it to actually write the "volume" text in MSpace.
My objects were medium size objects drawn in inches.
 :) Thanks for taking the time to write and share the script...You cannot view this attachment.
"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

PCSteel

Wait, wait, I needed some sleep and now I'm a full day behind.  ;D Go and get some rest and let me attempt to catch up. Thanks all.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

PCSteel

Quote from: nikkipollard on August 08, 2025, 02:14:34 AMNo Problem.
I am still trying to see if I can make it faster.
And to learn from your AI script.
This is the latest test
I tested it on about 106 very simple exploded boxes - (rotated different angles with varying sizes)
It took about a minute to run the script.
I did add a custom property to each graphic - so that you can use the Report tool to extract the volumes (and quantities) using the Database. (You will need to Regenerate the database, after running the script. Tools,Database,Regenerate.)



Option Explicit
'====================================================================
   '# DESCRIPTION
   'sorts dumb solids by volume
   'changes the name of the graphic - So you can select by query
   ' lists the volume and graphic ids for each volume at 0,0,0 on the drawing
   ' note the algorithm for the area hasn't been tested on complex shapes with holes in them
   'This takes very long
'=====================================================================

Call Main

'_______________________________________________________________________________
Sub Main
    
Dim obj
Dim volumeDict
Set volumeDict = CreateObject("Scripting.Dictionary")

   If Selection.Count = 0 Then
     MsgBox "Please Select Graphics First"
     Exit Sub
   End If
Dim k,i
k = 0
Dim gfx : Set gfx = Selection(0)
Dim IdsList   '

' Loop through the selected graphics in the drawing
For Each obj In Selection
    ' Check if the Graphic object is an ACIS solid or a Surface
   
    If obj.Type = "TCW60ACISSOLID" or obj.Type = "SURFACE" Then
        ' Calculate the volume of the solid or surface object - Note the graphics do need to be dumb solids or surfaces
        Dim volume
        volume = CalculateVolume(obj)
        ' Check if the volume already exists in the dictionary
     
      If volumeDict.Exists(volume) Then
         ' thare are other graphics with the same Volume as this Graphic
       
          Set IdsList = volumeDict(volume)
          Idslist.add obj.ID
          Set volumeDict(volume)= IdsList
     
       Else
            ' If it doesn't exist, add to the new volume to the dictionary
            ' The Calculated Volume is the Dictionary Key, and the value will be a list of Graphic IDS with that volume.
            'This is the first graphic with that Volume
                  
                  Set IdsList = CreateObject("System.Collections.Arraylist")
                  IdsList.Add obj.ID
                  volumeDict.Add volume,IdsList
      End If
    End If

Next
Dim Words
Words = ""

' Output the results

Dim key
Dim IdsArray

For Each key In volumeDict.Keys
     
     Set IdsList = volumeDict(key)
    
     dim num
     num = IdsList.Count
     dim newName
     newName = "volType" & k
    
     'change the name of the Graphic, to use the name property to find the graphics in the drawing with the same name using a query search
     For i = 0 to num-1
       Dim g
       'Use the Graphic ID to reference the Graphic
       Set g = ActiveDrawing.Graphics.GraphicFromID(IdsList(i))
       g.Name = newName
       'Add a volume property to the Graphic
       AddCustomProperty g,"M_Volume",key
     Next
    
     IdsArray = IdsList.ToArray
     Words = words & vbcrlf & "Volume = " & Key & "mm" & Chr(0179) & vbcrlf & "Count = " & num & vbcrlf & "Graphic IDS = " & Join(IdsArray,";") & vbcrlf
     k= k+1
  Next
'add the results as a text graphic to Turbocad at (0,0,0)
Call ActiveDrawing.Graphics.AddText(words,0,0,0,500)

' Clean up
Set volumeDict = Nothing
Set IdsList = Nothing
Set obj = Nothing

ActiveDrawing.ActiveView.Refresh

End Sub

'*____________________________________________________________________________________
Function CalculateVolume(gfx)
   
    Dim gCopy
    Dim gsurf
    Dim facts
    Dim nods
    Dim fact
    Dim n1,n2,n3
    Dim tvol,tv
    Dim i
    Dim P
    Set P = New PointD
   'make a copy of the graphic
   Set gCopy = gfx.Duplicate
  ' convert the copy to a Surface
    gCopy.Properties.Item("Solid").Value = 0
    'reference a list of facets for the graphic
    Set gsurf = gCopy.Surface
    Set facts = gsurf.facets
   
    tvol = 0.0
 'loop through each facet in the list of facets
    For Each fact In facts
       'List of nodes for the facet
       Set nods = fact.Nodes
       nods.UseWorldCS = True
       Set n1 = P.FromTcNode(nods(0))
             For i  = 1 To nods.Count - 2
               Set n2 = P.FromTcNode(nods(i))
               Set n3 = P.FromTcNode(nods(i + 1))
               tv = SignedVolumeofTriangle(n1, n2, n3)
               tvol = tvol + tv
            Next
    Next
    gcopy.Delete
   
Set gCopy = Nothing
Set gsurf = Nothing
Set facts = Nothing
Set nods = Nothing
Set n1 = Nothing
Set n2 = Nothing
Set n3 = Nothing

CalculateVolume = Round(tvol)           'mm cubed

End Function


'***************************************************************************************************************

Function SignedVolumeofTriangle(ByVal N1, ByVal N2, ByVal N3)
    Dim d
    d = 1 / 6 * (N1.X * (N2.Y * N3.Z - N3.Y * N2.Z) - N1.Y * (N2.X * N3.Z - N3.X * N2.Z) + N1.Z * (N2.X * N3.Y - N3.X * N2.Y))
   SignedVolumeofTriangle = d
End Function
'*****************************************************************************************

 Sub AddCustomProperty(gf,PName,PValue)
'creates a custom property - only if the property doesn't Exist
On Error Resume Next
Dim ix : Set ix = gf.Properties.Item(PName).Value
If Err <> 0 Then
'Property doesn't Exist
gf.Properties.Add PName,PValue
End If
Err.Clear

End Sub

'*******************************************************************************************

Class PointD

Public X
Public Y
Public Z

 Public Default Function Init(x1,y1,z1)
    x = x1
    y = y1
    z = z1
  Set Init = Me
  End Function

Public Function FromTcNode(Node)
Dim P
Set P = (New PointD)(Node.X,Node.Y,Node.Z)
Set FromTcNode = P
End Function

End Class





Ok, make that two days!  ::)
This works very well Nikki and the attribute attachments make it very easy to find/select the different objects. I've been using a small collection of objects to do my testing and it takes around 20 minutes to run so I would need to do batches on the full size projects. Thanks again.


Quote from: nikkipollard on August 08, 2025, 06:08:52 AMOh Alvin I think you have solved a mystery.

There is a tool for calculating the mass properties which Alvin mentioned earlier.
Tools| Inquiry | Mass properties
If you run that tool on all your graphics - it adds a "Mass" and a "Volume" custom property to the graphic properties collection.
You can then run a script or use the Database tools to extract the data.
You should be able to use ctrl+Q to select similar objects based on the volume custom property

Here is a simple script similar to the AI script. with a select similar option.

The problem with the BOM method is selecting hundreds of Graphics one at a time is more time consuming then waiting for the script to calculate the Volume. At least you can make coffee while you wait for the script to run.



Option Explicit

'====================================================================
   '# DESCRIPTION
'Generate mass properties via tools,inquiry,Mass properties before running the script
' select the graphics and Run the script
'=====================================================================

dim todo

todo = InputBox("What to do?" & vbCrlf & "1 Extract Volume Data" & vbCrlf & "2 Select Similar by volume","",1)

 Select Case todo
 Case 1
Call Main
 Case 2
Call SelectSimilar
 Case Else

 End Select




'_______________________________________________________________________________
Sub Main
  
Dim g
Dim volumeDict
Dim Idslist
Set volumeDict = CreateObject("Scripting.Dictionary")

   If Selection.Count = 0 Then
     MsgBox "Please Select Graphics First, remember to generate the mass properties before running the script"
     Exit Sub
   End If
 
 On Error Resume Next
 dim volume

For Each g In Selection
    If g.Type = "TCW60ACISSOLID" Then
    volume = g.Properties.Item("Volume").Value

    If volumeDict.Exists(volume) Then
              Set IdsList = volumeDict(volume)
              Idslist.add g.ID
              Set volumeDict(volume)= IdsList

    Else
            
      Set IdsList = CreateObject("System.Collections.Arraylist")
                      IdsList.Add g.ID
                      volumeDict.Add volume,IdsList
    End If
   End If
Next
  
   Dim Words
Words = ""

'Output the results

Dim key
Dim IdsArray

For Each key In volumeDict.Keys
     
     Set IdsList = volumeDict(key)
      dim num
     num = IdsList.Count
     dim newName
     newName = "volType" & k
    
     'change the name of the Graphic, to use the name property to find the graphics in the drawing with the same name using a query search
     For i = 0 to num-1
     
      ' Use the Graphic ID to reference the Graphic
       Set g = ActiveDrawing.Graphics.GraphicFromID(IdsList(i))
       g.Name = newName
   
     Next
    
     IdsArray = IdsList.ToArray
     Words = words & vbcrlf & "Volume = " & Key & vbcrlf & "Count = " & num & vbcrlf & "Graphic IDS = " & Join(IdsArray,";") & vbcrlf
     k = k + 1
  Next
'add the results as a text graphic to Turbocad at (0,0,0)
Call ActiveDrawing.Graphics.AddText(words,0,0,0,500)

'''Clean up
Set volumeDict = Nothing
Set IdsList = Nothing
Set g = Nothing


ActiveDrawing.ActiveView.Refresh

End Sub

'________________________________________________________________________________

Sub SelectSimilar()

 If Selection.Count = 0 Then
     MsgBox "Please Select one Graphic First"
     Exit Sub
 End If

Dim gfx : Set gfx = Selection(0)
dim Volume,vol2
Volume = GetVolume(gfx)


If Volume <> ""  Then
Selection.UnSelect

For each gfx in ActiveDrawing.Graphics

vol2 = GetVolume(gfx)

If vol2 = Volume then gfx.Select

Next

End If
End Sub
'**************************************

Function GetVolume(gfx)

 On Error Resume Next
  Dim ix : ix = gfx.Properties.Item("Volume").Value
 If Err <> 0 Then
 
  GetVolume = ""
 
  Else
  GetVolume = ix
 
  End IF
 
  Err.Clear
 
End Function




This would be excellent IF we could use the same selection methods as we can use with every other tool, rather than having to select one at a time.  :( I didn't understand what Alvin was referring to in that post (7) as I hadn't seen it on my system. I had to do a find to locate it and put it on a menu. I'll be doing more testing on the real thing.

Thanks so much for all you have put into this.
I'll attach the file that I've been using to do my comparisons.

You cannot view this attachment.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

PCSteel

Quote from: Alvin Gregorio on August 03, 2025, 05:56:26 PMI'm starting with Mass Properties  (within the Measurement Info, for me)
Then creating Custom Properties from that.*
BOM Report is one way to go.  Once into Excel, Object IDs can be used in a Select_by_Query.  Some formatting or something can make populating the Query fairly quick and simple.

Select_by_Query method:
  I tried a >= AND <= , but that didn't work.  Exact volume—  that is, just the =—  works in Select by Query.  But what's the odds that out of the hundreds of objects, John only wants to select those with the exact same volume.

*First issue I am running into— John said "hundreds" of objects.  Dang Mass Properties doesn't have a drag-window option; we have to hold the Shift-key down and select the objects one at a time.  Not good for "hundreds" of objects.


I must apologise Alvin as I didn't understand this at first, thinking you were referring to the 'volume' measure tool.
I have never seen any reference to this tool and it took way too long for me to wake up and go looking for it. Anyway I eventually found it and thanks for pointing it out. As you say, it's a shame a window can't be used for selection because then it would be brilliant.
In conjunction with the BOM (which I had to learn also) and using it to select and check just the likely suspects could be as good as it gets. I'll be doing more testing with this.
Thanks again.
John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

I think if Nikki can figure out those great scripts that call on certain TurboCAD functions, she can probably figure out how to add a Drag Window or Select All operation to the Mass Properties Tool.
  I worked on it some last week with my MS Copilot last weekend, but other priorities rose to the top before we achieved it.  It's still in my (obsessive) mind.

I believe "Mass Properties" was introduced in the v2020 release.  Nikki stated here that she found it in her v2021.
  If we can get that Tool to select many-multiple objects or Select All, all at once, we've got a good quick way to find entities with an exact Volume or a Volume within a range.  A script that runs Mass Properties on currently Selected objects would work also.
  I'm confident we can figure this out.  It's just a computer.
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)

PCSteel

Quote from: Alvin Gregorio on August 11, 2025, 01:42:00 AMI think if Nikki can figure out those great scripts that call on certain TurboCAD functions, she can probably figure out how to add a Drag Window or Select All operation to the Mass Properties Tool.

We can only hope!  ;)

Quote from: Alvin Gregorio on August 11, 2025, 01:42:00 AMI worked on it some last week with my MS Copilot last weekend, but other priorities rose to the top before we achieved it.  It's still in my (obsessive) mind.

And thanks again for that. You pointed us to the Mass Properties Tool, which I think is very useful but could be improved. It would be a game changer if it shared the same selection options as other tools.

John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

nikkipollard

The SDK doesn't give access to all Turbocad tools. And it was last updated in about 2010.

I am afraid the script in Reply 40 is the best I can do. It is faster then the first one. I ran it on a drawing with 240+ Graphics, it took about 1 And a half minutes, to run - The volumes did match the selection info palette.
The script adds a custom property as well as assigning the same name to graphics with the same volume.
So After running the script once in a drawing use CTRL + Q and use the Info property found in Common properties or the M_Volume custom property to find graphics quickly.

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

PCSteel

Quote from: nikkipollard on August 11, 2025, 08:12:38 AMThe SDK doesn't give access to all Turbocad tools. And it was last updated in about 2010.

I am afraid the script in Reply 40 is the best I can do. It is faster then the first one. I ran it on a drawing with 240+ Graphics, it took about 1 And a half minutes, to run - The volumes did match the selection info palette.
The script adds a custom property as well as assigning the same name to graphics with the same volume.
So After running the script once in a drawing use CTRL + Q and use the Info property found in Common properties or the M_Volume custom property to find graphics quickly.

I think you mean reply 39 Nikki and I thought that was the one I'd been using but decided I should check, only to find I've been using the older one.  :-[
Using the correct script only takes a few seconds on my test file.

Thanks for this and thank you for being so patient with me while I bumble my way through it.

I'm now excited and will trial this on some real files.

Thank you, thank you!


John@PC Steel

Core i7-6700 CPU
16GB Ram
64 Bit
Windows 10 Home
TurboCAD 2015 Pro Platinum 64 bit Build 90.0
TurboCAD 2023 Platinum 64 bit Build 63.3

Alvin Gregorio

Quote from: PCSteel on August 11, 2025, 03:54:35 PMI think you mean reply 39 Nikki
It depends on what we have set for "Show most recent posts at the top in topic view" in (our)Profile/Look_and_layout
   That can cause it to differ by one count between Forum members.
      Which kinda sucks for effective efficient communication.
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)