I'm using ChatGPT to try to create a simple macro to switch between fractional and US architectural on a selected dimension (horizontal or vertical). I prefer to not see the feet dimensions for under 12". I know you can turn off the leading 0 but it still leaves the foot mark and the dash which looks worse in my opinion, so I spend a lot of time using the drop down to switch to fractional when needed. A macro set to a hotkey would be extremely useful and quicker but so far ChatGPT is not having an easy time creating a macro. Does anybody have some info that I can use to push ChatGPT into the proper path?
Sub DimensionsToArch()
Dim sr As New ShapeRange Dim s As Shape Optimization = True For Each s In ActivePage.FindShapes(Type:=cdrLinearDimensionShape)sr.Add sNext s sr.AddToSelection SendKeys "%(ds)" 'my shortcut to Dimension Style (Alt+ds) SendKeys "{DOWN 3}" 'from Fractional to Architectural, adjust as needed SendKeys "{ENTER}" SendKeys "{ESC}" Optimization = False :RefreshEnd Sub
Sorry that I'm a little late with this, but if you use the shape's properties you can change between the styles:
Sub ChangeTextStyle(inSh As Shape, textSt As Integer) If (textSt < 0 Or textSt > 3) Then Exit Sub End If inSh.Style.GetProperty("dimension").SetProperty "textStyle", CStr(textSt)End Sub
Sub ChangeTextStyle(inSh As Shape, textSt As Integer)
If (textSt < 0 Or textSt > 3) Then
Exit Sub
End If
inSh.Style.GetProperty("dimension").SetProperty "textStyle", CStr(textSt)
End Sub
Pass inSh as the dimension shape and the textSt can be 0 to 3:
0 - Decimal
1 - Fractional
2 - U.S. Engineering
3 - U.S. Architecture
Hi Myron,
From your example, where are you assigning the values for inSh and textSt?
Keep in mind I'm using X7. When I copy and paste your code, as is, it isn't viewable as an option from either the macro Manager docker or running from Tools/Macros/Run Macro. Form Co-Pilot
The example I gave is a subroutine that needs to have two variables supplied to it; the shape to work on and then the format to change it to. Because the subroutine accepts variables, it can't be run by itself and won't show up in the docker.
I've updated the example code with an argument sub that collects all the dimension shapes and the calls the "ChangeTextStyle" subroutine with each shape it finds.
Sub ChangeTextStyleTest() Dim selRange As ShapeRange Dim targetRange As ShapeRange Dim workSh As Shape Dim changeStyle As Integer ' Uncomment out the style that you'd like to change to 'changeStyle = 0 ' Decimal changeStyle = 1 ' Fractional 'changeStyle = 2 ' U.S. Engineering 'changeStyle = 3 ' U.S. Architectural ' Get the currently selected items Set selRange = ActiveSelectionRange If (selRange.Count < 1) Then MsgBox ("Please select some shapes to process and try again.") End If ' Get only the linear dimensions from the selected shapes Set targetRange = selRange.Shapes.FindShapes(query:="@type='dimension:linear'") If (targetRange.Count < 1) Then MsgBox ("No linear dimensions found to process.") End If ' Loop through all our shapes and change them to the given style For Each workSh In targetRange.Shapes ChangeTextStyle workSh, changeStyle Next workSh End SubSub ChangeTextStyle(inSh As Shape, textSt As Integer) If (textSt < 0 Or textSt > 3) Then Exit Sub End If inSh.Style.GetProperty("dimension").SetProperty "textStyle", CStr(textSt)End Sub
Sub ChangeTextStyleTest()
Dim selRange As ShapeRange
Dim targetRange As ShapeRange
Dim workSh As Shape
Dim changeStyle As Integer
' Uncomment out the style that you'd like to change to
'changeStyle = 0 ' Decimal
changeStyle = 1 ' Fractional
'changeStyle = 2 ' U.S. Engineering
'changeStyle = 3 ' U.S. Architectural
' Get the currently selected items
Set selRange = ActiveSelectionRange
If (selRange.Count < 1) Then
MsgBox ("Please select some shapes to process and try again.")
' Get only the linear dimensions from the selected shapes
Set targetRange = selRange.Shapes.FindShapes(query:="@type='dimension:linear'")
If (targetRange.Count < 1) Then
MsgBox ("No linear dimensions found to process.")
' Loop through all our shapes and change them to the given style
For Each workSh In targetRange.Shapes
ChangeTextStyle workSh, changeStyle
Next workSh
I can't reinstall X7 on this machine as it complains about a newer version already being present, but I'll see if I have an opportunity to test it myself.
From the developer's documentation I believe Co-Pilot is incorrect, as the Shape object does have the Style property:https://community.coreldraw.com/sdk/api/draw/17/p/shape.style
which has both getter and setting properties.
Give this example a go and see if it works for you.
Myron,
I have a copy of X7 still installed in my laptop. I just copied and pasted Jeff's code directly into a standard module and it works perfectly (nice job, Jeff). Once you have pasted in the code, all you have to do is go to the Tools menu, Customization, Commands, change the dropdown at the top of the center list to "Macros", find the ChangeTextStyleTest macro, and assign a shortcut key combo it it. Then, if you drag a box around ALL of your dimension lines (doesn't matter if other objects are selected as well) and use the shortcut key you assigned, all the dimensions will be displayed in your desired format.
Yes, that one works.
I'll stick with my "SelectAllDimensions" macro then I can change any attributes I wish.