News:

When posting a problem be sure to include which version you are using.  Give as much information as possible.  If the problem is with a specific file be sure to attache it to your post.

Main Menu

VBScript to replace selected objects with circles of set diameter

Started by pvr, November 12, 2009, 01:59:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pvr

Hi

This is a small utility to change selected objects into circles. The diameter if each replacing circle is read from the object's X size it is replacing.

I recently had to do machine toolpaths from a 3rd party's dxf where all the holes to be drilled was polylines (about 60 holes). I wrote this utility to make the task easier for me. The polyline circles was in 16 segments and the cnc router would not have cut round circles for the larger holes.

The script works in the TC macro recorder

Feel free to use, change or comment.



[attachment deleted by admin]

marc_256

Hi pvr,

I never used this soft routines.

How can I use this, how must I place this in TC16.1 ?
Must I place it in a subdir of TC ?

Thanks,
Marc
Deluxe / TC v9 pro / TC v16.2 platinum / ... - AnimationLab 4.4 - MontageCenter 1.0 - CAM plug-in for v 16

- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...

pvr

Hi Marc

Download and unzip the file. You can unzip to any directory. Then under TC's View menu select MacroRecorder Palette. The Macro recorder (MR) will open. Now on the MR toolbar select open file button and go to the directory where you have unzipped this file and open it. Now select the objects on your drawing you want to change to circles and click the run button on the MR toolbar. The objects will be changed to circles. The objects should not be single lines as the diameter is read from the itmes x size. The diameter can be overridden by typing a diameter size, but then all circles will have the same size. This only works under TC Professional version and was made with TC v15 but should work with all versions from version 7.

Hope it helped and good luck.

Cheers

Piet

[attachment deleted by admin]

marc_256

Deluxe / TC v9 pro / TC v16.2 platinum / ... - AnimationLab 4.4 - MontageCenter 1.0 - CAM plug-in for v 16

- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...

sagreen83

Seems like the script for this was deleted. Anyone have an example, or the original script?

Scott...

Quote from: pvr on November 12, 2009, 01:59:43 AM
Hi

This is a small utility to change selected objects into circles. The diameter if each replacing circle is read from the object's X size it is replacing.

I recently had to do machine toolpaths from a 3rd party's dxf where all the holes to be drilled was polylines (about 60 holes). I wrote this utility to make the task easier for me. The polyline circles was in 16 segments and the cnc router would not have cut round circles for the larger holes.

The script works in the TC macro recorder

Feel free to use, change or comment.



[attachment deleted by admin]

pvr

Hey Scott,

Hope this helps :)

----------------------------------
' Obj2Circle.tcr
' Replace selected objects with circles of set diameter'
' To be loaded into TurboCAD's MacroRecorder and run from there

option explicit
Dim TCDwg, TCGrs
Dim Dia

Sub CreateCircle(Target)
Dim NewCircle

Set NewCircle = TCGrs.AddArcCenterAndPoint(0, 0, 0, Dia/2, 0, 0, 0, 0)
   
   NewCircle.MoveAbsolute Target.ReferencePoint.X, Target.ReferencePoint.Y, Target.ReferencePoint.Z
   NewCircle.Properties("PenColor") = RGB(255, 128, 64)   
End Sub

Sub Main
Dim TCSel, Target, NewCircle, BBox

Set TCDwg = ActiveDrawing
Set TCGrs = TCDwg.Graphics
Set TCSel = ActiveDrawing.Selection

   If TCSel.Count < 1 then
     MsgBox "Select some items first!"
     Exit Sub
   End If

   For Each Target in TCSel   
      Set BBox= Target.CalcBoundingBox
      Dia = BBox.Max.X - BBox.Min.X
      CreateCircle(Target)
      Target.Delete
      TCDwg.ActiveView.Refresh
   Next

   ActiveDrawing.Selection.Unselect
   TCDwg.ActiveView.Refresh
End Sub

Main

------------------------------

Copy all between the two ----------------- lines and save to a .tcr file



Piet

Jeff_in_90620

Quote from: pvr on June 04, 2019, 12:13:36 AM
Hey Scott,

