This question is spawned off from the http://communities.bentley.com/Products/MicroStation/MicroStation_-_all_pre-V8_versions/f/142/t/38062.aspx question of text ranges and view dependent versus independent. Additionally it may provide a sample to the previous question in this vba forum.
Now to the question. How to set the textnodeelement to dependent\independent if the property is read only? I can record a macro using the Selectby Attributes and it will let me change the property but the following code is cleaner but will not work on the text nodes (it does on just text). Just curious and learning.
Sub scanTextDep() Dim oElEnum As ElementEnumerator Dim oElScan As ElementScanCriteria Dim oele As Element Dim userTextDep As Boolean
' True makes all Dependent text independent ' False makes all Independent text dependent userTextDep = False
Set oElScan = New ElementScanCriteria oElScan.ExcludeAllTypes oElScan.IncludeType (msdElementTypeText) oElScan.IncludeType (msdElementTypeTextNode) On Error Resume Next Set oElEnum = ActiveModelReference.Scan(oElScan) While oElEnum.MoveNext Set oele = oElEnum.Current If oele.IsTextElement Or oele.IsTextNodeElement Then oele.AsTextElement.IsViewIndependent = userTextDep oele.AsTextNodeElement.IsViewIndependent = userTextDep ' error here on node property End If oele.Redraw msdDrawingModeNormal oele.Rewrite Wend End Sub
Here is the recorded macro that works.
Sub Macro1() Dim startPoint As Point3d Dim point As Point3d, point2 As Point3d Dim lngTemp As Long
MsgBox ("This will make all text view dependent") ' Start a command CadInputQueue.SendCommand "MDL SILENTLOAD SELECTBY dialog"
CadInputQueue.SendCommand "DIALOG SELECTBY "
' Set a variable associated with a dialog box SetCExpressionValue "selectorGlobals.typemask[0]", 5009, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[1]", -1223, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[2]", -30, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[3]", -1, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[4]", -1, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[5]", -65, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[6]", -257, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[7]", -1, "SELECTBY"
SetCExpressionValue "selectorGlobals.typemask[0]", 5073, "SELECTBY"
SetCExpressionValue "selectorGlobals.viewdependentButton", -1, "SELECTBY"
SetCExpressionValue "selectorGlobals.viewdependent", 1, "SELECTBY"
CadInputQueue.SendCommand "SELECTBY EXECUTE "
Dim modalHandler As New Macro1ModalHandler AddModalDialogEventsHandler modalHandler
' The following statement opens modal dialog "Alert"
CadInputQueue.SendCommand "MODIFY TEXT "
SetCExpressionValue "tcb->msToolSettings.changeText.viewind", 1, "MODIFY"
point.X = startPoint.X + 7.350986 point.Y = startPoint.Y - 16.868578 point.Z = startPoint.Z CadInputQueue.SendDataPoint point, 1
CadInputQueue.SendCommand "MDL UNLOAD SELECTBY"
RemoveModalDialogEventsHandler modalHandler CommandState.StartDefaultCommand End Sub
Here is some code I use to work around the read-only justification for text nodes, with a few minor modifications you should be able to use it for other properties as well including the view independent property. In fact, looking at it could probably be generalized to allow more general manipulation of text properties, but I was in a hurry and just modified the code from the macro recorder. Please notice the small helper function at the end. Please forgive any mistakes as this was one of the first pieces of code I wrote while learning VBA and Microstation. Private Sub TextNodeJust(txtNode As TextNodeElement, txtJust As MsdTextJustification) 'Justifies a text node 'Variables to store the current user settings Dim curStyle As Variant Dim curFont As Variant Dim curHeight As Variant Dim curWidth As Variant Dim curLinespace As Variant Dim curLineSpaceType As Variant Dim curInterchar As Variant Dim curSlant As Variant Dim curLinelength As Variant Dim curUnderline As Variant Dim curVertical As Variant Dim curViewind As Variant Dim curJustToggle As Variant Dim curJust As Variant CadInputQueue.SendCommand "MODIFY TEXT " 'capture the users settings curStyle = GetCExpressionValue("tcb->msToolSettings.changeText.textstyle") curFont = GetCExpressionValue("tcb->msToolSettings.changeText.font") curHeight = GetCExpressionValue("tcb->msToolSettings.changeText.height") curWidth = GetCExpressionValue("tcb->msToolSettings.changeText.width") curLinespace = GetCExpressionValue("tcb->msToolSettings.changeText.linespace") curLineSpaceType = GetCExpressionValue("tcb->msToolSettings.changeText.linespacetype") curInterchar = GetCExpressionValue("tcb->msToolSettings.changeText.interchar") curSlant = GetCExpressionValue("tcb->msToolSettings.changeText.slant") curLinelength = GetCExpressionValue("tcb->msToolSettings.changeText.linelength") curUnderline = GetCExpressionValue("tcb->msToolSettings.changeText.underline") curVertical = GetCExpressionValue("tcb->msToolSettings.changeText.vertical") curViewind = GetCExpressionValue("tcb->msToolSettings.changeText.viewind") curJustToggle = GetCExpressionValue("tcb->msToolSettings.changeText.just") curJust = GetCExpressionValue("tcb->textStyle.just") 'Modify the users settings to ensure only the justification change is made SetCExpressionValue "tcb->msToolSettings.changeText.textstyle", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.font", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.height", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.width", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.linespace", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.linespacetype", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.interchar", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.slant", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.linelength", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.underline", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.vertical", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.viewind", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.just", 0, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.just", 1, "MODIFY" SetCExpressionValue "tcb->textStyle.just", txtJust, "MODIFY" 'Make the justification change CadInputQueue.SendDataPoint MidPoint3d(txtNode.Range.Low, txtNode.Range.High) CommandState.StartDefaultCommand 'reset the user settings SetCExpressionValue "tcb->msToolSettings.changeText.textstyle", curStyle, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.font", curFont, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.height", curHeight, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.width", curWidth, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.linespace", curLinespace, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.linespacetype", curLineSpaceType, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.interchar", curInterchar, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.slant", curSlant, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.linelength", curLinelength, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.underline", curUnderline, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.vertical", curVertical, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.viewind", curViewind, "MODIFY" SetCExpressionValue "tcb->msToolSettings.changeText.just", curJustToggle, "MODIFY" SetCExpressionValue "tcb->textStyle.just", txtJust, "MODIFY" End Sub Public Function MidPoint3d(pt1 As Point3d, pt2 As Point3d) As Point3d 'Returns the midpoint between two points MidPoint3d = Point3dFromXY(pt1.X - pt2.X, pt1.Y - pt2.Y) End Function