.NET

Reply
Contributor
kemp77
Posts: 20
Registered: ‎11-06-2008
Message 1 of 7 (992 Views)
Accepted Solution

Cannoscale formatting

992 Views, 6 Replies
10-21-2010 03:24 PM

Dim str As String = ("1/16""" & " = 1'-0""")

MsgBox("Cannoscale = " & CannoScale)
Application.SetSystemVariable("CANNOSCALE", str)

 

I am new to learning vb.net. This problem will make that readily apparent :smileytongue: 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"

 

 

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.

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 2 of 7 (982 Views)

Re: Cannoscale formatting

10-21-2010 04:43 PM in reply to: kemp77

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. 

 

Dave O.                                                                  Sig-Logos32.png
Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 3 of 7 (980 Views)

Re: Cannoscale formatting

10-21-2010 05:01 PM in reply to: chiefbraincloud

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

Autodesk.AutoCAD.DatabaseServices.StandardScaleType Enumeration
See picture "is" "and"
1338iE51AEAF3AA21689A
You can also find your answers @ TheSwamp
Contributor
kemp77
Posts: 20
Registered: ‎11-06-2008
Message 4 of 7 (943 Views)

Re: Cannoscale formatting

10-25-2010 05:42 PM in reply to: chiefbraincloud

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

 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 5 of 7 (939 Views)

Re: Cannoscale formatting

10-25-2010 07:17 PM in reply to: kemp77

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.

Dave O.                                                                  Sig-Logos32.png
Contributor
kemp77
Posts: 20
Registered: ‎11-06-2008
Message 6 of 7 (917 Views)

Re: Cannoscale formatting

10-26-2010 12:05 PM in reply to: chiefbraincloud

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. 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 7 of 7 (906 Views)

Re: Cannoscale formatting

10-26-2010 05:28 PM in reply to: kemp77

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.

Dave O.                                                                  Sig-Logos32.png
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.