Hope this helps :)

----------------------------------
' Obj2Circle.tcr
' Replace selected objects with circles of set diameter'
' To be loaded into TurboCAD's MacroRecorder and run from there

Out of curiosity, which version can use this script?  From what I have read, more recent versions cannot use Visual Basic anymore.


Jeff
Jeff

TC 2026 Pro Platinum plus 2015->2024 (most with LightWorks & RedSDK) & V21
System: AMD Ryzen 9 7950X, MSI Mag X670E Tomahawk WiFi, 64GB RAM @ 4.80GHz, ARC A770 w/16GB, 3 x Samsung NVMe 990 (1TB), Windows 11 Pro (64-bit)

Torfinn

Macro recorder is a "leftover" in TC and still work, maybe they have work on it resently, i think to remember a post from Shaheryar about this.
The script above here work i v 2018 at least, i dont have 2019 open at the moment, but guess it will work there aswell

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

sagreen83

Thanks so much for the file. After you sent it I've used it thousands of times!

Couple questions:

1) The macro sets the color of the circle thats created. Any idea how to set the color to "By Layer"?

2) Do you know how to access the "Play Script" button with a hot key mapping?

Thanks for your help!
Scott...


Quote from: pvr on June 04, 2019, 12:13:36 AM
Hey Scott,

Hope this helps :)

----------------------------------
' Obj2Circle.tcr
' Replace selected objects with circles of set diameter'
' To be loaded into TurboCAD's MacroRecorder and run from there

option explicit
Dim TCDwg, TCGrs
Dim Dia

Sub CreateCircle(Target)
Dim NewCircle

Set NewCircle = TCGrs.AddArcCenterAndPoint(0, 0, 0, Dia/2, 0, 0, 0, 0)
   
   NewCircle.MoveAbsolute Target.ReferencePoint.X, Target.ReferencePoint.Y, Target.ReferencePoint.Z
   NewCircle.Properties("PenColor") = RGB(255, 128, 64)   
End Sub

Sub Main
Dim TCSel, Target, NewCircle, BBox

Set TCDwg = ActiveDrawing
Set TCGrs = TCDwg.Graphics
Set TCSel = ActiveDrawing.Selection

   If TCSel.Count < 1 then
     MsgBox "Select some items first!"
     Exit Sub
   End If

   For Each Target in TCSel   
      Set BBox= Target.CalcBoundingBox
      Dia = BBox.Max.X - BBox.Min.X
      CreateCircle(Target)
      Target.Delete
      TCDwg.ActiveView.Refresh
   Next

   ActiveDrawing.Selection.Unselect
   TCDwg.ActiveView.Refresh
End Sub

Main

------------------------------

Copy all between the two ----------------- lines and save to a .tcr file



Piet

John R

re: ...1) The macro sets the color of the circle that's created. Any idea how to set the color to "By Layer"?

Use -3 (minus three) for "By Layer".

Original:
NewCircle.Properties("PenColor") = RGB(255, 128, 64)   
New:

NewCircle.Properties("PenColor") = -3

-3 = By Layer
-4 = By Block
(edited for incorrect number for Block)
John R.

V17—V21, 2015—2025
Designer, Deluxe, (Basic, Expert, Professional), Platinum
RedSDK enabled
Windows 11 Pro (25H2), 64-bit

AussieBloke

Hey John where or how did you get those references from, -3 and -5 ?

John R

Quote from: Darryl W on August 10, 2019, 03:08:24 PM
Hey John where or how did you get those references from, -3 and -5 ?

I botched that up. I checked an olde list and this is what I had: 0=Black, -3=By Layer, -4=By Block, -5=By Pen
"-5" is normally used in the "Brush Color" Property, so that a hatch will be the same color as its parent.

Draw 3 lines. In the Line Color section of the Property toolbar, set one to By Layer, another to By Block and the third to White (TurboCAD True Color).
Select the "By Layer" line and click on the "Copy" icon in the Selection Info palette.
This will open a webpage in your browser showing all the properties of the Line.
The "Line Color" entry will show a Value of -3.

