Adding New TextStyle

Adding New TextStyle

Anonymous
Not applicable
362 Views
4 Replies
Message 1 of 5

Adding New TextStyle

Anonymous
Not applicable
HI,

I am having a problem adding a textstyle in vba. What I am doing is looping through several different textstyles to add them dynamically. When I do this the routine fails with the error "Run-time erro '-2145320949 (8021000b)': Calling method SetObjectId of interface IAcadBaseObject failed". What I have found out is that when I add the textstyle using a variable for my name it fails, if i actually type the name in it works. Here is a code snippet of each.

DOES NOT WORK
For intI = 0 To 1
Dim StyleHt As Double, StyleWF As Double, StyleOA As Double
tempAry = Split(strStyleAry(intI), ",")
Dim strStyleName As String
strStyleName = tempAry(0)

Dim objTextStyle As AcadTextStyle
Set objTextStyle = .TextStyles.Add(strStyleName)
Set TextStyleObject = Nothing
Next

WORKS
Dim objTextStyle As AcadTextStyle
Set objTextStyle = .TextStyles.Add("TESTSTYLE")
Set TextStyleObject = Nothing

Please help, I cannot figure out why this is happening....

Thanks,
Mike
0 Likes
363 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
First thing I'd check is that the line:
tempAry = Split(strStyleAry(intI), ",")
Is returning what you think it is.

wrote in message news:5052540@discussion.autodesk.com...
HI,
0 Likes
Message 3 of 5

Anonymous
Not applicable
i have checked that....it does return exactly what it should. basically, whatever i hardcode into the section of code that works, is being returned into that variable.
0 Likes
Message 4 of 5

Anonymous
Not applicable
Could you post the rest of the code? I cannot duplicate the error when I
recreate your code.

Jeff

wrote in message news:5052798@discussion.autodesk.com...
i have checked that....it does return exactly what it should. basically,
whatever i hardcode into the section of code that works, is being returned
into that variable.
0 Likes
Message 5 of 5

Anonymous
Not applicable
Well, here's the code I tried and it works just fine......

Sub textstyleTEST()
Dim intI As Integer
Dim intJ As Integer
Dim tempAry As Variant
Dim strStyleAry(1) As String

strStyleAry(0) = "Styl1,Styl2"
strStyleAry(1) = "Styl3,Styl4,SuperDuperStyle"
For intI = 0 To 1
Dim StyleHt As Double, StyleWF As Double, StyleOA As Double
tempAry = Split(strStyleAry(intI), ",")
Dim strStyleName As String
For intJ = 0 To UBound(tempAry)
strStyleName = tempAry(intJ)
Dim objTextStyle As AcadTextStyle
Set objTextStyle = ThisDrawing.TextStyles.Add(strStyleName)
Debug.Print objTextStyle.Name
Set objTextStyle = Nothing
Next
Next

End Sub

"Jeff Mishler" wrote in message
news:5052849@discussion.autodesk.com...
Could you post the rest of the code? I cannot duplicate the error when I
recreate your code.

Jeff
0 Likes