Solidworks API: How to change Dimension text
Solidworks API: How to change Dimension text
(OP)
Hello
I have been looking how to change the dimension text from within the solidworks api. I can change the value and position no problem but not the displayed text.
I am looking to get the text such as
"4 Holes<MOD-DIAM><DIM> THRU ALL"
The only values I can get is <MOD-DIAM><DIM> but I need to be able to change the comment section.
I've spent hours going through examples and the API help but I can not find a reference.
The code I have got that is accessing the dimension object is as follows. I can access the general dimension name, value, full name, tolerance details just not the dimension text.
//=============================================================
SldWorks swApp = new SldWorks();
ModelDoc2 l_Model;
DrawingDoc l_Draw;
Sheet l_Sheet;
RevisionTableAnnotation l_Revtable;
Dimension dim;
SolidWorks.Interop.sldworks.View l_View;
RevisionTableAnnotation tab;
l_Model = (ModelDoc2)swApp.OpenDoc("PartTwo.SLDDRW"
,(int) swDocumentTypes_e.swDocDRAWING);
l_Draw = (DrawingDoc)l_Model;
l_Sheet = (Sheet) l_Draw.GetCurrentSheet();
l_Revtable = l_Sheet.RevisionTable;
l_Revtable.GetColumnCustomProperty(10);
MessageBox.Show( l_Revtable.GetRevisionForId(10).ToString() );
dim = (Dimension)l_Model.Parameter("RD5@Drawing View6");
MessageBox.Show(dim.FullName);
MessageBox.Show(dim.Value.tostring());
//=============================================
I have been looking how to change the dimension text from within the solidworks api. I can change the value and position no problem but not the displayed text.
I am looking to get the text such as
"4 Holes<MOD-DIAM><DIM> THRU ALL"
The only values I can get is <MOD-DIAM><DIM> but I need to be able to change the comment section.
I've spent hours going through examples and the API help but I can not find a reference.
The code I have got that is accessing the dimension object is as follows. I can access the general dimension name, value, full name, tolerance details just not the dimension text.
//=============================================================
SldWorks swApp = new SldWorks();
ModelDoc2 l_Model;
DrawingDoc l_Draw;
Sheet l_Sheet;
RevisionTableAnnotation l_Revtable;
Dimension dim;
SolidWorks.Interop.sldworks.View l_View;
RevisionTableAnnotation tab;
l_Model = (ModelDoc2)swApp.OpenDoc("PartTwo.SLDDRW"
,(int) swDocumentTypes_e.swDocDRAWING);
l_Draw = (DrawingDoc)l_Model;
l_Sheet = (Sheet) l_Draw.GetCurrentSheet();
l_Revtable = l_Sheet.RevisionTable;
l_Revtable.GetColumnCustomProperty(10);
MessageBox.Show( l_Revtable.GetRevisionForId(10).ToString() );
dim = (Dimension)l_Model.Parameter("RD5@Drawing View6");
MessageBox.Show(dim.FullName);
MessageBox.Show(dim.Value.tostring());
//=============================================






RE: Solidworks API: How to change Dimension text
Ken
CODE
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim sCurrPrefix As String
Dim sCurrSuffix As String
Dim sCurrCalloutAbove As String
Dim sCurrCalloutBelow As String
Dim sNewPrefix As String
Dim sNewSuffix As String
Dim sNewCalloutAbove As String
Dim sNewCalloutBelow As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "Must have a SolidWorks document open." & Chr(13) & "Routine ending.", vbCritical, "Change Dimension Text"
End
End If
If swModel.GetType <> swDocDRAWING Then
MsgBox "Macro only works for Drawing files." & Chr(13) & "Routine ending.", vbCritical, "Change Dimension Text"
End
End If
Set swSelMgr = swModel.SelectionManager
If (swSelMgr.GetSelectedObjectType3(1, -1) = swSelDIMENSIONS) Then
Set swDispDim = swSelMgr.GetSelectedObject6(1, 0)
Set swDim = swDispDim.GetDimension
'Current Dimension Text
sCurrPrefix = swDispDim.GetText(swDimensionTextPrefix)
sCurrSuffix = swDispDim.GetText(swDimensionTextSuffix)
sCurrCalloutAbove = swDispDim.GetText(swDimensionTextCalloutAbove)
sCurrCalloutBelow = swDispDim.GetText(swDimensionTextCalloutBelow)
'New Dimension Text
sNewPrefix = "My New Prefix "
sNewSuffix = " My New Suffix"
sNewCalloutAbove = "My New Callout Above"
sNewCalloutBelow = "My New Callout Below"
'*Change* Dimension Text
swDispDim.SetText swDimensionTextPrefix, sNewPrefix
swDispDim.SetText swDimensionTextSuffix, sNewSuffix
swDispDim.SetText swDimensionTextCalloutAbove, sNewCalloutAbove
swDispDim.SetText swDimensionTextCalloutBelow, sNewCalloutBelow
'*Add to Current* Dimension Text
swDispDim.SetText swDimensionTextPrefix, sCurrPrefix & sNewPrefix
swDispDim.SetText swDimensionTextSuffix, sCurrSuffix & sNewSuffix
swDispDim.SetText swDimensionTextCalloutAbove, sCurrCalloutAbove & sNewCalloutAbove
swDispDim.SetText swDimensionTextCalloutBelow, sCurrCalloutBelow & sNewCalloutBelow
End If
swModel.GraphicsRedraw2
End Sub
RE: Solidworks API: How to change Dimension text