If you do the same with the other two lines, you'll get a Value of -4 and 16777215 (the Decimal number for white).
You can use Excel to generate a Decimal number. On line 68 in Excel I have the RGB numbers (255,255,255) listed in separate columns (F,G,H).
In column "I" I have: =SUM(F68+256*G68+65536*H68)
This generates a number of 16777215.
TurboCAD used to use Decimal numbers long ago before they switched to RGB.

I was trying to figure this out about 15-20 years ago. Here's a TurboCAD Colors list in HTML format that shows the different color formats.
John R.

V17—V21, 2015—2025
Designer, Deluxe, (Basic, Expert, Professional), Platinum
RedSDK enabled
Windows 11 Pro (25H2), 64-bit

nikkipollard

Thanks John. I always use the macro palette to get the code - this will save a lot of time!
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

John R

John R.

V17—V21, 2015—2025
Designer, Deluxe, (Basic, Expert, Professional), Platinum
RedSDK enabled
Windows 11 Pro (25H2), 64-bit

sagreen83

Thanks John, -3 worked perfectly!

Scott...


Quote from: John R on August 10, 2019, 08:48:39 PM
Quote from: Darryl W on August 10, 2019, 03:08:24 PM
Hey John where or how did you get those references from, -3 and -5 ?

I botched that up. I checked an olde list and this is what I had: 0=Black, -3=By Layer, -4=By Block, -5=By Pen
"-5" is normally used in the "Brush Color" Property, so that a hatch will be the same color as its parent.

Draw 3 lines. In the Line Color section of the Property toolbar, set one to By Layer, another to By Block and the third to White (TurboCAD True Color).
Select the "By Layer" line and click on the "Copy" icon in the Selection Info palette.
This will open a webpage in your browser showing all the properties of the Line.
The "Line Color" entry will show a Value of -3.

If you do the same with the other two lines, you'll get a Value of -4 and 16777215 (the Decimal number for white).
You can use Excel to generate a Decimal number. On line 68 in Excel I have the RGB numbers (255,255,255) listed in separate columns (F,G,H).
In column "I" I have: =SUM(F68+256*G68+65536*H68)
This generates a number of 16777215.
TurboCAD used to use Decimal numbers long ago before they switched to RGB.

I was trying to figure this out about 15-20 years ago. Here's a TurboCAD Colors list in HTML format that shows the different color formats.

John R

John R.

V17—V21, 2015—2025
Designer, Deluxe, (Basic, Expert, Professional), Platinum
RedSDK enabled
Windows 11 Pro (25H2), 64-bit

sauerkraut2018

Hi,

I found this script. It works great.

Can the script be rewritten in such a way that it does not change the position of the objects but only changes the diameter of the circle?

Thanks in advance for your help.
#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

Andy H

Quote from: sauerkraut2018 on March 22, 2021, 07:05:23 PM
Hi,
I found this script. It works great.
Can the script be rewritten in such a way that it does not change the position of the objects but only changes the diameter of the circle?
Thanks in advance for your help.

It sounds like a workplane issue.  You could try using the 'Place on workplane' to ensure all the objects are on the world workplane, prior to running the script.  calcboundingbox uses world coordinates (I think), which when using 2d in 3d selector mode, may be different to whatever workplane the object was created on. 

sauerkraut2018

Hello Andy,

no, it's not the workplane. All objects are at zero in the Z direction.
For example, I create a circle d = 3.5mm. I copy the circle linearly 10 times. Now I am using "select by query". And run the script. All circles are moved to 0,0,0 and the diameter changes as entered.

Moving the circles should be prevented.
See the line in the script:
"Set NewCircle = TCGrs.AddArcCenterAndPoint (0,0,0, Arc / 2,0,0,0)
I think this line moves the circles and changes the diameter.
#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

nikkipollard

I think Andy is right - It might be a workplane issue,
because the next line on the script moves the circle to the reference point of the "target" graphic.
I wonder if setting the vertices of the graphic to by world before getting the reference point might help?
I am not sure what the syntax is in the macro recorder palette to set  the reference point  but this is what works in VBA



