I need to resize extruded text in a part from a design table.The problem is that there doesn't seem to be a way to attach adimension to text. Can someone think of a way to do this with code?
I've attached a simple part as an example. The way it should workis that changing the height and width of the base extrusion shouldcause a change of the height of the extruded text. D2@Sketch2should drive the text height but it is totally disconnected in thiscase (just change the height of the base extrusion to verify this).
Thanks,
-Martin
SolidworksApi macros

I've attached a simple part as an example. The way it should workis that changing the height and width of the base extrusion shouldcause a change of the height of the extruded text. D2@Sketch2should drive the text height but it is totally disconnected in thiscase (just change the height of the base extrusion to verify this).
Thanks,
-Martin
SolidworksApi macros

-Martin
You already have equations set up to work out the height of thetext, just alter the equations to incorporate the Extrude1's depthas a factor
I need to be able to control text HEIGHT parametrically, preferablyfrom a design table.
When you enter text into a sketch there is no such thing as adimension ON THE SKETCH that determines the HEIGHT of that text. Inorder to modify the HEIGHT one has to use the font selection dialogand manually alter that value. As far as I can tell there is no wayto "touch" text HEIGHT from an equation.
I have a part (an injection molded emblem) that needs to bemanufactured in various sizes. I can parameterize every feature ofthis emblem with the exception of text height. I can drive partdimensions, extrusion depths, etc. from a design table just fine.No such luck for text height. I really want to avoid having tomanually edit text height every time a new size emblem is required.This is opening the door for errors.
Anyhow, I thought that, just maybe, there's a way to use the API tocreate a link between a dimension somewhere on the same sketch thatthe text is on and the height of the corresponding text. Can anyonehelp me with this?
Thanks,
-Martin
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim SelMgr As SelectionMgr
Dim text As SketchText
Dim format As TextFormat
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set SelMgr = swModel.SelectionManager
swModel.Extension.SelectByID2 "Sketch2", "SKETCH", 0, 0, 0, False,0, Nothing, 0
swModel.EditSketch
swModel.Extension.SelectByID2 "SketchText1", "SKETCHTEXT", 0, 0, 0,False, 0, Nothing, 0
Set text = SelMgr.GetSelectedObject6(1, -1)
Set format = text.GetTextFormat
format.CharHeight = 1 ' set size you want based on dimensions here
text.SetTextFormat False, format
swModel.EditRebuild3
End Sub
Private Sub ll1()
Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2
Dim SwSelMgr As SelectionMgr, SwFeat As Feature
Set SwApp = GetObject(, "SldWorks.Application")
Set SwModel = SwApp.ActiveDoc
Set SwSelMgr = SwModel.SelectionManager
Set SwFeat = SwModel.FeatureByName("草图1")
Dim SwSketch As Sketch
Set SwSketch = SwFeat.GetSpecificFeature2
Dim vSkSeg, vSkSegArr, SwSkSeg As SketchSegment
vSkSegArr = SwSketch.GetSketchSegments
Dim SwSkText As SketchText
For Each vSkSeg In vSkSegArr
Set SwSkSeg = vSkSeg
''
Select Case SwSkSeg.GetType
Case swSketchLINE
Set swSkLine = SwSkSeg
Case swSketchARC
Set swSkArc = SwSkSeg
Case swSketchELLIPSE
Set swSkEllipse = SwSkSeg
Case swSketchSPLINE
Set swSkSpline = SwSkSeg
Case swSketchTEXT
Set SwSkText = SwSkSeg
Debug.Print SwSkText.Text
Debug.Print SwSkText.GetUseDocTextFormat ', SwSkText.GetTextFormat
Case swSketchPARABOLA
Set swSkParabola = SwSkSeg
Case Default
Debug.Assert False
End Select
Next
End Sub
Check out this video of equation triggered macros. It might help you out.
http://www.cadsharp.com/blog/equation-triggered-macros/
***************
Username: ning58,Password: 44bfc25
You may log in and start learning the SolidWorks API right now.
but don't see videos in your web site like videos.
*********************
Hope see the following content
Lesson 1.1 – Introduction to VBA
Lesson 1.2 – Using variables
Lesson 1.3 – Using arrays