I feel like I have done this before but can't get it to work for some reason.
I would like to scan a model for text elements and set the text style for each one found.
I have the scan etc working fine but can't apply the text style -
'Change text style of sign names Do While oEnumerator.MoveNext Set oText = oEnumerator.Current Set oText.TextStyle = oFile.TextStyles("1.8mm BG") 'oEnumerator.Current.Rewrite oText.Redraw msdDrawingModeNormal oText.Rewrite counter = counter + 1 Loop
Any help would be appreciated.
Les Leayr said:I have the scan etc working fine but can't apply the text style
Text styles in VBA seem often to cause problems. Try something like this...
Dim oStyle As TextStyle Set oStyle = oFile.TextStyles("1.8mm BG") Debug.Assert Not oStyle Is Nothing Do While oEnumerator.MoveNext Set oText = oEnumerator.Current.AsTextElement Debug.Assert Not oText Is Nothing Set oText.TextStyle = oStyle oText.Rewrite counter = counter + 1 Loop
Regards, Jon Summers LA Solutions
I thought I had replied here but must have not.
Thanks Jon although the text style is still not being applied.
I have ran some debugging and the results are confirming the following are correct -
Current Text Style name of the element
Text contents of the element
New Text Style name set to oStyle
Do While oEnumerator2.MoveNext Set oText = oEnumerator2.Current.AsTextElement Debug.Assert Not oText Is Nothing Set oText.TextStyle = oStyle oText.Rewrite Debug.Print oText.Text Debug.Print "oText style name = " & oText.TextStyle.Name counter = counter + 1 Loop
Any (more) help would be greatly appreciated.
Les Leayr said:Debug.Print oText.Text Debug.Print "oText style name = " & oText.TextStyle.Name
Debug.Print oText.Text Debug.Print "oText style name = " & oText.TextStyle.Name
Those two lines display the expected value of text and text style from the in-memory text element?
Try this to see if the change was persisted...
Dim id As DLong id = oText.ID oText.Rewrite Dim test As TextElement set test = ActiveModelReference.GetElementById (id) Debug.Print test.Text Debug.Print "test style name = " & test.TextStyle.Name
Does that reveal the unexpected?
Just trying to test and whenever I type oID = oText.ID the editor changes it to lowercase oID = oText.id and I'm getting a Type Mismatch error?
Les Leayr said:whenever I type oID = oText.ID the editor changes it to lowercase oID = oText.id
The IDE has its idiosyncrasies. VBA is case-insensitive so there's nothing to worry about: id is the same as ID.
id
ID
Les Leayr said:I'm getting a Type Mismatch error?
Show your declaration of oID.
oID
Dim oID as Long
Les Leayr said:Dim oID as Long I'm getting a Type Mismatch error id = oText.ID
I'm getting a Type Mismatch error
id = oText.ID
Element.ID is a DLong, not a Long. Do this...
Element.ID
DLong
Long
Dim oID as DLong
DLong was invented so that 32-bit VBA 6 could store a 64-bit Element ID: in VBA terms it's a user-defined type (UDT). You see the mismatch error because VBA can't reconcile a DLong with a Long. Look in VBA help to see several conversion functions to get data to/from a DLong to other data types.
Thanks Jon, missed that somehow.
Can confirm the change has not persisted.
Les Leayr said:Can confirm the change has not persisted
Can you package your DGN file and VBA project into a ZIP file and present them as evidence? Perhaps Artur Goldsweer or Yongan.Fu could take a look?