Sub CreateCircle(Target)
Dim NewCircle
Dim rp As IMSIGX.Vertex
Set NewCircle = TCGrs.AddArcCenterAndPoint(0, 0, 0, Dia/2, 0, 0, 0, 0)
   Set rp = Target.ReferencePoint(True)
 
NewCircle.MoveAbsolute  rp.X, rp.Y, rp.Z
   NewCircle.Properties("PenColor") = RGB(255, 128, 64)   
End Sub
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

sauerkraut2018

Hi,

thank you for your contributions. I thought it would work.

Is there another possibility to select many circles (approx. 500 pieces) and to change the diameter (e.g. from 3mm to 6mm) at once? Without losing their position?

P.S. the drawing already exists, an old drawing.

#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

Torfinn

Yes there is, but i don't remember the tread anymore  ::)
John R know how to, i remember that it involved the Edit tool, and he show'd how to back then, less than a year ago i think.
It was a reply in another guy's tread, so maybe possible to find by search.

Torfinn
Edit;
It was easy, just tested in v 2020, use edit tool, select all the circles and just change the size down at Inspector bar, they will all update and not move  ;) :)
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

You can use this script
Instead of using Dia/2  in

Set NewCircle = TCGrs.AddCircleCenterAndPoint(0, 0, 0, Dia/2, 0, 0)

you can use the  new radius .
Isn't there a ruby script that does this?





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

nikkipollard

I am not sure how to convert this to macro syntax but here is an excel VBA version.

Sub ChangeCircleRadius()

Dim TCApp As IMSIGX.Application
Dim TCdraw As IMSIGX.Drawing
Set TCApp = IMSIGX.Application
Set TCdraw = TCApp.ActiveDrawing
Dim sel As IMSIGX.Selection
Set sel = TCdraw.Selection
Dim num As Integer
num = sel.Count
Dim newrad As Double
    newrad = Application.InputBox("New Radius", "", 50)


If num > 0 Then

For Each G In sel

If G.Type = "CIRCLE" Then

    G.Vertices.UseWorldCS = True
  Dim cen As IMSIGX.Vertex
    Set cen = G.Vertices(0)
  Dim newcircle As IMSIGX.Graphic
    Set newcircle = TCdraw.Graphics.AddCircleCenterAndPoint(cen.x, cen.y, cen.Z, cen.x + newrad, cen.y, cen.Z)
    G.Delete
End If
   
    Next
TCdraw.ActiveView.Refresh
TCdraw.Selection.Unselect
Set sel = Nothing

MsgBox "Done"

Else

MsgBox "Please select the Circles first"

End If

Set TCdraw = Nothing
Set TCApp = Nothing


End Sub


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

sauerkraut2018

Hi Torfinn,

yeah, the keyword was "edit tool". It works entirely without a script.

Solution:
First separate all circles on one layer.
Hide all other layers or just make the circles visible
Use the "Edit tool", draw a frame around the circles
Change the radius in the status bar.
Voila, it works

Hello Nikkipollard,

thank you too.

I tried to run the codes and Excel VBA codes.
Unfortunately no success.
It's up to me, there is a lack of know-how on the subject of VBA, scripts and macro recorders.
#-----
Very low knowledge of English - I ask for indulgence - Thanks
Currently installed
TurboCAD Professional 32-bit V.17.2.77.1
TurboCAD 2016 ProPlatinum 64-bit V23.2-61.2 engl.
TurboCAD 2021 Platinum 64-bit V28.0 B.82.3 de.
#-----

Andy H

Quote from: nikkipollard on March 23, 2021, 03:20:11 AM
I am not sure how to convert this to macro syntax but here is an excel VBA version.

Just needs a few tweaks Nikki.

VBS (macro's) don't use the 'AS' to define a variable.
The Sub requires a call to it,  so that it can run.  i.e. after the End Sub, one could just type ChangeCircleRadius.  so that it directs the macro to run the Sub.
G requires a Dim for it.

Macro's are generally run in the active drawing. so don't need the IMSIGX.  One could just type, Dim TCdraw.  Set TCdraw = ActiveDrawing.


nikkipollard

Thank You Andy That is great.
After a lot of tweaks I managed to get it to work.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h