.NET

Reply
Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 1 of 10 (586 Views)

Changing system variables

586 Views, 9 Replies
08-01-2011 11:49 AM

I want a few sendcommands executed when AutoCAD starts up. 

 

 Dim doc As Document = Application.DocumentManager.MdiActiveDocument        doc.SendStringToExecute("ANNOAUTOSCALE 4" & vbCr, False, False, True)       

 

The DocumentCreated or DocumentActivated events doen't seem to trigger on start up so i've added them to the initialize sub. (Maybe the dll isn't loaded at this point)

 

And in the initialize sub then they are ignored.Commandline looks like this:

Command:

AutoCAD menu utilities loaded.ANNOAUTOSCALE 4

CANNOSCALE 1:100

Command: _RIBBON

 

 If I put them in a routine they are slow and get minced in with other commands. Can anyone suggest a good place. Ir is SendStringToExecute not the right method?

Distinguished Mentor
michael.robertson
Posts: 593
Registered: ‎03-18-2008
Message 2 of 10 (576 Views)

Re: Changing system variables

08-01-2011 12:47 PM in reply to: SRSDS

You could try to set the variable programmitically instead of sending commands using:

 

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable(variable, value)

Mike Robertson
FL. Dept. of Transportation
CADD Applications Developer
Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 3 of 10 (572 Views)

Re: Changing system variables

08-01-2011 01:11 PM in reply to: michael.robertson

Exactly what I'm after. 

I got an error saying SetSystemVariable is not a member of Autodesk.AutoCAD.ApplicationServices.Application.

But google it and found  Application.SetSystemVariable("MAXSORT", 100)

Thankyou!

Mentor
SRSDS
Posts: 247
Registered: ‎04-15-2011
Message 4 of 10 (545 Views)

Re: Changing system variables

08-02-2011 01:16 AM in reply to: SRSDS

Hi again.

Is there a similar way to change the document variable settings?

I also want to change things like the drawing annotation scale

 

 

Valued Contributor
pjfontes
Posts: 98
Registered: ‎03-17-2008
Message 5 of 10 (474 Views)

Re: Changing system variables

12-23-2011 08:30 AM in reply to: SRSDS

 


SRSDS wrote:

Hi again.

Is there a similar way to change the document variable settings?

I also want to change things like the drawing annotation scale

 

 


Excellent Question!

 

Anybody?  Does the document have to be opened and active?

 

Thanks.

Valued Mentor
jeff
Posts: 330
Registered: ‎05-12-2009
Message 6 of 10 (471 Views)

Re: Changing system variables

12-23-2011 08:39 AM in reply to: pjfontes

Some you can set through the Database object like Database.Cannoscale if that is what you are talkink about

You can also find your answers @ TheSwamp
Valued Contributor
pjfontes
Posts: 98
Registered: ‎03-17-2008
Message 7 of 10 (468 Views)

Re: Changing system variables

12-23-2011 08:56 AM in reply to: jeff

Great!  I knew I was over-thinking it..

 

Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument

 

Dim acCurDb As Database = acDoc.Database

acCurDb.Attmode = MyValue

 

 

*Expert Elite*
GTVic
Posts: 916
Registered: ‎09-07-2004
Message 8 of 10 (428 Views)

Re: Changing system variables

12-27-2011 04:04 PM in reply to: pjfontes

You can use the following:

 

Imports Autodesk.AutoCAD.ApplicationServices
Try
    Dim lms As Object = Application.GetSystemVariable("CANNOSCALE")
    Application.SetSystemVariable("CANNOSCALE", lms)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
End Try

 If a drawing is not open for a drawing based variable you will get an eInvalidInput exception. So you can mask that with the error trapping plus the error trapping helps if the version of AutoCAD does not support the variable you are using.

Valued Mentor
jeff
Posts: 330
Registered: ‎05-12-2009
Message 9 of 10 (406 Views)

Re: Changing system variables

12-28-2011 09:46 AM in reply to: GTVic

Why not use Database.Cannoscale?

You can also find your answers @ TheSwamp
*Expert Elite*
GTVic
Posts: 916
Registered: ‎09-07-2004
Message 10 of 10 (394 Views)

Re: Changing system variables

12-28-2011 01:41 PM in reply to: jeff

jeff wrote:

Why not use Database.Cannoscale?


I understood that CANNOSCALE was just an example of the type of variable he would like to set so my suggestion is a generic solution.

 

On a side topic, I noticed that other 3rd party apps can have the problem of interrupting the startup sequence when using SendStringToExecute. When I had AutoCAD 2009 infected with the Adobe plug-in I would get an Adobe initialization message on the commandline followed by "Unknown command: OMMANDLINE" (missing the 'C') because AutoCAD was probably doing it's own SendStringToExecute of "COMMANDLINE" that was being interrupted by the Adobe plug-in. IMO, Autodesk shouldn't be programming its products this way but if you have to use SendStringToExecute I think there is a function you can call to make sure other commands are not being executed.

 

DocumentManager.MdiActiveDocument.Editor.Document.CommandInProgress

 

Or perhaps a document lock would work but I wonder if that could crash another plug-in that was trying to initialize. Assuming the other plug-in was not written properly.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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