Dim str As String = ("1/16""" & " = 1'-0""")
I am new to learning vb.net. This problem will make that readily apparent 😛 What is wrong with this statement? I have checked the output of str with a msgbox and it looks exactly like what I should be feeding the cannoscale system variable, yet it does not change the value. What could I be formatting incorrectly? I have it currently working in vba using the following format:
("1/16" & Chr(34) & "=1'-0" & Chr(34))
but it fires a debug error in vb.net
Output to cannoscale should be --> 1/16" = 1'-0"
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
I assume that for your testing purposes you know that the scale exists, right?
That said, I'm not sure why it would fail, but try something like this:
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ocm As ObjectContextManager = db.ObjectContextManager
Dim occ As ObjectContextCollection = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES")
Dim tstAnnoScale As AnnotationScale = occ.GetContext("1/16""" & " = 1'-0""")
If Not tstAnnoScale Is Nothing Then db.Cannoscale = tstAnnoScale
Similar code works for me, and this way, you can test the tstannoscale object to be sure it exists before trying to set it.
Also if you are ever dealing with StandardScale property of a viewport use values in documentation
under Autodesk.AutoCAD.DatabaseServices.StandardScaleType Enumeration
not Viewport.StandardScale Property they use "is instead of and"
To clarify, for a ViewPort.StandardScale property use values listed in the docs for
Thanks for the help understanding this so far guys. But using this code all I get is an eLockViolation.
Autodesk.AutoCAD.Runtime.Exception: eLockViolation at Autodesk.AutoCAD.DatabaseServices.Database.set_Cannoscale(AnnotationScale annotationScale) at ClassLibrary1.DialogBoxForm.OKButton_Click(Object sender, EventArgs e) in C:\Documents and Settings\kburgess.UDA-DOMAIN\my documents\visual studio 2010\Projects\ClassLibrary1\ClassLibrary1\DialogBoxForm.vb:line 86
What could be the culprit of this? I am not using a fancy modeless form, I have verified the string is valid, and yet I still can't seem to do this basic function.
I have tried:
("1/16""" & " = 1'-0""")
"1/16""" & " = 1'-0"""
("1/16"" = 1" & Chr(39) & "-0""")
"1/16"" = 1" & Chr(39) & "-0"""
All to no avail. ps did I mention I hate this web interface? LOL
From your error message, I can tell that you are running the code from a form (evidentally modal, since you said not modeless), and that still means you should lock the document. Try wrapping your code that accesses the database in the Click Event handler with something like this:
Using loc as ApplicationServices.DocumentLock = MdiActiveDocument.LockDocument
'your code here
End Using
That should work, but If it doesn't, try wrapping the Form Show code with the document lock.
I now see that without locking the document none of my strings were working. With it locked all of them behave as they should. Thanks for nudge in the proper direction I needed.
It was not the string format that was causing the failure. It was that autocad had the document locked from changes. The language may be a little misleading, but the best I can explain it is that when you create your document lock, you are telling autocad that you are about to make changes and therefore autocad should not allow anything but you to make changes until you are done.